Skip to main content

Python bindings for the Lora in-memory graph database

Project description

lora-python

Python bindings for the Lora graph engine. Ships both a synchronous PyO3 Database class and an asyncio-compatible AsyncDatabase wrapper that never blocks the event loop.

Package: lora-python.

Install (local dev)

cd crates/bindings/lora-python
python3 -m venv .venv && source .venv/bin/activate
pip install -U pip maturin pytest pytest-asyncio
maturin develop         # builds the Rust extension into the venv
pytest                  # runs the sync + async smoke tests

maturin develop produces a lora_python/_native.<platform>.so inside the package and makes import lora_python work immediately.

Sync usage

from lora_python import Database, is_node

db = Database.create()
db.execute("CREATE (:Person {name: $n, age: $a})", {"n": "Alice", "a": 30})

res = db.execute("MATCH (n:Person) RETURN n")
for row in res["rows"]:
    n = row["n"]
    if is_node(n):
        print(n["properties"]["name"])

Initialization rule:

from lora_python import Database

scratch = Database.create()            # in-memory
persistent = Database.create("app", {"database_dir": "./data"})  # persistent: ./data/app.loradb

If you want persistence, pass a database name and database_dir to Database.create(...) or Database(...).

Explain & Profile

db.explain() and db.profile() are first-class methods alongside db.execute(). They are intentionally separate calls — neither routes through execute() — so plan inspection and runtime metrics must be requested explicitly.

plan = db.explain(
    "MATCH (p:Person) WHERE p.name = $name RETURN p",
    {"name": "Alice"},
)
print(plan["shape"])             # "readOnly"
print(plan["tree"]["operator"])  # top-most operator label

profile = db.profile(
    "MATCH (p:Person) WHERE p.name = $name RETURN p",
    {"name": "Alice"},
)
print(profile["metrics"]["total_elapsed_ns"])
print(profile["metrics"]["per_operator"])  # per-step inclusive timing

explain() never invokes the executor — calling it on a mutating query (CREATE, MERGE, SET, DELETE, REMOVE) leaves the graph untouched.

profile() executes the query for real. Mutating queries produce the same side effects as execute(). Use explain() to inspect a mutating plan without running it.

Async usage (non-blocking)

import asyncio
from lora_python import AsyncDatabase

async def main():
    db = await AsyncDatabase.create()
    await db.execute("CREATE (:Person {name: 'Alice'})")
    r = await db.execute("MATCH (n:Person) RETURN n.name AS name")
    print(r["rows"])

asyncio.run(main())

Async initialization follows the same rule:

db = await AsyncDatabase.create()            # in-memory
db = await AsyncDatabase.create("app", {"database_dir": "./data"})  # persistent: ./data/app.loradb

AsyncDatabase.execute dispatches the query onto the default asyncio thread pool via asyncio.to_thread. The PyO3 Database.execute releases the Python GIL for the duration of engine work, so other coroutines on the event loop can progress while a query runs. A dedicated test proves the event loop continues ticking during a 2 000-node MATCH.

Typed value model

Same conceptual contract as lora-node / lora-wasm:

Python shape Lora value
None, bool, int, float, str scalars
list, dict collections
{"kind": "node", "id", "labels", "properties"} node
{"kind": "relationship", "id", …} relationship
{"kind": "path", "nodes": [...], "rels": [...]} path
{"kind": "date", "iso": "YYYY-MM-DD"} (and time, …) temporal
point dicts — see below point

Points are returned as dicts keyed on their CRS:

SRID Dict
7203 {"kind": "point", "srid": 7203, "crs": "cartesian", "x", "y"}
9157 {"kind": "point", "srid": 9157, "crs": "cartesian-3D", "x", "y", "z"}
4326 {"kind": "point", "srid": 4326, "crs": "WGS-84-2D", "x", "y", "longitude", "latitude"}
4979 {"kind": "point", "srid": 4979, "crs": "WGS-84-3D", "x", "y", "z", "longitude", "latitude", "height"}

Constructors and guards are exported from lora_python.types: date, time, localtime, datetime, localdatetime, duration, cartesian, cartesian_3d, wgs84, wgs84_3d, is_node, is_relationship, is_path, is_point, is_temporal.

distance() on WGS-84-3D points ignores height — see functions reference for the full spatial reference and known limitations.

Errors

  • LoraError — base class
  • LoraQueryError — parse / analyze / execute failure
  • InvalidParamsError — a parameter value couldn't be mapped

All three are available as lora_python.LoraError, etc.

Persistence

Database.create("app", {"database_dir": "./data"}), Database("app", {"database_dir": "./data"}), and await AsyncDatabase.create("app", {"database_dir": "./data"}) open or create an archive-backed persistent database at ./data/app.loradb. Reopening the same path replays committed writes before returning the handle.

Call db.close() / await db.close() before reopening the same archive inside one process.

For explicit WAL directories with managed snapshots, use open_wal:

