Skip to main content

drasi-lib

PyPI version Python versions license docs

📖 Documentation: https://drasi-project.github.io/drasi-python/ — installation, concepts, the full API reference, guides, and a worked example.

Embed the Drasi continuous-query engine directly in your Python application. drasi-lib is a native PyO3 binding around Drasi's embeddable engine (drasi-lib) and its plugin host SDK (drasi-host-sdk), so you get:

  • In-process continuous queries over a property graph, in Cypher or GQL.
  • A working plugin ecosystem — search, resolve, download, verify and install the Drasi source/reaction/bootstrap plugins published to ghcr.io/drasi-project, picking the build that is compatible with your host.
  • Python-defined components — define a reaction as a Python callback, or a source you push changes into from your own code. No Rust required.
  • Streaming — async for event in drasi.query_results(id), plus lifecycle events and component logs.
  • A blocking API — drasi.sync.Drasi for scripts and notebooks.

Status: pre-1.0. The API is complete — full parity with @drasi/lib plus streaming as async iterators, a blocking facade, and plugin lockfiles. See docs/api-audit.md.

Install

pip install drasi-lib

Imported as drasi. Wheels are abi3 for Python 3.10+ on Linux (x86_64, aarch64), macOS (x86_64, arm64) and Windows (x86_64), so no Rust toolchain is needed. To build from source instead, see Development, or examples/README.md for a step-by-step walkthrough.

Quickstart

Push changes from your own code and react to the results — no plugins needed:

import asyncio
from drasi import Drasi


async def main() -> None:
    async with await Drasi.create("my-app") as drasi:
        await drasi.start()

        await drasi.add_python_source("orders")
        await drasi.add_query(
            "open",
            "MATCH (o:Order) WHERE o.status = 'open' RETURN o.id AS id, o.total AS total",
            ["orders"],
        )

        def on_results(event):
            for diff in event["results"]:
                print(diff["type"], diff.get("data"))

        await drasi.add_python_reaction("watch", ["open"], on_results)

        await drasi.push_change(
            "orders",
            {
                "op": "insert",
                "id": "o1",
                "labels": ["Order"],
                "properties": {"id": "o1", "status": "open", "total": 42},
            },
        )
        await asyncio.sleep(0.5)
        print(await drasi.get_query_results("open"))


asyncio.run(main())

Using a plugin

install_plugin() resolves the build that is compatible with your machine, downloads it, verifies it and loads it:

async with await Drasi.create("my-app") as drasi:
    await drasi.install_plugin("source/mock")
    await drasi.start()

    await drasi.add_source("mock", "counters", {"dataType": {"type": "counter"}, "intervalMs": 500})
    await drasi.add_query("counts", "MATCH (c:Counter) RETURN c.value AS value", ["counters"])

Browse what is available first, if you like:

for plugin in await drasi.search_plugins():
    print(plugin["reference"])  # e.g. source/postgres, reaction/http

Plugin configuration keys are defined by the plugin itself, so they are passed through untouched — dataType above is the mock source's own spelling. Drasi's own API is snake_case, and accepts the Node.js camelCase spellings as aliases.

Plugins

Drasi plugins are self-contained cdylib files distributed as OCI artifacts from ghcr.io/drasi-project, published per platform:

ghcr.io/drasi-project/{type}/{kind}:{version}-{arch}

Because a plugin is a native library loaded into your process, it is only usable by a host built against a compatible set of Drasi crates. install_plugin() handles this for you — it reads the registry index, picks the newest build whose sdk/core/lib versions and target triple match this host, downloads it, optionally verifies its cosign signature, and loads it.

See the plugins guide, or docs/plugins.md for the contributor-facing detail.

Watching a query

Polling is rarely what you want:

async for event in await drasi.query_results("open"):
    for diff in event["results"]:
        print(diff["type"], diff.get("data"))

Lifecycle events (query_events, source_events, reaction_events, all_events) and logs (query_logs, source_logs, reaction_logs) stream the same way, and replay their history first. Callback forms (on_query_results, on_*_events, on_*_logs) exist for parity with the Node.js binding.

Without async

from drasi.sync import Drasi

with Drasi.create("my-app") as drasi:
    drasi.start()
    drasi.add_python_source("orders")
    print(drasi.get_query_results("open"))

Streams become ordinary iterators. Don't use this inside an existing event loop — it will tell you so rather than deadlocking.

Durability

A durable reaction only advances its checkpoint once your callback succeeds, so an unhandled event is replayed after a restart:

drasi = await Drasi.create(
    "app",
    state_store={"kind": "redb", "path": "state.redb"},
    index_store={"kind": "rocksdb", "path": "index"},
)


async def handle(event):
    await write_somewhere(event)  # if this raises, the event is retried


await drasi.add_durable_python_reaction("sink", ["open"], handle)

Status

docs/api-audit.md inventories the public API and compares it against the Node.js bindings and the Rust engine. It is at full parity — 48/48 methods — plus 21 methods Node does not have.

Examples

Runnable programs are in examples/, with a guide covering how to build the package locally and run them. The documentation site also has a worked Postgres dashboard example built entirely on published plugins.

Example What it shows Needs
python_source.py Push changes from your own code; react to results nothing
install_plugin.py Browse the registry, install a plugin, use it network
postgres_cdc.py React to a real Postgres database Docker, network
make venv && make develop
.venv/bin/python examples/python_source.py

