Skip to main content

relate-db — Relate for Python

An embedded graph database for Python. Query it in Cypher, in-process — no server, no network, nothing to deploy.

Relate is an in-memory property-graph engine written in Rust. This package embeds it as a native extension (import relate): queries run in your process, on a graph that is pure in-memory, a directory, or a single .rl file, made durable by a fsync'd write-ahead log and Parquet checkpoints.

The PyPI name relate belongs to another project; this package is relate-db, and the import is relate.

Install

pip install relate-db

Optional extras — each is only needed for the matching result helper:

pip install "relate-db[pandas]"   # cursor.to_df()
pip install "relate-db[arrow]"    # cursor.to_arrow() (pyarrow)

Wheels are published for Linux (x86-64, aarch64), macOS (arm64) and Windows (x86-64); Python 3.9+ (one abi3 wheel per platform). No Rust toolchain needed.

Quick start

import relate

conn = relate.connect(":memory:")          # or a path: relate.connect("./friends")

conn.execute("CREATE (:Person {name: $name, age: $age})", {"name": "Alice", "age": 30})
conn.execute("CREATE (:Person {name: $name, age: $age})", {"name": "Bob", "age": 28})
conn.execute(
    "MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'}) "
    "CREATE (a)-[:FRIENDS_WITH {since: 2020}]->(b)"
)

cursor = conn.execute(
    "MATCH (p:Person)-[:FRIENDS_WITH]->(f) RETURN p.name AS person, f.name AS friend"
)
for row in cursor:
    print(row["person"], "->", row.friend)   # rows are dicts with attribute access

conn.close()

relate.connect() is a sqlite3-style, DB-API 2.0 flavoured connection (execute, executemany, cursors, commit/rollback, context manager). The native relate.Database is the direct engine handle, with Arrow IPC via execute_arrow().

Persistence

Store Open with
In-memory — gone at exit relate.connect(":memory:")
Directory — WAL + Parquet shards (default) relate.connect("./friends")
Single file — WAL, snapshot and catalog in one .rl file relate.connect("./friends.rl")
Read-only — load once, refuse writes and checkpoints relate.connect("./friends", read_only=True)

A second writable open of the same store is refused (single-writer lease); use read_only=True for readers.

Parameters

Pass a dict and reference values as $name. Python types map the way you would expect: None, bool, int (64-bit), float, str, list/tuple, nested dict, datetime/date/time/timedelta, uuid.UUID (as its string) and bytes (as a list of byte values). Relate adds relate.Duration, relate.Vector and relate.Point for values stdlib types cannot carry without loss. A plain dict with srid/x/y keys stays an ordinary map — points are explicit.

conn.execute("UNWIND $rows AS r CREATE (:Item {id: r.id, tags: r.tags})",
             {"rows": [{"id": 1, "tags": ["a", "b"]}, {"id": 2, "tags": []}]})

Results

Rows are relate.Records — a dict with driver-style conveniences:

row = conn.execute("MATCH (p:Person) RETURN p.name AS name, p.age AS age ORDER BY name").fetchone()
row["name"] == row.name == "Alice"
row.data()      # {"name": "Alice", "age": 30} — nodes, relationships and
                # paths inside the row become plain dicts/lists, like the Neo4j driver
row.to_dict()   # like data(), but nodes/relationships/paths keep ids, labels,
                # endpoints and a "properties" dict — JSON-ready
row.keys()      # ["name", "age"]

On the cursor: fetchone / fetchmany / fetchall, data(), peek(), single() (exactly one row or ResultNotSingleError), keys(), plus to_df() (pandas) and to_arrow() (pyarrow, the fast bulk path).

n = conn.execute("MATCH (p:Person) RETURN count(p) AS n").single().n

summary = conn.execute("MATCH (p:Person) RETURN p").consume()
summary.counters, summary.query_type, summary.namespace
summary.elapsed_ms, summary.parse_ms, summary.plan_ms, summary.execute_ms

graph = conn.execute("MATCH (a)-[r]->(b) RETURN a, r, b").graph()
graph.nodes, graph.relationships          # de-duplicated, id-ordered

Temporal results come back as stdlib types when that is lossless and as relate.Temporal (nanoseconds, IANA zone) when it is not; durations are always relate.Duration. Node and relationship element_id equals Cypher's elementId(), so WHERE elementId(n) = $id finds the entity again. For a quick picture, relate.viz.to_visualization_graph(...) builds a neo4j-viz graph.

Transactions

Autocommit by default: a statement is durable when execute() returns. Turn it off to group statements.

