Skip to content

feat!: publish the Python host as the sqlload-python-host crate - #368

Merged
kvlonge merged 5 commits into
mainfrom
feat/python-host
Nov 26, 2026
Merged

kvlonge merged 5 commits into
mainfrom
feat/python-host

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Another pyo3 extension can now run its Python tables on SQLLoad's engine without copying the crossing.

  • New crate sqlload-python-host holds the crossing and the host, moved out of the sqlload extension.
    • module_host(runtime) is the engine's PythonHost over a Python runtime module the host provides. That module defines discover, start_table, current_state, table_state, rename and finish_run.
    • table_stream, transform_stream, read_error and error_text are building blocks for a host that implements PythonHost itself.
    • It re-exports pyo3 (0.29, abi3-py310). The first read fails when the interpreter's sqlload-api isn't the crate's version, and the error names the version to install.
  • sqlload_api.Context and Connection move from sqlload, together with Context.from_read(read, **extras) for hosts and their subclasses. Transforms and the crossing's callbacks move to sqlload_api._host, so a process has one transform registry. sl.Context is the same object as before.
  • PythonSource.host is an opaque value the engine copies unread into each of the source's TableReads.
  • Breaking (Rust): PythonSource, TableRead and ProjectConfig are #[non_exhaustive]. PythonSource::new and TableRead::new build them.
  • Release:
    • publish.yml publishes sqlload, then sqlload-python-host, with the same OIDC token.
    • The release-metadata check covers the crates' exact workspace pins.
    • verify.yml packages both crates with cargo package.
    • sqlload-python-host 0.0.0 is already on crates.io, reserving the name. Its trusted publisher (sqlstack-io/sqlload, publish.yml, environment crates) needs to be in place before the release runs.
  • Example host: an unpublished one (crates/sqlload-python-host-example, with its Python side in tests/external_host) loads into DuckDB through module_host, from make test-python. It covers:
    • its own table declarations;
    • an ExampleContext(sqlload_api.Context) with a field read from host;
    • an sqlload_api.http job with a page transform;
    • the version-mismatch error.
  • Docs: the crate's README, and an "Embedding the Python host" section on the Python sources page.

Checks run

  • cargo fmt --all --check, the three make check-ci clippy runs and fensu check (0 faults), all on Rust 1.95.0.
  • cargo package --no-verify --locked -p sqlload -p sqlload-python-host, and maturin sdist for sqlload.
  • Focused Python tests:
    • sqlload-api (including the new test_host.py);
    • the external host;
    • the sqlload declare, crossing, cursor, logged-state, Python-sources, transforms, rename, batched, API-wire and HTTP tests (642 passed).

Also in this PR

  • fix(motherduck): a command returns only once its MotherDuck bridges have exited. Dropping a bridge's last handle closed its stdin, and a detached thread reaped the process. So sqlload could return while the bridge still held DuckDB's file lock. That race was already on main, and it caused the flaky test_motherduck.py failure.
    • Dropping the last handle now waits for the bridge to exit, and ends it after 10 s.
    • The watchdog's interrupt thread holds only a weak handle, so the bridge doesn't outlive the command through that thread.
    • make test-python passes --rootdir to pytest, so test IDs show their real paths instead of packages/sqlload-api/….
  • feat: check how a table's options combine when the project is parsed. The settings-only combination rules move into one place, a new table_options module. The loader's build_spec and parse_project / parse_python_project both call it. So these mistakes are reported before anything connects, for TOML and Python tables, with plan's wording at the table's entry. Rules that need the discovered table stay at plan. A new parse test covers every rule. The integration cases that expected plan to refuse these combinations moved there.

Another pyo3 extension can now run its Python tables on SQLLoad's engine
without copying the crossing:

- The crossing and the host move from the sqlload extension into
  sqlload-python-host. module_host(runtime) is the engine's PythonHost
  over a Python runtime module the host provides. table_stream,
  transform_stream, read_error and error_text are building blocks for a
  host that implements PythonHost itself. The crate re-exports pyo3
  (0.29, abi3-py310) and fails the first read when the interpreter's
  sqlload-api is not its own version.
- Context and Connection move to sqlload_api, with Context.from_read
  for a host (or a subclass with fields of its own). Transforms and the
  crossing's callbacks move to sqlload_api._host, so a process has one
  transform registry. sl.Context is the same object as before.
- PythonSource takes an opaque host value that the engine copies unread
  into each of the source's TableReads.
- Publish releases sqlload, then sqlload-python-host, with the same
  crates.io token, and the release-metadata check covers both exact
  workspace pins.
- An unpublished example host (crates/sqlload-python-host-example,
  tests/external_host) loads into DuckDB through module_host from
  make test-python.

BREAKING CHANGE: PythonSource, TableRead and ProjectConfig are
#[non_exhaustive]; build PythonSource and TableRead with their new
constructors.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Deploying sqlload with  Cloudflare Pages  Cloudflare Pages

Latest commit: bdbbd9e
Status: ✅  Deploy successful!
Preview URL: https://c789d187.sqlload.pages.dev
Branch Preview URL: https://feat-python-host.sqlload.pages.dev

View logs

…ave exited

The last handle of a bridge closed its stdin and left the exit to a
detached thread, so sqlload could return while the bridge still held the
database it opened, and the next command (or a reader) hit DuckDB's file
lock. Dropping the last handle now waits for the bridge to exit, ending
it after 10 s. The memory watchdog's interrupt thread holds a weak
handle, so that wait happens on the command's own path, not on that
thread.

make test-python roots pytest at the repository, so test IDs name their
real paths instead of sqlload-api's folder.
The rules for how a table's options combine (merge needs a unique_key,
replace takes no cursor, append takes no lookback, a setting for another
strategy, and the rest the loader enforced from settings alone) ran only
when a table was planned. A tool that validates a project offline, such
as one calling parse_python_project, never saw them.

They now live in one place, the table_options module. The loader's
build_spec calls it as it plans a table, and parse_project and
parse_python_project call it for every table entry, Python tables
included, before anything connects. A source that lists no tables is
checked with its own settings, which every table it finds takes. Parse
reports each problem at the table's entry with plan's wording.

Rules that need the discovered table (its columns, its primary key and
its nullability, constants, a missing write_strategy) stay at plan.

The integration test cases that expected plan to refuse settings-only
combinations moved to a parse test covering every rule, for TOML and
Python sources.
…se test

These combinations are refused when the project is parsed, which stops
the whole command, so the container tests that expected plan to refuse
one table no longer reach plan. Each case is a parse test case now (a
masked newest_by column, a cursor on a delete_insert by replace_key,
null_cursor = "include" on append and delete_insert, and
on_overlapping_files on a merge, an append and a delete_insert by
cursor), with the full message the container tests checked.

The postgres_cdc files case that checks a source which cannot list its
tables is refused while another source loads no longer declares a
postgres_cdc source merging into a files target, which the project
parse refuses; the parse test covers that.
…smoke tests

The wheel smoke tests installed the sqlload wheel with --find-links dist.
Before Release Please bumps the version, the branch's sqlload-api has the
version of the release already on PyPI, so pip took PyPI's copy, which
lacks this branch's modules. Each install now names dist's sqlload_api
wheel too: the smoke test on every OS, its Linux ODBC container, and the
MySQL Connector/ODBC smoke script. The Makefile already installs the
local package, and published-smoke.yml keeps installing from PyPI.
@kvlonge
kvlonge merged commit a67c058 into main Nov 26, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant