marsdb (Python)
Python bindings for MarsDB, an embeddable property-graph database with an openCypher query subset: single file on disk (or fully in-memory), no server, ACID transactions. In-process via PyO3 — no C ABI, no sockets, queries run on the calling thread.
pip install marsdb
Prebuilt wheels cover macOS (arm64, x86_64) and Linux (x86_64, manylinux); other platforms install from the source distribution and need a Rust toolchain.
To build from source instead:
cd marsdb-python
maturin develop --release
Quickstart
import marsdb
db = marsdb.Database.in_memory() # or marsdb.Database.open("graph.db")
db.execute("CREATE (a:Person {name: 'Alice'})-[:KNOWS {since: 2001}]->(b:Person {name: 'Bob'})")
for row in db.execute("MATCH (a:Person)-[:KNOWS]->(b) RETURN a.name, b.name"):
print(row["a.name"], "knows", row["b.name"])
execute runs one Cypher statement and returns a list of dicts, one
per result row, keyed by column name.
Parameterized queries
execute takes an optional params dict resolving $name placeholders
— no string interpolation, no escaping bugs:
db.execute(
"MATCH (p:Person {name: $name}) RETURN p.age",
{"name": "O'Hara"},
)
Values may be None/bool/int/float/str, or nested list/dict
of those. Ints keep their full 64-bit range; an int outside i64 raises
instead of truncating. Map-valued params work ($m.city).
Errors
Everything raised derives from marsdb.Error; subclasses expose the
engine's own taxonomy so programs catch selectively instead of
string-matching:
| Exception | Raised for |
|---|---|
ProgrammingError |
syntax/semantic errors, unbound variables, missing $params, stray COMMIT |
DataError |
type errors, integer overflow, unstorable parameter values |
IntegrityError |
unique-index violations, deleting a connected node without DETACH |
OperationalError |
timeout, cancellation, max_rows exceeded, storage failures |
Execution bounds
db.execute("MATCH (n) RETURN n", max_rows=100_000, timeout_ms=5_000)
Both are checked during evaluation — a runaway query raises
OperationalError at the bound instead of materializing an unbounded
result first, so it can't OOM the process.
Streaming (bulk export)
db.execute_streaming(
"MATCH (n:Person) RETURN n.name AS name",
lambda row: writer.writerow(row), # return False to stop early
)
Rows are pushed one at a time — bounded memory no matter how many rows
match. Accepts exactly the streamable shape (one plain MATCH ... RETURN, SKIP/LIMIT fine) and raises ProgrammingError for ORDER BY/aggregation/DISTINCT/WITH — those must see all rows before
emitting any, so streaming them would be pretend; use execute.
Arrow (pyarrow / polars / pandas / DuckDB)
query_arrow returns the result as an Arrow stream — an object
implementing the Arrow PyCapsule protocol, accepted directly by any
Arrow consumer with zero per-value conversion:
import pyarrow as pa
table = pa.table(db.query_arrow("MATCH (n:Person) RETURN n.name AS name, n.age AS age"))
df = table.to_pandas() # or polars.from_arrow(table), duckdb.sql(...)
Column types are inferred strictly, per column over the whole result:
int64 (full 64-bit, exact), float64, string, bool, date32,
month-day-nano interval for durations, ISO-8601 text for other
temporals, lists of one element type. A column mixing ints and floats
raises DataError — silent promotion to float would corrupt integers
beyond 2⁵³; cast in the query (toFloat/toInteger) instead. So do
node/relationship/map/path columns: project scalar properties.
The stream is single-use (hand it to one consumer); batch_rows
(default 8192) sets rows per record batch, and .stats carries the
statement's write counters. pyarrow itself is not a dependency of
this package — anything speaking the protocol works.
Value mapping
| Cypher | Python |
|---|---|
| integer | int (full 64-bit, no precision loss) |
| float / string / boolean / null | float / str / bool / None |
| list / map | list / dict |
| node | {"id": ..., "labels": [...], "props": {...}} |
| relationship | {"id": ..., "label": ..., "src": ..., "dst": ..., "props": {...}} |
| date / duration | ISO-8601 str |
Transactions
BEGIN / COMMIT / ROLLBACK are statements (BEGIN TRANSACTION
also accepted). One session per Database handle; reads inside a
transaction see its own uncommitted writes; a statement that fails at
execution time rolls the whole transaction back.
db.execute("BEGIN")
db.execute("CREATE (:Account {id: 1, balance: 100})")
db.execute("CREATE (:Account {id: 2, balance: 0})")
db.execute("COMMIT") # or ROLLBACK to discard both
Schema introspection
db.execute("CALL db.labels()") # [{'label': 'Person', 'count': 2}]
db.execute("CALL db.relationshipTypes()") # [{'relationshipType': 'KNOWS', 'count': 1}]
db.execute("CALL db.propertyKeys()") # [{'propertyKey': 'name'}, ...]
db.execute("CALL db.indexes()") # [{'label': ..., 'property': ..., 'unique': ...}]
Examples
examples/commit_graph.py— build a graph of a git repo's history (commits, files,TOUCHESedges).examples/visualize_commit_graph.py— render it as a PNG.
Tests
maturin develop && python -m unittest discover tests
Cypher coverage, benchmarks, and the full manual live in the main repository.
Metadata
Release files for marsdb 0.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| marsdb-0.10.0.tar.gz | 596.8 kB | Without provenance | Details for marsdb-0.10.0.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| marsdb-0.10.0-cp314-cp314-macosx_11_0_arm64.whl | CPython 3.14 | CPython 3.14 | macOS 11.0+ ARM64 | Details for marsdb-0.10.0-cp314-cp314-macosx_11_0_arm64.whl |
| marsdb-0.10.0-cp314-cp314-macosx_10_12_x86_64.whl | CPython 3.14 | CPython 3.14 | macOS 10.12+ x86-64 | Details for marsdb-0.10.0-cp314-cp314-macosx_10_12_x86_64.whl |
| marsdb-0.10.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | CPython 3.9 | Linux glibc 2.17+ x86-64 | Details for marsdb-0.10.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
Total release size: 9.1 MB
Release files / marsdb-0.10.0.tar.gz
| Download URL | marsdb-0.10.0.tar.gz |
|---|---|
| Size | 596.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
66a154779d6b5d07df122f49694934e216bd6d2ec52a14c97b8698e6ad1d48c9
|
|
BLAKE2b-256 checksum How to use checksums |
8f094155c1eca5df8eed3cf9a553b2af966f3312fe35c558a89c270fe7eca8f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / marsdb-0.10.0-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | marsdb-0.10.0-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.6 MB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
d94fba6bcc0f2b95bf695f26ec3283bbe1bc9014c5fe583e88612a93c48bf899
|
|
BLAKE2b-256 checksum How to use checksums |
7c5f978a9951104c86ef7bc430c5dadcbabd3315713954e858a6b846224ba1dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / marsdb-0.10.0-cp314-cp314-macosx_10_12_x86_64.whl
| Download URL | marsdb-0.10.0-cp314-cp314-macosx_10_12_x86_64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.14 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
ba2d2b621282a2882b31a7f9294dd50983e0ee553be39641b9f4b0028869425f
|
|
BLAKE2b-256 checksum How to use checksums |
78d6d1f1bcbf92cc3f7615af919830bce984c1dc00c138338551270c9e7768ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / marsdb-0.10.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | marsdb-0.10.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 3.1 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
7d217054d75d419060680c6499f1ee08f3a0531806ed8cd09843bda9aa74a9eb
|
|
BLAKE2b-256 checksum How to use checksums |
8b95051e1acc0b22bbaacd7c08b2131c77f73f97a8ed890c65648c90fafd1572
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for marsdb 0.10.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.