Skip to main content

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

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.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for marsdb 0.11.0
File Size Uploaded Provenance Actions
marsdb-0.11.0.tar.gz 596.3 kB Without provenance Details for marsdb-0.11.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for marsdb 0.11.0
File Interpreter ABI Platform Actions
marsdb-0.11.0-cp315-cp315-macosx_11_0_arm64.whl CPython 3.15 CPython 3.15 macOS 11.0+ ARM64 Details for marsdb-0.11.0-cp315-cp315-macosx_11_0_arm64.whl
marsdb-0.11.0-cp315-cp315-macosx_10_12_x86_64.whl CPython 3.15 CPython 3.15 macOS 10.12+ x86-64 Details for marsdb-0.11.0-cp315-cp315-macosx_10_12_x86_64.whl
marsdb-0.11.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details for marsdb-0.11.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Total release size: 9.1 MB

Release files / marsdb-0.11.0.tar.gz

Download URL marsdb-0.11.0.tar.gz
Size 596.3 kB
Tags Source
SHA-256 checksum
How to use checksums
253cdac4b219cbfc5f2298db20573526ce3b637706ef04569cd1e07010280843
BLAKE2b-256 checksum
How to use checksums
5ce06b1231c99db398555fbccf97663a804b126fd667c7928901b78ebce04532
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.11.0-cp315-cp315-macosx_11_0_arm64.whl

Download URL marsdb-0.11.0-cp315-cp315-macosx_11_0_arm64.whl
Size 2.6 MB
Tags CPython 3.15 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
168428bbce6a13865d59c75a5bba415ad2c489c0a04c76178e33162159d5c192
BLAKE2b-256 checksum
How to use checksums
426abba93695387f8b4efddb93d5fb63bb9513192e15c28a9fbd2ee038dc41a3
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.11.0-cp315-cp315-macosx_10_12_x86_64.whl

Download URL marsdb-0.11.0-cp315-cp315-macosx_10_12_x86_64.whl
Size 2.8 MB
Tags CPython 3.15 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
8ce3c6b93330fdf80ea430d495ec5d2db87bff831ce459444205179209494e2b
BLAKE2b-256 checksum
How to use checksums
0a7a50518c7857b2f992f9ede07896ec8898a5da4f1ce47e3f900598038a0837
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.11.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL marsdb-0.11.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 3.1 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
2c26aa04dbc578315bd89d61d46ea2ee8249adb6558a1365e128f4bfc9c7189e
BLAKE2b-256 checksum
How to use checksums
1fe3c123823bb5ad1c6d7df376b4415d17fa53c254035cbec56b208abb7cdd1e
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.11.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page