Tutorials

Longer, hands-on walkthroughs live in tutorials/. The Building Comfort tutorial builds a smart-building monitor from PostgreSQL CDC, six continuous queries with synthetic joins, and a Python reaction that drives a live Streamlit UI. The tutorials also render on the documentation site.

Development

make venv        # create .venv with a managed Python and the dev tooling
make develop     # build the native extension and install it editable
make test        # unit tests + hermetic end-to-end tests
make test-oci    # download and install real plugins from ghcr.io

Building requires a Rust toolchain. The optional rocksdb feature additionally requires libclang and a C++ toolchain. See CONTRIBUTING.md.

License

Apache-2.0. See LICENSE.

Metadata

Release files for drasi-lib 0.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 drasi-lib 0.3.0
File Size Uploaded Provenance Actions
drasi_lib-0.3.0.tar.gz 608.5 kB With provenance Details for drasi_lib-0.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for drasi-lib 0.3.0
File Actions
drasi_lib-0.3.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for drasi_lib-0.3.0-cp310-abi3-win_amd64.whl
drasi_lib-0.3.0-cp310-abi3-manylinux_2_35_x86_64.whl CPython 3.10 abi3 Linux glibc 2.35+ x86-64 Details for drasi_lib-0.3.0-cp310-abi3-manylinux_2_35_x86_64.whl
drasi_lib-0.3.0-cp310-abi3-manylinux_2_35_aarch64.whl CPython 3.10 abi3 Linux glibc 2.35+ ARM64 Details for drasi_lib-0.3.0-cp310-abi3-manylinux_2_35_aarch64.whl
drasi_lib-0.3.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for drasi_lib-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
drasi_lib-0.3.0-cp310-abi3-macosx_10_13_x86_64.whl CPython 3.10 abi3 macOS 10.13+ x86-64 Details for drasi_lib-0.3.0-cp310-abi3-macosx_10_13_x86_64.whl

Total release size: 52.9 MB

Release files / drasi_lib-0.3.0.tar.gz

Download URL drasi_lib-0.3.0.tar.gz
Size 608.5 kB
Tags Source
SHA-256 checksum
How to use checksums
56a0a6ad79cf3ad3c9fdf3a743e9cbc2c302c585907b1936cb6d043d671e1888
BLAKE2b-256 checksum
How to use checksums
997d30032d285e5f7dcbbf4825f4a76252198e711bb2b9ef5d6e519f13cf166c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 1, 2026.

Transparency log

Release files / drasi_lib-0.3.0-cp310-abi3-win_amd64.whl

Download URL drasi_lib-0.3.0-cp310-abi3-win_amd64.whl
Size 10.8 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
8647b7ec4b99b92a457a0d9e923a4d8507f9070aaad9f11383bcb468948445fb
BLAKE2b-256 checksum
How to use checksums
c59f3d26e523c8b27cfb021ae5c30ae86916b83e207375767904a92bc59575ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 1, 2026.

Transparency log

Release files / drasi_lib-0.3.0-cp310-abi3-manylinux_2_35_x86_64.whl

Download URL drasi_lib-0.3.0-cp310-abi3-manylinux_2_35_x86_64.whl
Size 11.3 MB
Tags CPython 3.10 Linux glibc 2.35+ x86-64 abi3
SHA-256 checksum
How to use checksums
3a0f49faf2a9eab9ccf2c84d4583d97d25545df4abd4e5f2ef82f8936d7db106
BLAKE2b-256 checksum
How to use checksums
3280aa01e84a5d53edfa77328a530c090c39a8a9e89c4d6ede3a832d97fee9ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 1, 2026.

Transparency log

Release files / drasi_lib-0.3.0-cp310-abi3-manylinux_2_35_aarch64.whl

Download URL drasi_lib-0.3.0-cp310-abi3-manylinux_2_35_aarch64.whl
Size 10.6 MB
Tags CPython 3.10 Linux glibc 2.35+ ARM64 abi3
SHA-256 checksum
How to use checksums
470382f19d0a59f3aa33df6f305589dbf91ea8b74ad23eb42db9b4e5f9a685a8
BLAKE2b-256 checksum
How to use checksums
b4a392f434dc1e1142397837bd0e5d06718b0273a8bad21efe78adda65769f72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 1, 2026.

Transparency log

Release files / drasi_lib-0.3.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL drasi_lib-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
Size 9.4 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
51621a45e25bfdcbac9c11968d2ba3de6e814e488439921bcd30eb74dc2c0ca7
BLAKE2b-256 checksum
How to use checksums
3d2dca062eaa3783f887e59caf3fca9b1d3edd76e532bef92097c9ca7e9f6a49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 1, 2026.

Transparency log

Release files / drasi_lib-0.3.0-cp310-abi3-macosx_10_13_x86_64.whl

Download URL drasi_lib-0.3.0-cp310-abi3-macosx_10_13_x86_64.whl
Size 10.2 MB
Tags CPython 3.10 abi3 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
5ca63d37950ddd419d7ddd2bc6bd44db8cecf8c6a6b9fd9dcd0f80015823376d
BLAKE2b-256 checksum
How to use checksums
d339c80ea9d33119adbea22897bce1047b749e80dd438bc416d4200a21c0dd0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 1, 2026.

Transparency log

Security for drasi-lib 0.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 drasi_lib-0.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 Oct 1, 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