Python API Reference
fdl exposes the same operations available in the CLI as a Python package, so pipelines and orchestrators (e.g. Dagster, Airflow) can drive DuckLake catalogs without spawning a subprocess.
At a glance
import fdl
fdl.init("mydata", target_url="s3://my-bucket")
fdl.pull("default")
with fdl.connect("default") as conn:
conn.execute("CREATE TABLE t (x INTEGER)")
conn.execute("INSERT INTO t VALUES (1), (2), (3)")
fdl.push("default")
Function-to-command mapping
| Python API | CLI |
|---|---|
fdl.init(name, ...) |
fdl init NAME |
fdl.pull(target) |
fdl pull TARGET |
fdl.push(target) |
fdl push TARGET |
fdl.run(target, command) |
fdl run TARGET -- COMMAND |
fdl.sync(target, command) |
fdl sync TARGET -- COMMAND |
fdl.connect(target) |
(use directly via DuckDB) |
fdl.connect() is the Python-only entry point — the CLI uses it internally
to implement fdl sql.
Conventions
targetis a required positional argument. There is no implicit"default"target; pass the target name explicitly.- Each function accepts a
project_dir: Path | Nonekeyword. When omitted, fdl walks up from the current working directory to find the nearestfdl.toml, mirroring CLI behavior. - Console output (progress lines, conflict detection, etc.) matches the CLI and is written to stdout.
fdl.run()andfdl.sync()return the subprocess exit code as anint. They do not raise on non-zero exit; check the return value.fdl.init()is not idempotent: it raisesFileExistsErroriffdl.tomlis already present. Initialize once (typically via the CLI) and commitfdl.tomlto the repo; the Python API is for day-to-day operations, not reinitialization.
See Dagster for a worked example of using these APIs inside a Dagster asset.
Reference
fdl
Frozen DuckLake: manage DuckLake catalogs on object storage.
fdl is both a CLI (fdl) and a Python API. The CLI handlers are thin
wrappers over the same internal functions exposed as the Python API, so the
two stay in sync by construction.
Example
import fdl fdl.pull("default") with fdl.connect("default") as conn: ... conn.execute("CREATE TABLE cities (name VARCHAR, pop INTEGER)") fdl.push("default")
init
init(name: str, *, target_name: str = 'default', target_url: str | None = None, public_url: str = 'http://localhost:4001', project_dir: Path | None = None) -> None
Initialize an fdl project (CLI: fdl init).
Writes fdl.toml and creates .fdl/{target_name}/ducklake.sqlite.
On failure, partially created fdl.toml / .fdl/ are rolled back.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Datasource name. Must be a valid SQL identifier.
TYPE:
|
target_name
|
Target name in fdl.toml.
TYPE:
|
target_url
|
Storage URL for the target. Defaults to
:func:
TYPE:
|
public_url
|
Public URL the dataset will be served under.
TYPE:
|
project_dir
|
Directory to initialize in. Defaults to
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
FileExistsError
|
If |
sync
sync(target: str, command: list[str] | None = None, *, force: bool = False, project_dir: Path | None = None) -> int
Run command then push in one step (CLI: fdl sync).
When the command exits non-zero, push is skipped and the exit code is returned as-is.
| PARAMETER | DESCRIPTION |
|---|---|
target
|
Target name defined in fdl.toml.
TYPE:
|
command
|
Command to run. When
TYPE:
|
force
|
Override conflict detection on push.
TYPE:
|
project_dir
|
Project directory containing fdl.toml. Defaults to the nearest ancestor that contains one.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The subprocess exit code ( |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If |
ValueError
|
If |
PushConflictError
|
When the remote has been updated since
the last pull (only when |
connect
Open a DuckDB connection with the DuckLake catalog attached.
The datasource (from fdl.toml name) is attached and selected via
USE, so table references can be bare::
with fdl.connect("default") as conn:
conn.execute("CREATE TABLE cities (...)")
rows = conn.execute("SELECT * FROM cities").fetchall()
| PARAMETER | DESCRIPTION |
|---|---|
target
|
Target name defined in fdl.toml.
TYPE:
|
project_dir
|
Project directory containing fdl.toml. Defaults to the nearest ancestor that contains one.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
DuckDBPyConnection
|
A DuckDB connection with the DuckLake catalog attached. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If |
ValueError
|
If |
default_target_url
Default target URL ($XDG_DATA_HOME/fdl or ~/.local/share/fdl).
Returns a display-friendly path using ~ when under the home directory.