Skip to main content

Python host package for GraphReFly over the native Rust graph engine.

Project description

GraphReFly Python

graphrefly is the Python host package for GraphReFly: a reactive graph runtime with a Python-owned facade over the native Rust engine.

Install it from PyPI:

pip install graphrefly

GraphReFly is alpha software, but the Python host/native binding closeout is now backed by the clean-slate conformance suite. The package requires Python 3.12+.

Quick Start

from graphrefly import Graph


with Graph("hello") as graph:
    count = graph.state(1, name="count")
    doubled = graph.derived([count], lambda value: value * 2, name="doubled")

    with doubled.subscribe(lambda msg: print(msg.kind, msg.value)):
        count.set(2)
        count.set(3)

    assert doubled.cache() == 6

The subscription receives the initial cached value and each later update. The graph owns the node topology; with Graph(...) closes facade resources when the scope exits.

Core Shape

from graphrefly import Graph


graph = Graph("demo")

source = graph.state(1, name="source")
plus_one = graph.derived([source], lambda value: value + 1, name="plus_one")
advanced = graph.node(
    [source],
    lambda ctx: ctx.emit(ctx.data(0) + 10),
    name="advanced",
)

with plus_one.subscribe(lambda msg: print(msg.kind, msg.value)):
    source.set(4)

assert plus_one.cache() == 5
assert advanced.cache() == 14
assert plus_one.status in {"settled", "resolved"}

Use Graph.derived(...) for value-level functions. Use Graph.node(...) when you need the callback-scoped Ctx surface for advanced graph behavior such as per-node state, raw wave data reads, invalidation hooks, pull demand, or deferred rewire.

Public Surface

The Python facade exports:

  • Graph, Node[T], Ctx, PullContext, RewireNext
  • Subscription, Retain, GraphReentryQueue
  • DataMessage[T], ErrorMessage, ControlMessage, Message[T], GraphEvent
  • SENTINEL for raw ctx.wave_data INVALIDATE/no-DATA projection
  • checkpoint and restore helpers: GraphCheckpoint, RestoreRef, RestoreContext, RestoreDescriptor, RestoreRegistry, restore_ref, restore_registry, restore_graph
  • async boundary helpers: AsyncRunner, from_awaitable, from_async_iter, async_node, asyncio_runner, trio_runner, anyio_runner
  • wire bridge facades: wire_bridge, wire_bridge_protobuf, wire_edge_group, wire_bridge_ack_driver
  • public exceptions under GraphReflyError

The private native extension is loaded as graphrefly._native; it is not the public API.

Boundary Notes

  • The sync wave protocol runs in Rust. Python callbacks enter through the native dispatcher path; Python does not reimplement the wave core.
  • Native graph handles are single-thread host objects in this foundation slice.
  • None is valid Python DATA. Absence of DATA is separate and Node.cache() raises GraphReflyNoDataError when no DATA is present. Use Node.cache(default=...) or Node.has_value for non-exceptional absence handling.
  • ctx.wave_data is the raw advanced dep input shape. Ergonomic helpers such as ctx.data() and ctx.has_data() are derived from that shape.
  • Graph.close() and with Graph(...) are Python host lifetime scopes. They release facade-created subscriptions/observers and graph-owned retain roots; they do not emit protocol TEARDOWN or COMPLETE.
  • Public Python does not expose raw Node.up(msgs), raw Node.down(msgs), arbitrary message construction/sending, raw ctx.up(msgs), or raw PyO3 handles.

Async Runners

Async work enters only through explicit runner helpers. The core API does not own an asyncio loop, Trio nursery, AnyIO task group, background thread, portal, or hidden pump.

Install optional runtime adapters with:

pip install "graphrefly[async]"
import trio
from graphrefly import Graph, from_awaitable, trio_runner


async def fetch_value() -> int:
    return 42


async def main() -> None:
    graph = Graph("trio-demo")

    async with trio.open_nursery() as nursery:
        node = from_awaitable(
            graph,
            trio_runner(nursery),
            fetch_value,
            name="value",
        )
        with node.subscribe(lambda msg: print(msg.kind, msg.value)):
            await trio.lowlevel.checkpoint()

When a host runtime completes work away from the graph owner thread, keep re-entry explicit:

graph = Graph("queued-demo")
queue = graph.reentry_queue()
runner = queue.wrap_runner(host_owned_runner)
node = from_awaitable(graph, runner, fetch_value, name="queued")

with node.subscribe(lambda msg: None):
    queue.drain(max_items=None)

The queue accepts only GraphReFly-owned private completions; it is not a public callable enqueue or graph mutation channel.

Documentation

Local Development

This package expects sibling checkouts:

~/src/graphrefly-py
~/src/graphrefly-rs

Install and test:

