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
  • network source adapters: HttpRequest, HttpResponse, HttpStreamHead, HttpStreamHeadEvent, HttpStreamChunkEvent, HttpStreamErrorEvent, HttpStreamCompleteEvent, HttpStreamDriverEvent, SseEvent, LocalHttpDriver, LocalHttpStreamDriver, from_http, from_sse
  • 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 exposes facade methods only; raw protocol ingress, arbitrary message construction/sending, and native handles remain hidden.

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.

from_http and from_sse follow the same boundary rule: callers provide both an explicit AsyncRunner and a host-owned driver. The package does not own an event loop or ship a default HTTP client in this slice; from_sse parses text/event-stream bytes from LocalHttpStreamDriver without hidden retry, reconnect, or Last-Event-ID management.

Documentation

This repo owns the Python package docs: public docstrings, generated Python API reference, Starlight source pages, examples, PyPI install material, and package release notes, plus the package-local website/ site configuration. The package-local docs policy is docs/docs.jsonl.

Shared graphrefly.dev website architecture, shared concepts, protocol authority, and the public blog stay in ~/src/graphrefly under D563. Generated API output comes from docstrings through the griffe-backed Starlight generator; do not edit generated website/src/content/docs/api/ output by hand.

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 python scripts/check_api_docs.py
cd website && pnpm docs:gen:check
cd website && pnpm build
python -c "import graphrefly; print(graphrefly.version())"

The Python repo validates Starlight and griffe-generated API output and deploys the package-local docs artifact to https://py.graphrefly.dev/. The shared ~/src/graphrefly website links to this route but does not copy generated Python API pages into the main graphrefly.dev artifact.

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.23.0-cp312-abi3-win_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12+Windows ARM64

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

Uploaded CPython 3.12+Windows x86-64

graphrefly-0.23.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.23.0-cp312-abi3-musllinux_1_2_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ ARM64

graphrefly-0.23.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.23.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (997.9 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

graphrefly-0.23.0-cp312-abi3-macosx_11_0_arm64.whl (990.1 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

graphrefly-0.23.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.23.0-cp312-abi3-win_arm64.whl.

File metadata

  • Download URL: graphrefly-0.23.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.23.0-cp312-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 8dfbe33ca1f825e0901c0131e8fa1fde90c2a459ebad591795fafe6812929a51
MD5 8043b5b34f73f76eac1309c0e748cf44
BLAKE2b-256 43345b15227b1e66cf482139135e5c7fc904607962d397a79e967fc730fce3a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.23.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.23.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: graphrefly-0.23.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.23.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b6410342d727a82f9a487268a8a33e7d0ad41e72885015409d7d20f837e200e2
MD5 4894403ee5fe5ed7eddbd00319dcd5d7
BLAKE2b-256 6f236f53357ce589875026834fb65bd0d6a6a313ec1a82869706a7996db5bcf4

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.23.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.23.0-cp312-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for graphrefly-0.23.0-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 714026a0b776a21053e6990cf8af584206bf5ce4d4d72e90155c6e7d40c2255d
MD5 58940c3b7b8659ff3c7098be717a1a07
BLAKE2b-256 d365370b904a084eac448db44c4da7e1665aee2f8c42e70b2abcfda9506c32e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.23.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.23.0-cp312-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for graphrefly-0.23.0-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 d7bc04fa24f934822e1637714defabd8dcaead4ea95d95350ea92ecdab3ecaa0
MD5 fd7402bb5166c468808e92f9f4b145fa
BLAKE2b-256 26882c13016b198fe4f15a19f4539f876c86c521cddc9cc1cec0066e72fcacb9

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.23.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.23.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for graphrefly-0.23.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ce6effe2b0603548846d63db0b5576ac5dd283506e49d7024c92894271cc832e
MD5 1f67b5ec7687f9acecce0c9533608c44
BLAKE2b-256 8bf87625a8add00e7cd8c2d2df7c26fa62420c1d0c49a75e4961546e6168c409

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.23.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.23.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for graphrefly-0.23.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 85403dff18833bd6f3fd06648eb7db7259ca890cc47a4598fd30f235016c32c6
MD5 cb118fbcb2db34737161a367fded4816
BLAKE2b-256 9267b6e6c89f15fcb8850e1ce11ef227b400f4e9a59d8950c75a353ab15f4981

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.23.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.23.0-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for graphrefly-0.23.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a7cde0b77ffaf8c8cf47110d7b77a216954aa1099df7a224568676963b922d67
MD5 4475fda54240964e9e3d74cc1175f329
BLAKE2b-256 6241d7430fe9fa0c4f6ad1371938ec4959e5e08ea37294366fd9f1de026ec32a

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.23.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.23.0-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for graphrefly-0.23.0-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a3f269ef44ece156ddc4bbd48bb2e93017ee8fbe7366530fe46c46161a8165df
MD5 cc0326ffb6220863187192221671e6a9
BLAKE2b-256 910a777a2ddf78a5c3ff070e46d3d3bfde6f3357f36eeb36a5879f53630d5614

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphrefly-0.23.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