Skip to content

Commit ff6e060

Browse files
build(kernel): add optional [kernel] extra for use_kernel=True
databricks-sql-kernel is now published to PyPI, so the kernel backend can ship as an optional dependency instead of a local-dev-only build. - pyproject: declare databricks-sql-kernel as an optional dependency gated to python>=3.10 (the wheel is cp310-abi3, Requires-Python >=3.10), and add the `[kernel]` extra. The extra also lists pyarrow: the kernel result path (backend/kernel/result_set.py) imports it unconditionally to wrap the Arrow batches the kernel returns. pyarrow is already pulled transitively via the kernel wheel's pyarrow>=23.0.1,<24, but naming it makes the connector-side requirement explicit and lets pip co-resolve both constraints at install time. - backend/kernel/_errors.py: update the use_kernel=True ImportError to point at `pip install "databricks-sql-connector[kernel]"` and note the python>=3.10 requirement (was the obsolete "not yet published, build locally" hint). - README: document the [kernel] extra, use_kernel=True usage, and the python>=3.10 / pyarrow notes. On python<3.10 the `[kernel]` extra resolves to nothing and use_kernel=True raises the friendly ImportError at runtime; the connector's own python floor (3.8) is unchanged. Verified locally (kernel served from a locally-built cp310-abi3 wheel, since the published package isn't yet mirrored on the dev proxy): - pip install "databricks-sql-connector[kernel]" -> connector + kernel + pyarrow all install; use_kernel=True runs a live query end-to-end (backend KernelDatabricksClient). - plain install -> use_kernel=True raises the friendly ImportError. NOTE: `poetry lock` still needs to be run to refresh poetry.lock with the databricks-sql-kernel entry; it is intentionally NOT included here because it requires the kernel to be resolvable on the index poetry/CI use (the JFrog db-pypi proxy). Confirm the package resolves there before merging. Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
1 parent 0dbec57 commit ff6e060

3 files changed

Lines changed: 50 additions & 18 deletions

File tree

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@ Install using `pip install databricks-sql-connector`
3030
### Installing the core library with PyArrow
3131
Install using `pip install databricks-sql-connector[pyarrow]`
3232

33+
### Installing with the Rust kernel backend (`use_kernel=True`)
34+
Install using `pip install databricks-sql-connector[kernel]`
35+
36+
This adds the optional [`databricks-sql-kernel`](https://pypi.org/project/databricks-sql-kernel/)
37+
extension (a native Rust client core, exposed via PyO3). Pass
38+
`use_kernel=True` to `sql.connect(...)` to route the connection through it
39+
instead of the default Thrift backend:
40+
41+
```python
42+
connection = sql.connect(
43+
server_hostname=host,
44+
http_path=http_path,
45+
access_token=token,
46+
use_kernel=True,
47+
)
48+
```
49+
50+
Notes:
51+
- Requires **Python >= 3.10** (the kernel wheel is published as
52+
`cp310-abi3`). On older interpreters the `[kernel]` extra installs
53+
nothing and `use_kernel=True` raises an `ImportError`.
54+
- The extra also pulls in PyArrow, which the kernel result path requires.
55+
- Authentication supports PAT (`access_token`), OAuth M2M, and OAuth U2M.
56+
3357

3458
```bash
3559
export DATABRICKS_HOST=********.databricks.com

pyproject.toml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,30 @@ pyarrow = [
3232
pyjwt = "^2.0.0"
3333
pybreaker = "^1.0.0"
3434
requests-kerberos = {version = "^0.15.0", optional = true}
35+
# Optional Rust kernel backend for ``use_kernel=True`` (PyO3 wheel).
36+
# Pulled in only via the ``[kernel]`` extra below. The published wheel
37+
# is ``abi3`` with ``Requires-Python: >=3.10`` (built ``abi3-py310``),
38+
# so the dependency is gated to Python >= 3.10: on 3.8/3.9 the
39+
# ``[kernel]`` extra resolves to nothing and ``use_kernel=True`` raises
40+
# a clear ImportError at runtime (see backend/kernel/_errors.py).
41+
databricks-sql-kernel = {version = "^0.1.0", optional = true, python = ">=3.10"}
3542

3643

3744
[tool.poetry.extras]
3845
pyarrow = ["pyarrow"]
39-
# `[kernel]` extra is intentionally not declared here yet.
40-
# `databricks-sql-kernel` is built from the databricks-sql-kernel
41-
# repo and not yet published to PyPI; declaring it as a poetry dep
42-
# breaks `poetry lock` for every CI job. Once the wheel is on PyPI
43-
# the extra will be added back here:
46+
# ``pip install databricks-sql-connector[kernel]`` adds the Rust kernel
47+
# backend so ``use_kernel=True`` works. No-op on Python < 3.10 (the
48+
# wheel's floor) — those users get a runtime ImportError if they pass
49+
# ``use_kernel=True``.
4450
#
45-
# databricks-sql-kernel = {version = "^0.1.0", optional = true}
46-
# [tool.poetry.extras]
47-
# kernel = ["databricks-sql-kernel"]
48-
#
49-
# Until then, the wheel is not on PyPI and the only supported
50-
# install path is local dev:
51-
# cd databricks-sql-kernel/pyo3 && maturin develop --release
52-
# (into the same venv as databricks-sql-connector).
51+
# pyarrow is listed explicitly: the kernel result path
52+
# (``backend/kernel/result_set.py``) imports pyarrow unconditionally to
53+
# wrap the Arrow batches the kernel returns. The kernel wheel already
54+
# declares ``pyarrow>=23.0.1,<24`` so it's pulled transitively, but
55+
# naming it here documents the connector-side requirement and makes pip
56+
# co-resolve both constraints at install time rather than failing at
57+
# ``use_kernel=True`` runtime if the kernel ever drops its pyarrow dep.
58+
kernel = ["databricks-sql-kernel", "pyarrow"]
5359

5460
[tool.poetry.group.dev.dependencies]
5561
pytest = "^7.1.2"

src/databricks/sql/backend/kernel/_errors.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@
5252
import databricks_sql_kernel as _kernel # type: ignore[import-not-found]
5353
except ImportError as exc: # pragma: no cover - same hint as client.py
5454
raise ImportError(
55-
"use_kernel=True requires the databricks-sql-kernel extension, which "
56-
"is not yet published on PyPI. Build and install it locally from the "
57-
"databricks-sql-kernel repo:\n"
58-
" cd databricks-sql-kernel/pyo3 && maturin develop --release\n"
59-
"(into the same venv as databricks-sql-connector)."
55+
"use_kernel=True requires the optional databricks-sql-kernel "
56+
"extension, which is not installed. Install it with:\n"
57+
' pip install "databricks-sql-connector[kernel]"\n'
58+
"The kernel wheel requires Python >= 3.10; on older interpreters "
59+
"use_kernel is unavailable. For local kernel development you can "
60+
"instead build it from the databricks-sql-kernel repo:\n"
61+
" cd databricks-sql-kernel/pyo3 && maturin develop --release"
6062
) from exc
6163

6264
# Route the kernel's Rust-side logs into Python's ``logging`` as soon as

0 commit comments

Comments
 (0)