Query FeatureQL through ADBC

featuremesh-adbc runs FeatureQL from Python code that already uses ADBC , Arrow's database connectivity API. You write FeatureQL, and you get Arrow tables or data frames back. In the transpiled mode, your own database runs the query and only the translation happens on a FeatureMesh server.

pip install featuremesh-adbc duckdb   # DuckDB's ADBC driver ships in the duckdb package
bash

It needs Python 3.12 or later and the ADBC driver of your database. The driver name you pass to connect() picks it:

DatabasedriverInstall the driver with
DuckDBduckdbpip install duckdb (the driver ships inside it)
PostgreSQLpostgresqlpip install adbc-driver-postgresql
BigQuerybigquerypip install adbc-driver-bigquery
Snowflakesnowflakepip install adbc-driver-snowflake
featuremeshdflightsqlpip install adbc-driver-flightsql
Trino, ClickHouse, Databrickstrino, clickhouse, databricksdbc install <driver> ( dbc , Columnar's ADBC driver installer: these have no pip package)

The package page on PyPI shows a connect() call for each database. The transpiled mode works with a FeatureMesh registry 0.4.1 or later; the direct mode needs featuremeshd 0.3.1 or later.

Run FeatureQL on your database

In the transpiled mode, the package sends each statement to the registry, receives the SQL for your database, and runs that SQL through the ADBC driver:

from featuremesh_adbc import dbapi

config = {
    "adbc.featuremesh.execution_mode": "transpiled",
    "adbc.featuremesh.registry_url": "https://<your registry>/v1/featureql",
    "adbc.featuremesh.registry_token": "<your token>",
}

with dbapi.connect(driver="duckdb", path=":memory:", **config) as con, con.cursor() as cursor:
    cursor.execute("RETURN F1 := 1, F2 := 2, F3 := F1 + F2;")
    table = cursor.fetch_arrow_table()

assert tuple(table.to_pylist()[0].values()) == (1, 2, 3)
python

The registry translates for the database the driver names: duckdb here. Set adbc.featuremesh.backend when the two differ. cursor.fetch_df() returns a pandas data frame instead, when pandas is installed.

Send FeatureQL to featuremeshd

In the direct mode, the default, the package passes each statement unchanged to the driver. Use it with the Flight SQL driver (pip install adbc-driver-flightsql) against the Flight SQL port of featuremeshd 0.3.1 or later, which reads FeatureQL itself. featuremeshd checks every caller: send a project user or service account token in the Authorization header:

from featuremesh_adbc import dbapi

auth = {"adbc.flight.sql.authorization_header": "Bearer <your token>"}

with dbapi.connect(driver="flightsql", uri="grpc://<featuremeshd host>:10093", **auth) as con, con.cursor() as cursor:
    cursor.execute("RETURN F1 := 1, F2 := 2, F3 := F1 + F2;")
    table = cursor.fetch_arrow_table()

assert tuple(table.to_pylist()[0].values()) == (1, 2, 3)
python

Options

OptionValuesDefault
adbc.featuremesh.execution_modedirect: the statement goes to the driver unchanged. transpiled: the registry translates it firstdirect
adbc.featuremesh.registry_urlThe registry's FeatureQL endpoint. Required in the transpiled mode—
adbc.featuremesh.registry_tokenYour registry token. Required in the transpiled mode—
adbc.featuremesh.backendThe backend the registry translates forthe driver's name
adbc.featuremesh.debugTrue prints the SQL the registry returnedFalse

When a statement is refused

The cursor runs one SQL statement per call. A FeatureQL statement whose translation needs several steps, such as temporary tables created first, is refused with the named error PLAN-NEEDS-STEPS. Run it with the Python library instead, which runs every step.

A registry newer than the package can answer with a plan the package does not know. It refuses it with PLAN-VERSION-UNSUPPORTED or PLAN-UNKNOWN-VALUE before running anything: upgrade the package.

Related