sombra
Python bindings for the Sombra graph database. The package exposes the Stage 8
fluent query builder together with lightweight CRUD helpers that forward to the
Rust planner/executor through pyo3. Native failures are surfaced as typed
exceptions (see wrap_native_error), and both Database and query streams
provide context managers to ensure handles are released promptly.
Typed facade
For schema-aware CRUD helpers that mirror the TypeScript ergonomics, use the
SombraDB wrapper under sombra.typed:
from typing import TypedDict
from typing_extensions import Literal
from sombra.typed import NodeSchema, SombraDB, TypedGraphSchema
class PersonProps(TypedDict):
name: str
age: int
class PersonNode(NodeSchema):
properties: PersonProps
class GraphSchema(TypedGraphSchema):
nodes: dict[str, PersonNode]
edges: dict[str, TypedDict("KnowsEdge", {"from": Literal["Person"], "to": Literal["Person"], "properties": dict})]
schema: GraphSchema = {
"nodes": {"Person": {"properties": {"name": "", "age": 0}}},
"edges": {"KNOWS": {"from": "Person", "to": "Person", "properties": {}}},
}
db = SombraDB("/tmp/typed.db", schema=schema)
friend = db.add_node("Person", {"name": "Ada", "age": 33})
See examples/typed.py for a longer walkthrough that mirrors the Node.js demo.
Quick start
from sombra import Database
from sombra.query import eq
db = Database.open("/tmp/sombra.db")
db.seed_demo()
rows = db.query().nodes("User").where(eq("name", "Ada")).select("name").execute()
print(rows[0]["name"])
# Need request ids or feature flags? Ask for the metadata envelope:
payload = (
db.query().nodes("User").request_id("example").select("name").execute(with_meta=True)
)
print(payload.request_id(), len(payload.rows()))
user_id = db.create_node("User", {"name": "New User"})
db.update_node(user_id, set_props={"bio": "updated"})
db.delete_node(user_id, cascade=True)
# Clean up native handles explicitly or via context managers
db.close()
async def stream_users() -> None:
async with db.query().nodes("User").stream() as stream:
async for row in stream:
print(row["n0"])
Run the end-to-end example in examples/crud.py to see the workflow in action:
python examples/crud.py
Performance
The Python bindings have minimal overhead compared to the Rust core (~3-5%). Benchmark results on a typical developer machine:
| Operation | Throughput |
|---|---|
| Node + edge creation | ~9,000 ops/sec |
| Point reads | ~20,000 reads/sec |
Tips for optimal performance:
-
Use the builder for bulk operations –
db.create()batches all nodes and edges into a single transaction, which is significantly faster than individualcreate_node/create_edgecalls. -
Use release builds – If building from source, always use
maturin develop --release. Debug builds are significantly slower. -
Tune synchronous mode – For write-heavy workloads where durability can be relaxed, set
synchronous="normal"in options. The default"full"ensures every commit is fsync'd. -
Use direct lookups when possible –
db.get_node_record(id)is faster than running a query for single-node fetches.
Benchmarks
benchmarks/crud.py performs simple create/read/update/delete micro-benchmarks
against a throwaway database:
python benchmarks/crud.py
benchmarks/realistic_bench.py runs a larger benchmark comparable to the Node.js and Rust benchmarks:
python benchmarks/realistic_bench.py
Predicate builders accept timezone-aware datetime objects directly and reject naive datetimes so callers do not need to juggle epochs. Property projections ({"var": "a", "prop": "name", "as": "alias"}) return scalar columns when you only need a subset of properties.
Development
Install the native module via maturin:
cd bindings/python
maturin develop --release
python -m pytest tests
Use maturin build to produce distributable wheels once you are ready to
publish the bindings.
Release Workflow
- Land a
featcommit that touchesbindings/python/**whenever you want the PyO3 wheel to bump its minor version. Release Please maps that commit to a newsombrapyrelease PR. - Before merging the PR, build and test the wheel locally:
maturin develop,pytest -q, andmaturin build --release(ormaturin publish --dry-run). - Merge the release PR to tag the repo; the
publish-python.ymlworkflow uploads the wheels to PyPI. Re-runmaturin publishmanually only if the workflow fails.
Metadata
Release files for sombra 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sombra-0.4.0-cp38-abi3-win_amd64.whl | CPython 3.8 | abi3 | Windows x86-64 | Details |
| sombra-0.4.0-cp38-abi3-manylinux_2_34_x86_64.whl | CPython 3.8 | abi3 | Linux glibc 2.34+ x86-64 | Details |
| sombra-0.4.0-cp38-abi3-macosx_11_0_arm64.whl | CPython 3.8 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 3.7 MB
Release files / sombra-0.4.0-cp38-abi3-win_amd64.whl
| Download URL | sombra-0.4.0-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
03d83f4e118cb23ee36263e39bab68f59b6cfec114dac894ef6cade312f66fca
|
|
BLAKE2b-256 checksum How to use checksums |
46da8ab1f8584bb749cd2ea7085a8f15ceb1b395739b72b57fa829998b16b0f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / sombra-0.4.0-cp38-abi3-manylinux_2_34_x86_64.whl
| Download URL | sombra-0.4.0-cp38-abi3-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.8 Linux glibc 2.34+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
681d5ad8cd49a99d1431a7d659abbede2968a0441d6dfc04b81a583b4f50729d
|
|
BLAKE2b-256 checksum How to use checksums |
8874e4ed0a19ecada1f50dad31007916a9319ff850b5c7a3c7201b705eca6277
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / sombra-0.4.0-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | sombra-0.4.0-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8bdbde0a896efb34a41b6cb42466d16fab0a21653fede3399d08ac23d8525521
|
|
BLAKE2b-256 checksum How to use checksums |
b6e67a01cc0c2adab5855984bb6ea7316301f8c8878051123cc7165ed6eb2e36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|