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.

Not published to PyPI yet — build from the repo with maturin:

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

marsdb-0.9.0.tar.gz (590.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

marsdb-0.9.0-cp314-cp314-macosx_11_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

marsdb-0.9.0-cp314-cp314-macosx_10_12_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

marsdb-0.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file marsdb-0.9.0.tar.gz.

File metadata

  • Download URL: marsdb-0.9.0.tar.gz
  • Upload date:
  • Size: 590.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for marsdb-0.9.0.tar.gz
Algorithm Hash digest
SHA256 f2bf3711b5b55530c8d9a77065fdd19fea04f560a671377e1db9f723f37bc7a3
MD5 e18a0e5af30b674e00e66fec744df438
BLAKE2b-256 194bd7a40920cf36cdb0f95d8a10baf82edb6e79791247388c03420a9ab8dc69

See more details on using hashes here.

File details

Details for the file marsdb-0.9.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for marsdb-0.9.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a5a168fbc5c990631da220827d0ec94254973bf2c24816f8b549e96ade0dc31a
MD5 a9764f0f1f3829258073592b31613e0b
BLAKE2b-256 647cb4d17df7d6c212fdd8b6c57ff2839d9fca275660ba22df2c7c6331ac7294

See more details on using hashes here.

File details

Details for the file marsdb-0.9.0-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for marsdb-0.9.0-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1c579a59786e250bfc908600d19627b7d008e93122e42d50ef829b088d6e448e
MD5 1b2c7382e37426c6b4fbf730e721568b
BLAKE2b-256 5c704095bab4572357045b0150d9f89eb5dca02bf5ea807aa6a0907b70d2ebb0

See more details on using hashes here.

File details

Details for the file marsdb-0.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for marsdb-0.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5dce8f65919d4629d7152cdcd58e6a39c7d8cbc7bf4d189c414b38b87dbd146a
MD5 5e41cd9e5180d7e11cd25fa21fe57cff
BLAKE2b-256 19e66938e14e1243e0f8257a698d066352d173d8484523cc0e79e69e9eeb9ead

See more details on using hashes here.

Release history Release notifications | RSS feed

0.9.1

4 files

This release

0.9.0 This release

4 files

0.8.0

4 files

0.7.1

4 files

0.7.0

4 files

0.6.0

4 files

0.5.0

4 files

0.4.0

4 files

0.3.0

4 files

0.2.0

4 files

0.1.0

3 files

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