feat: Python bindings for embedded mode (clickgraph-py)#180
Merged
Conversation
New 'clickgraph' Python package via PyO3 + maturin, exposing the
embedded graph query engine to Python:
import clickgraph
db = clickgraph.Database('schema.yaml')
conn = db.connect()
for row in conn.query('MATCH (u:User) RETURN u.name'):
print(row['u.name'])
API:
- Database(schema_path, **credentials) — open embedded database
- Database.connect() → Connection
- Database.execute(cypher) → QueryResult (shorthand)
- Connection.query(cypher) → QueryResult (iterable of dicts)
- Connection.query_to_sql(cypher) → str (debug)
- QueryResult: iterable, len(), column_names, num_rows, as_dicts(), get_row(i)
All credential kwargs (S3, GCS, Azure) passed through to StorageCredentials.
Tests: 14 passing Python tests (5 skipped — require chdb runtime)
Docs: Updated Embedded-Mode wiki with 'Option C — Python Library' section
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds first-party Python bindings for ClickGraph embedded mode (clickgraph Python package) using PyO3/maturin, exposing an embedded Database/Connection/QueryResult API and documenting Python usage alongside existing embedded-mode options.
Changes:
- Introduces new
clickgraph-py/crate/package with PyO3 bindings, packaging metadata, and pytest-based tests. - Updates the Rust workspace to include
clickgraph-pyand updatesCargo.lockaccordingly. - Updates embedded-mode documentation to include a Python library option; removes an unused Rust import in
clickgraph-embedded.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/wiki/Embedded-Mode.md | Documents Python embedded-mode usage as an additional option. |
| clickgraph-py/src/lib.rs | Implements PyO3 bindings for Database, Connection, and QueryResult. |
| clickgraph-py/python/clickgraph/init.py | Exposes the compiled extension module as a Python package API. |
| clickgraph-py/pyproject.toml | Defines Python build system and maturin configuration. |
| clickgraph-py/README.md | Provides Python user-facing documentation and examples. |
| clickgraph-py/Cargo.toml | Defines the Rust cdylib crate for the Python extension. |
| clickgraph-py/.gitignore | Ignores common Python/build artifacts for the new package. |
| clickgraph-py/tests/test_bindings.py | Adds pytest coverage for bindings and SQL translation behavior. |
| clickgraph-embedded/src/connection.rs | Removes an unused Row import. |
| Cargo.toml | Adds clickgraph-py to workspace members. |
| Cargo.lock | Adds PyO3 and clickgraph-py dependency resolution entries. |
- Connection(db) constructor (Kuzu-style, alternative to db.connect()) - conn.execute() alias for conn.query() (Kuzu-compatible) - conn.run() alias for conn.query() (Neo4j-compatible) - result.has_next() / result.get_next() cursor (Kuzu-compatible) - result.reset_iterator() to restart cursor - result[i] indexing with negative index support - Updated README with API compatibility table - Updated Embedded-Mode.md wiki with all three API styles - 10 new tests (29 total: 20 pass, 9 skip without chdb) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Upgrade pyo3 0.23→0.24 to fix RUSTSEC-2025-0020 (buffer overflow) - rust_value_to_py now returns PyResult, propagates errors with ? - __next__ returns PyResult<Option<PyObject>>, propagates set_item errors - Fix SQL debugging example in wiki (make output generic) - Fix test docstring to match actual test content - Remove unused imports (os, tempfile) in test_bindings.py Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
Adds a
clickgraphPython package (via PyO3 + maturin) that exposes the embedded graph query engine to Python users.Usage
API
Database__init__(schema_path, **kwargs)Databaseconnect()Databaseexecute(cypher)Connectionquery(cypher)Connectionquery_to_sql(cypher)QueryResultlen(),column_names,num_rows,as_dicts(),get_row(i)All credential kwargs (S3, GCS, Azure) are passed through to
StorageCredentials.Changes
clickgraph-py/— PyO3 bindings wrappingclickgraph-embeddedclickgraph-pyto workspace membersRowimport inclickgraph-embeddedInstall
cd clickgraph-py pip install maturin maturin develop