conn.autocommit = False
try:
    conn.execute("CREATE (:Person {name: 'Carol'})")
    conn.execute("CREATE (:Person {name: 'Dan'})")
    bookmark = conn.commit()      # "relate:<n>", the engine's commit sequence
except Exception:
    conn.rollback()
    raise

Closing a connection rolls back an open transaction.

Errors

Every error inherits relate.RelateError (PEP 249 hierarchy: OperationalError, ProgrammingError, DataError, …) and carries the engine's own classification — neo4j_code, gql_status, stage and a retryable flag — so a retry loop never parses messages:

try:
    conn.execute("MATCH (n RETURN n")
except relate.RelateError as e:
    print(e.neo4j_code, e.retryable)

Threads

relate.threadsafety is 1: share the module, not a connection. A connection must be used (and dropped) on the thread that opened it; using it elsewhere raises ProgrammingError and leaves the owner thread's connection intact. In a threaded server, own the connection on one worker thread and submit work to it.

Bigger loads

Send rows in batches with UNWIND $rows, a few tens of thousands per statement, rather than one huge statement or one statement per row.

Serving it over the network

The same engine runs as a server. Start relate serve --bolt 7687 (see the CLI) and use the stock neo4j Python driver against it.

Documentation

The wheel also bundles an agent skill (.agents/skills/relate/SKILL.md, library-skills).

Development

pip install maturin
cd surfaces/relate-python && maturin develop --release

License: Apache-2.0.

Metadata

Release files for relate-db 1.3.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 relate-db 1.3.0
File Size Uploaded Provenance Actions
relate_db-1.3.0.tar.gz 5.7 MB With provenance Details for relate_db-1.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for relate-db 1.3.0
File Actions
relate_db-1.3.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for relate_db-1.3.0-cp39-abi3-win_amd64.whl
relate_db-1.3.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for relate_db-1.3.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
relate_db-1.3.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for relate_db-1.3.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
relate_db-1.3.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for relate_db-1.3.0-cp39-abi3-macosx_11_0_arm64.whl
relate_db-1.3.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for relate_db-1.3.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 56.1 MB

Release files / relate_db-1.3.0.tar.gz

Download URL relate_db-1.3.0.tar.gz
Size 5.7 MB
Tags Source
SHA-256 checksum
How to use checksums
c0a37aea9a17574504cf8cf61aaa9b5de407c2cac7b1ac9f1d1f110d257a59aa
BLAKE2b-256 checksum
How to use checksums
ab953e8c8ff0b0b6b787bd1380154d96dcdeccab6768a989cbb1a99e490ce904
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / relate_db-1.3.0-cp39-abi3-win_amd64.whl

Download URL relate_db-1.3.0-cp39-abi3-win_amd64.whl
Size 10.4 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
b8a1e883b6bf59cc9ad688a1dfd063bceb4086f8fc4a8568d2cb26a9734bf3d7
BLAKE2b-256 checksum
How to use checksums
71f8fe17e96125a3456d20a55ebe091b8a00929007c7b5e010c8d099820dbc8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / relate_db-1.3.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL relate_db-1.3.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 10.5 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
33ba7a6163d3bc2f2220a7ac3719754b091735071ce48c54489978fbacc9d1b4
BLAKE2b-256 checksum
How to use checksums
871743c4f61fc4252c7f98d8f0c88117fd9eea5a4d0731f826a531c0a0a53235
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / relate_db-1.3.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL relate_db-1.3.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 10.0 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
20db5be79fde04bbb2b94999bded569e1f792ef99c33a6e232a717bf5ca91449
BLAKE2b-256 checksum
How to use checksums
326c4b08e970ad2d6acb32092a77ac510487696f27bc5d2e2dcda0352763749a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / relate_db-1.3.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL relate_db-1.3.0-cp39-abi3-macosx_11_0_arm64.whl
Size 9.4 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
af871c1604d417a57b6286ad295f287a1270e016093a5ac5c91c165a7f466c65
BLAKE2b-256 checksum
How to use checksums
2a115618c554d6be0adb5c19f1f5ba4b180427eb8eee2ad525ff11fbb93d1b62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / relate_db-1.3.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL relate_db-1.3.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 10.1 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
2727796b1ec283a64fde447eb3dbc6ed7913105f7154954afbda66e6114581ec
BLAKE2b-256 checksum
How to use checksums
e06df7c645d36ea272c2fdf624fd773f09662b1c8bbfd0a9c4c30a0f11622685
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for relate-db 1.3.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.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for relate_db-1.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

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