Skip to content

feat: Python bindings for embedded mode (clickgraph-py)#180

Merged
genezhang merged 4 commits intomainfrom
feature/python-bindings
Mar 5, 2026
Merged

feat: Python bindings for embedded mode (clickgraph-py)#180
genezhang merged 4 commits intomainfrom
feature/python-bindings

Conversation

@genezhang
Copy link
Copy Markdown
Owner

Summary

Adds a clickgraph Python package (via PyO3 + maturin) that exposes the embedded graph query engine to Python users.

Usage

import clickgraph

db = clickgraph.Database("schema.yaml")
conn = db.connect()

for row in conn.query("MATCH (u:User) RETURN u.name LIMIT 5"):
    print(row["u.name"])

API

Class Method Description
Database __init__(schema_path, **kwargs) Open embedded database with optional credentials
Database connect() Create a Connection
Database execute(cypher) Shorthand: query without explicit connection
Connection query(cypher) Execute Cypher, return iterable QueryResult
Connection query_to_sql(cypher) Translate Cypher to SQL (debug)
QueryResult iteration, len(), column_names, num_rows, as_dicts(), get_row(i) Result access

All credential kwargs (S3, GCS, Azure) are passed through to StorageCredentials.

Changes

  • New crate: clickgraph-py/ — PyO3 bindings wrapping clickgraph-embedded
  • Workspace: Added clickgraph-py to workspace members
  • Tests: 14 passing Python tests, 5 skipped (require chdb runtime)
  • Docs: Updated Embedded-Mode wiki with Python library section
  • Cleanup: Removed unused Row import in clickgraph-embedded

Install

cd clickgraph-py
pip install maturin
maturin develop

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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-py and updates Cargo.lock accordingly.
  • 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.

Comment thread docs/wiki/Embedded-Mode.md Outdated
Comment thread clickgraph-py/tests/test_bindings.py Outdated
Comment thread clickgraph-py/tests/test_bindings.py Outdated
Comment thread clickgraph-py/src/lib.rs
Comment thread clickgraph-py/src/lib.rs Outdated
Comment thread clickgraph-py/src/lib.rs Outdated
Comment thread clickgraph-py/src/lib.rs
genezhang and others added 3 commits March 4, 2026 22:04
- 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>
@genezhang genezhang merged commit e65a199 into main Mar 5, 2026
4 checks passed
@genezhang genezhang deleted the feature/python-bindings branch March 5, 2026 06:37
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.

2 participants