Repository navigation
refactor(python): wrap the compiled classes in typed, documented python classes - #71
Merged
Merged
Conversation
The public lance_csr classes are now pure-Python wrappers around the private compiled module, carrying the type hints and NumPy docstrings. The Python API reference is generated from them with mkdocstrings, read statically, so the docs builds don't need the compiled extension. The public API is unchanged. Enums become IntEnums with the same names and values; a wrong argument class raises TypeError naming the parameter. Python-facing docstrings move out of the Rust bindings, and the Rust API reference on docs.rs is linked from the docs.
Deploying lance-csr with
|
| Latest commit: |
99a145f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://939951d0.lance-csr.pages.dev |
| Branch Preview URL: | https://refactor-python-api-wrappers.lance-csr.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The public
lance_csrclasses were the compiled PyO3 classes, re-exported. Their docstrings lived in Rust///comments, and the API reference page was written by hand, so every Python API change meant re-checking that page line by line against the bindings. Generating the page instead would have meant importing the compiled extension during the docs build, which puts a Rust build into both the GitHub Actions check and the Cloudflare Pages build.This follows the pattern LanceDB, Polars and pylance use. The public classes become thin Python classes with type hints and NumPy docstrings, each holding a private compiled object, and mkdocstrings reads them statically. The docs build stays Markdown-only (a strict build takes about 1.3 seconds), and the reference can't drift from the signatures.
What changed
The public API is unchanged: same names, signatures, behaviour and exceptions.
lance_csr._internal. Builders still return new objects, and methods that return a config, such asCypherEngine.config(), return the publicGraphConfig.ExecutionStrategy,SqlDialectandDistanceMetricareIntEnums with the same member names and integer values.GraphConfigis expected, raisesTypeErrornaming the parameter.GraphConfig()still has no public constructor and raisesTypeErrorpointing atGraphConfig.builder().with_node_labelandwith_relationshipstill point at the caller's line.GraphConfigBuilder.build()documentingRuntimeErrorwhen it raisesValueError.make testand in Python CI. The docs workflow also runs when the Python package changes.Per-call cost of the wrapper, measured in one process against the compiled object directly: 13 to 86 ns per call. A one-row Cypher query on a 100-row table takes about 0.9 ms in the same debug build, so the wrapper is within noise there.
Validation
make test: 1,590 passed, including new tests that check each wrapper against the compiled class (members, signatures, enum values), that every public method is documented and typed, and the wrapper seams (builders,TypeError, enum pass-through, deprecation warning location).make lint: ruff, format and Pyright pass, including the strict public-API typing check, unchanged.cargo fmt --check,cargo clippy --workspace --all-targets -- -D warnings(and on the bindings crate),cargo test --workspace: pass.zensical build --strictpasses without the compiled extension on the path; every docstring cross-reference and page link resolves. Checked the page in light and dark mode and at phone width.docs/check_snippets.py(every page's Python examples) anduvx typos@1.26.0 .: pass.Benchmarks
Measured with the
CONTRIBUTING.mdharness: release wheels frommain(57a3326) and this branch (99a145f), both suites,memoryandlazymodes, alternating builds and running each twice. Every run passed (30 queries in graph-benchmark-ldbc at b649bc1, 14 in graph-benchmark-ldbc-complex at f3e63fd), and each runner loaded the built wheel, not the pinned release. Apple M5, 10 cores, 24 GB, macOS (Darwin 25.6.0).mainrunsmemorylazymemorylazyEvery change is well within the 15 to 20% run-to-run range the guide describes, so this shows no measurable slowdown. The largest single-query change, Q30 in graph-benchmark-ldbc
lazy(+8.7%), goes the other way inmemory(-5.7%).graph-benchmark-ldbc, `memory` mode
Geometric mean of branch/main ratios: 1.007 (+0.7%). Between the two
mainruns: 0.999 (-0.1%), largest single-query gap 6%.graph-benchmark-ldbc, `lazy` mode
Geometric mean of branch/main ratios: 1.015 (+1.5%). Between the two
mainruns: 0.999 (-0.1%), largest single-query gap 6%.graph-benchmark-ldbc-complex, `memory` mode
Geometric mean of branch/main ratios: 1.005 (+0.5%). Between the two
mainruns: 0.984 (-1.6%), largest single-query gap 4%.graph-benchmark-ldbc-complex, `lazy` mode
Geometric mean of branch/main ratios: 1.007 (+0.7%). Between the two
mainruns: 1.013 (+1.3%), largest single-query gap 6%.🤖 Generated with Claude Code