Skip to content

feat: expose CypherEngine in Python for multi-query execution#124

Merged
beinan merged 2 commits intolance-format:mainfrom
ChunxuTang:catalog
Feb 3, 2026
Merged

feat: expose CypherEngine in Python for multi-query execution#124
beinan merged 2 commits intolance-format:mainfrom
ChunxuTang:catalog

Conversation

@ChunxuTang
Copy link
Collaborator

@ChunxuTang ChunxuTang commented Feb 3, 2026

Currently, every call of query.execute() needs to build the catalog, which is an expensive operation. This PR exposes a CypherEngine API in Python for multi-query execution, with a reusable catalog.

An example usage (also included in the README.md):

import pyarrow as pa
from lance_graph import CypherEngine, GraphConfig

cfg = (
    GraphConfig.builder()
    .with_node_label("Person", "id")
    .with_node_label("City", "id")
    .with_relationship("lives_in", "src", "dst")
    .build()
)

datasets = {
    "Person": pa.table({"id": [1, 2], "name": ["Alice", "Bob"], "age": [30, 25]}),
    "City": pa.table({"id": [10, 20], "name": ["London", "Sydney"]}),
    "lives_in": pa.table({"src": [1, 2], "dst": [10, 20]}),
}

# Create engine once - builds catalog
engine = CypherEngine(cfg, datasets)

# Execute multiple queries efficiently - catalog is reused
result1 = engine.execute("MATCH (p:Person) WHERE p.age > 25 RETURN p.name")
result2 = engine.execute("MATCH (p:Person)-[:lives_in]->(c:City) RETURN p.name, c.name")
result3 = engine.execute("MATCH (p:Person) RETURN count(*) as total")

print(result1.to_pylist())
# [{'p.name': 'Alice'}]

@beinan beinan merged commit e433625 into lance-format:main Feb 3, 2026
2 checks passed
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