Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,8 @@ tempfile = "3"
[lib]
name = "databricks_sql_kernel"
crate-type = ["lib", "cdylib", "staticlib"]

# Workspace — the kernel is the root crate; language bindings live as
# sibling members. PyO3 first; napi-rs / etc. slot in here later.
[workspace]
members = [".", "pyo3"]
53 changes: 53 additions & 0 deletions pyo3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright (c) 2026 Databricks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[package]
name = "databricks-sql-kernel-pyo3"
version = "0.1.0"
edition = "2021"
authors = ["Databricks"]
license = "Apache-2.0"
description = "PyO3 Python bindings for the Databricks SQL Kernel"
repository = "https://github.com/databricks/databricks-sql-kernel"

# Built as a Python extension module by maturin. The lib basename here
# only affects the intermediate `.so` cargo produces; maturin renames
# the wheel artifact to `databricks_sql_kernel.<abi>.so` per
# `module-name` in pyproject.toml, and pyo3 derives the `PyInit_*`
# symbol from the `#[pymodule]` function name (not this `[lib].name`).
# Picking a distinct name avoids colliding with the kernel root crate's
# own cdylib output.
#
# `rlib` is included so `cargo test -p databricks-sql-kernel-pyo3`
# can pick up future `#[cfg(test)]` modules in `src/**`. With only
# `cdylib`, cargo silently reports "running 0 tests / ok" even if a
# `#[test]` exists — a real footgun for any later Rust-side test.
[lib]
name = "databricks_sql_kernel_pyo3"
crate-type = ["cdylib", "rlib"]

[dependencies]
databricks-sql-kernel = { path = ".." }

# pyo3 — abi3-py39 lets one wheel cover Python 3.9+.
pyo3 = { version = "0.26", features = ["extension-module", "abi3-py39"] }

# Multi-thread runtime — one per Session, owned on the Rust side.
tokio = { version = "1", features = ["rt-multi-thread"] }

# Arrow handoff. Pinned to 57 to match the kernel's arrow-* deps so we
# share the same RecordBatch / Schema types and never have to convert.
arrow-array = "57"
arrow-schema = "57"
arrow-pyarrow = "57"
16 changes: 16 additions & 0 deletions pyo3/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[build-system]
requires = ["maturin>=1.5,<2.0"]
build-backend = "maturin"

[project]
name = "databricks-sql-kernel"
version = "0.1.0"
description = "Python bindings for the Databricks SQL Kernel (PyO3)"
requires-python = ">=3.9"
license = { text = "Apache-2.0" }
authors = [{ name = "Databricks" }]
dependencies = ["pyarrow>=14"]

[tool.maturin]
module-name = "databricks_sql_kernel"

6 changes: 6 additions & 0 deletions pyo3/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[pytest]
testpaths = tests
# Without rootdir/conftest discovery the `from conftest import live`
# imports in each test module won't resolve. Putting conftest.py in
# `tests/` plus adding tests/ to sys.path is the conventional setup.
pythonpath = tests
54 changes: 54 additions & 0 deletions pyo3/src/auth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2026 Databricks, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Translate Python auth kwargs into a kernel `AuthConfig`.
//!
//! Phase 1 ships PAT only. The kernel surface reserves
//! `AuthConfig::OAuthM2M`, `OAuthU2M`, `OAuthFederation`, and
//! `External`; wiring any of them into the Python wrapper needs a
//! deliberate design decision about credential ownership (does
//! PySQL own OAuth and feed tokens to the kernel, or does the
//! kernel run its own browser flow?). Until that's settled, the
//! connector backend raises `NotSupportedError` for non-PAT auth
//! and the wrapper rejects unknown `auth_type` values here so the
//! mistake surfaces at construction time, not deep inside an HTTP
//! retry loop.

use databricks_sql_kernel::AuthConfig;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;

/// Build a kernel `AuthConfig` from the Python kwargs the `Session`
/// constructor accepts.
///
/// `auth_type` is currently restricted to `"pat"`. Additional
/// variants land when the OAuth ownership question is resolved.
pub(crate) fn build_auth_config(
auth_type: &str,
access_token: Option<String>,
) -> PyResult<AuthConfig> {
match auth_type {
"pat" => {
let token = access_token
.ok_or_else(|| PyValueError::new_err("auth_type='pat' requires access_token"))?;
if token.is_empty() {
return Err(PyValueError::new_err("access_token must not be empty"));
}
Ok(AuthConfig::Pat { token })
}
other => Err(PyValueError::new_err(format!(
"unsupported auth_type {other:?}; only 'pat' is supported today"
))),
}
}
Loading