db = Database.open_wal(
    "./data/wal",
    {
        "snapshot_dir": "./data/snapshots",
        "snapshot_every_commits": 1000,
        "snapshot_keep_old": 2,
    },
)

snapshot_options accepts the same compression/encryption options as save_snapshot.

Snapshots accept the same broad shapes in sync and async APIs:

import io
from lora_python import Database

db = Database.create()
db.execute("CREATE (:Person {name: 'Alice'})")

meta = db.save_snapshot("./graph.lorasnap")   # path / PathLike
raw = db.save_snapshot("binary")              # bytes
text = db.save_snapshot("base64")             # base64 str
buf = io.BytesIO()
meta = db.save_snapshot(buf)                  # binary writer

db.load_snapshot("./graph.lorasnap")
db.load_snapshot(raw)
db.load_snapshot(io.BytesIO(buf.getvalue()))
db.load_snapshot(text, format="base64")

Architecture

lora-database (Rust)
   └── lora-python (crate, cdylib)             <- PyO3 bindings
          ├── Database (sync, releases the GIL)
          └── python/lora_python/
                 ├── _async.py  AsyncDatabase via asyncio.to_thread
                 └── types.py   typed dicts + constructors + guards

Project details


Download files

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

Source Distribution

lora_python-0.15.0.tar.gz (771.0 kB view details)

Uploaded Source

Built Distributions

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

lora_python-0.15.0-cp38-abi3-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.8+Windows x86-64

lora_python-0.15.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

lora_python-0.15.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

lora_python-0.15.0-cp38-abi3-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

lora_python-0.15.0-cp38-abi3-macosx_10_12_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file lora_python-0.15.0.tar.gz.

File metadata

  • Download URL: lora_python-0.15.0.tar.gz
  • Upload date:
  • Size: 771.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lora_python-0.15.0.tar.gz
Algorithm Hash digest
SHA256 aad93a8543570077a266f983602ead130cd34064bcf3d4c4a724ced1c4064de2
MD5 5d069dda4f39bea81f985ff603f8d3ce
BLAKE2b-256 cfb15254c1eb895f73ef8be9404c5282e4c2f82a1bdc2115f1e1267a42029229

See more details on using hashes here.

Provenance

The following attestation bundles were made for lora_python-0.15.0.tar.gz:

Publisher: packages-release.yml on lora-db/lora

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lora_python-0.15.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: lora_python-0.15.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lora_python-0.15.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 dadbf75debb3b4834cd24ef43aa1a3675a567a7b81a73a1b244fd40e849d9989
MD5 bf156c1f1a096b60af4ceda724c93fdb
BLAKE2b-256 533f538bf981f411ad59a7da20d2bd8b7a725df03bc0fa9001d1fec2a28a1c66

See more details on using hashes here.

Provenance

The following attestation bundles were made for lora_python-0.15.0-cp38-abi3-win_amd64.whl:

Publisher: packages-release.yml on lora-db/lora

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lora_python-0.15.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lora_python-0.15.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fd5cb7531d0cb07cad3111799bba86c8615dfc4339e8bae598c7d6b53c6d6e14
MD5 47a16dafa86dce697f21568457725f45
BLAKE2b-256 b02fd31301046c5040e95718ff12bfe4965de1577f234a3b51588abc988af6e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for lora_python-0.15.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: packages-release.yml on lora-db/lora

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lora_python-0.15.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for lora_python-0.15.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2864df8672fbcca018d556f6d7a1f1b01570165f3fc5d67cdb79e3709f44b3c5
MD5 ccc20ec6788103753d2d689469fa31f7
BLAKE2b-256 5acfadb26b171d3f80bf06f57220613eade0c555f247859a702c732411c4df75

See more details on using hashes here.

Provenance

The following attestation bundles were made for lora_python-0.15.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: packages-release.yml on lora-db/lora

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lora_python-0.15.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lora_python-0.15.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a78c463841c54afea685d42663ed5b01aefaa2f92379448b7af0b1bd55f93893
MD5 892518e4dfdff9644832521c842de43b
BLAKE2b-256 81edaa6033dcd92988aa792807f57261da6c93108ed3f783aef4ae735c7e2fdd

See more details on using hashes here.

Provenance

The following attestation bundles were made for lora_python-0.15.0-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: packages-release.yml on lora-db/lora

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lora_python-0.15.0-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for lora_python-0.15.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 aa3a5b02df6935235f6784c640f0dca150c98d265dd2dbc2cbbbeec7b9bfd2f6
MD5 c47813d1fc74da2180a0e39225af18b7
BLAKE2b-256 ddada217dda40b839525c3b6aa6669ab10435baf7b82e3505c66d1eae9295c37

See more details on using hashes here.

Provenance

The following attestation bundles were made for lora_python-0.15.0-cp38-abi3-macosx_10_12_x86_64.whl:

Publisher: packages-release.yml on lora-db/lora

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page