uv sync --group dev --group docs
cd ../graphrefly-rs
mise exec -- bash -lc 'cd ../graphrefly-py && uv run maturin develop --release'
cd ../graphrefly-py
uv run pytest
uv run ruff check .
uv run mypy src
uv run mkdocs build --strict
python -c "import graphrefly; print(graphrefly.version())"

The Rust foundation can be checked directly from the sibling repo:

cd ~/src/graphrefly-rs
mise exec -- cargo test -p graphrefly-bindings-py

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

graphrefly-0.22.0-cp312-abi3-win_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12+Windows ARM64

graphrefly-0.22.0-cp312-abi3-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.12+Windows x86-64

graphrefly-0.22.0-cp312-abi3-musllinux_1_2_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ x86-64

graphrefly-0.22.0-cp312-abi3-musllinux_1_2_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ ARM64

graphrefly-0.22.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

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

graphrefly-0.22.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.0 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

graphrefly-0.22.0-cp312-abi3-macosx_11_0_arm64.whl (992.2 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

graphrefly-0.22.0-cp312-abi3-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

Details for the file graphrefly-0.22.0-cp312-abi3-win_arm64.whl.

File metadata

  • Download URL: graphrefly-0.22.0-cp312-abi3-win_arm64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.12+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for graphrefly-0.22.0-cp312-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 a52218ed95baf36310e5b8335f0e6d92160dc71a22d1e6f61df02a80bbc300e7
MD5 7839c07d3fa2b9fd2ebd66fe85e1def9
BLAKE2b-256 241ddd0df0607b18c49d45b14d050be62a0d7cff0273f0d07f2551adc47cfb0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.22.0-cp312-abi3-win_arm64.whl:

Publisher: release.yml on graphrefly/graphrefly-py

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

File details

Details for the file graphrefly-0.22.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: graphrefly-0.22.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for graphrefly-0.22.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2e68c814819077cd77f3081e13ff24a5ee20513b453a69e61a18f44970dee5ae
MD5 2acbd1e83a5bac758a31cbd9b2b07879
BLAKE2b-256 36b946ed07764a6b254928dc5a3777bc2896e5ff51ea41014a0f126defdc162a

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.22.0-cp312-abi3-win_amd64.whl:

Publisher: release.yml on graphrefly/graphrefly-py

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

File details

Details for the file graphrefly-0.22.0-cp312-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for graphrefly-0.22.0-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 199735f0034a49bd94de9d57509fdf83be4760c736f526f657d4a656de66932b
MD5 f3e0f9948ba54880e8d6883054899749
BLAKE2b-256 7ce6b26622ff197d2e7d461ad702729d85a8903fab16f077275cdc466d61352b

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.22.0-cp312-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on graphrefly/graphrefly-py

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

File details

Details for the file graphrefly-0.22.0-cp312-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for graphrefly-0.22.0-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 10f71423adab9aa35d29a22b6996afeca7308b22f2e2c9e23d1c4ad18783d28f
MD5 4b74146d8a9b0cf7af10b20513f763b3
BLAKE2b-256 890b7ea88e748af325eb8dfae75d94730a5e0c72bfda53d2b5a2fde840191505

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.22.0-cp312-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.yml on graphrefly/graphrefly-py

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

File details

Details for the file graphrefly-0.22.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for graphrefly-0.22.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 210452ad7af2bf91168d1c600d684580b7617d9f027e9501c97e8a9faf9a4081
MD5 53fd936618bf0ee284ea7c3b2938e426
BLAKE2b-256 a3fbfa08a993abcb68f2c67d72595bdd6631c5120244982fcf30b8d47968b4c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.22.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on graphrefly/graphrefly-py

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

File details

Details for the file graphrefly-0.22.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for graphrefly-0.22.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e5ab729e54334ca8329a88dc0301943b2d8aa59ded070e8394b120e983e54af8
MD5 60bc9f05eb50952a07b2bed8f098e8e5
BLAKE2b-256 477d51f3349dc556693a4f8cdcacf3066bd27894bd4cd9d76586dded1cfacbc4

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.22.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on graphrefly/graphrefly-py

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

File details

Details for the file graphrefly-0.22.0-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for graphrefly-0.22.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 377e7daf1b968aafa85d7f7fbdacc2bf2f7292865bd9a123296e00f4f5805284
MD5 3ef0268f359e2ff37fcfbc8c277e9b1e
BLAKE2b-256 c924c54903b9e569f16ff05d707c022c3905cb579ae35ce0612b7eb147904d92

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.22.0-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on graphrefly/graphrefly-py

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

File details

Details for the file graphrefly-0.22.0-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for graphrefly-0.22.0-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a1cfa53fbba513658d9ce8e75082e1e059e01f614ca4b6dd4fb89ce1c2cc2f77
MD5 255431dc503b76c9d31b610396209b32
BLAKE2b-256 c921eef24d14d0b3e6ef07c2928b23b5dc4e6c3290f1ba1ef9540f0e070f2341

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.22.0-cp312-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on graphrefly/graphrefly-py

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