LaminDB Connection¶
The lamindb connection type connects Airflow to a LaminDB instance hosted on
LaminHub through the LaminHub REST API.
The default connection ID is lamindb_default.
Configuring the Connection¶
- API Key (password)
- A Lamin API key. It is exchanged for a short-lived access token that the hook refreshes automatically. Leave it empty for anonymous access to public instances. For production, use the API key of a bot account that has read access to the instance.
- Instance (
instanceextra) - The instance slug
owner/name, e.g.laminlabs/lamindata. Hooks, triggers and sensors accept aninstanceargument to override it, the lineage operators and decorators alamindb_instanceargument, so one connection can serve several instances of the same account. - LaminHub API URL (host, optional)
-
The LaminHub REST API used to exchange the API key and to look up the instance. Defaults to
https://aws.us-east-1.lamin.ai/api. Requests to the instance itself automatically go to the instance's regional API, so hosted instances in any region work with the default. Set this for on-prem LaminHub deployments. The lineage operators don't use it: lamindb finds the instance itself.The URL is the LaminHub deployment's base URL followed by
/api. LaminHub's hosted deployments are listed under Deployments in the LaminHub REST docs:https://aws.us-east-1.lamin.ai,https://aws.us-west-2.lamin.ai,https://aws.eu-central-1.lamin.aiandhttps://aws.eu-west-2.lamin.ai. On-prem deployments have their own; ask your LaminHub administrator for its base URL. To check a URL, open<base URL>/_docs(the Swagger UI of the API, e.g. https://aws.us-east-1.lamin.ai/_docs) or test the connection. - Cache directory (
cache_dirextra, optional) -
Absolute path of a lamindb cache that the virtualenvs of the lineage operators and
@task.lamindb_virtualenvsteps share, for example a directory on a volume mounted on every worker. It's passed asLAMIN_CACHE_DIR, so artifacts that one task loaded or saved are not downloaded again by the next task. Without it, lamindb uses its default cache directory on each worker. Override it per task withlamindb_cache_dir.The cache directory must be writable by every task that uses it.
@task.lamindb_kubernetespods don't get it: mount a volume into the pod and setLAMIN_CACHE_DIRin itsenv_vars.
Hook request and response validation¶
The synchronous and asynchronous hook methods use the same Pydantic wire models for request parameters and bodies, authentication responses, and instance settings. Their method signatures are unchanged: pass normal Python arguments and record dictionaries; the hook validates and serializes them.
Model validation failures raise pydantic.ValidationError before an HTTP request is made. Existing
filter validation still raises ValueError or TypeError for invalid filter expressions. Pagination
limits and offsets must be non-negative integers, and include_foreign_keys must be a boolean,
not a string such as "false". A limit of zero returns no records. The hook still splits larger
limits into pages of at most 200 records.
Most record fields remain registry-specific JSON data, not a fixed provider schema. Explicit None
values in inserts and updates are sent as JSON null, including inside nested fields.
An explicitly empty branch_ids=[] scope is preserved; omitting the scope is different.
Malformed authentication and settings responses raise LaminDBApiError without including raw
response values in the error message. Unknown response fields are ignored; database credentials
returned by the settings endpoint are not retained. Missing or empty owner/name and regional API
URL fields still fall back to the requested instance slug and configured LaminHub API URL.
Response validation checks field types, not whether a returned instance ID belongs to a slug.
Artifact, database-write, branch, branch-block and user query and write responses use partial models
for the known fields.
Fields may be absent in projections, and additional columns are preserved. Hook results remain
dictionaries with the original payload, without injecting missing fields or rewriting JSON strings.
Malformed known fields raise a sanitized LaminDBApiError.
Instance schema responses validate module and registry envelopes before being cached. Field descriptions and additional schema metadata remain extensible; an omitted table name still falls back to the module/model table name.
Artifact processing uses typed kind and upload metadata (_aux.so). Auxiliary metadata may be
a JSON object or a JSON-encoded object; both None and the encoded string "null" mean no
metadata. Invalid metadata is reported rather than silently treating an invalid flag as a completed
upload. Database-write data remains dynamic previous record data, and unfamiliar event names are
still ignored by event classification.
Internal filters use the same F, Condition, And and Or builders exposed to DAG authors,
with field enums where available. They are converted to REST dictionaries at query and serialization
boundaries; the serialized filters and trigger identities are unchanged.
Event and execution envelopes¶
Trigger models validate built-in record,
branch-status and branch-block events, actor/branch summaries, persisted cursors and sensor outcomes.
Public event payloads remain dictionaries, including sparse projections and dynamic record data.
Custom write-log trigger subclasses may use their own event names and additional fields.
Malformed sensor outcomes raise a sanitized AirflowException; terminal branch failures still
raise AirflowFailException.
Persisted cursor positions must be non-negative integers (not booleans) bound to an instance ID. Malformed stored values are ignored with a warning, preserving the existing reset behavior. Valid cursors belonging to another instance are ignored.
Worker-side models validate flow-run parameters
and tracked, connected, flow-start and flow-finish execution configurations before remote execution.
Airflow timing/run-type metadata is still stringified, and DAG configuration remains dynamic.
Virtualenvs and pods receive plain dictionaries, not model instances: the shipped runtime still
requires only the standard library and lamindb, not Airflow, this provider or Pydantic.
Lineage operators and decorators¶
The flow operators and @task.lamindb_virtualenv steps pass the connection to lamindb in their virtualenv:
the API key as LAMIN_API_KEY and a temporary, empty LAMIN_SETTINGS_DIR, so lamindb never reads
the worker's ~/.lamin. Both are set only while the task runs and are never rendered. With a
connection, the virtualenv installs the instance's lamindb version unless lamindb_version is given;
either must be 2.8.1 or newer.
@task.lamindb_kubernetes pods only get the instance from the connection. Mount the API key from a
Kubernetes secret, because environment variables of a pod are readable in its spec.
Pass lamindb_conn_id to use another connection for a task, or lamindb_conn_id=None to use
lamindb's own configuration (LAMIN_API_KEY, LAMIN_CURRENT_INSTANCE, ~/.lamin) instead.
lamindb_conn_id, lamindb_instance and lamindb_cache_dir are templated in the flow operators
and the step decorators, and lamindb_conn_id and instance in the sensors, so an upstream task
can choose them at run time:
from airflow.sdk import DAG, task
CONN_ID = "{{ ti.xcom_pull(task_ids='pick_connection') }}"
@task
def pick_connection() -> str:
return "lamindb_staging"
@task.lamindb_virtualenv(lamindb_conn_id=CONN_ID)
def process(): ...
with DAG("templated_connection"):
pick_connection() >> process() # a standalone tracked task
A LaminDBFlow takes its own lamindb_conn_id for its init and finish tasks, like the flow operators; the
tasks inside keep their own connection settings. Triggers can't be templated: Airflow creates them
from the DAG file when it parses it, so their lamindb_conn_id must be a fixed value.
Examples¶
Using an environment variable:
export AIRFLOW_CONN_LAMINDB_DEFAULT='{
"conn_type": "lamindb",
"password": "<lamin-api-key>",
"extra": {"instance": "my-org/my-instance", "cache_dir": "/shared/lamindb-cache"}
}'
Using the CLI:
airflow connections add lamindb_default \
--conn-type lamindb \
--conn-password '<lamin-api-key>' \
--conn-extra '{"instance": "my-org/my-instance"}'
Anonymous access to a public instance, without a connection:
from airflow.providers.lamindb.hooks.lamindb import LaminDBHook
from airflow.providers.lamindb.client.filters import ArtifactField, F
hook = LaminDBHook(lamindb_conn_id=None, instance="laminlabs/lamindata")
hook.query_records("core.artifact", F(ArtifactField.SUFFIX) == ".csv", order_by=["-created_at"], limit=5)
See Filters for building filters.
Testing the connection runs LaminDBHook.test_connection,
which resolves the instance and reads its database write log. It fails for instances on lamindb older
than 2.8.1, which the provider doesn't support. Airflow disables connection testing by default; enable
it with [core] test_connection = Enabled.