Skip to main content

reflex-gravityui-graph

A Reflex custom component that wraps @gravity-ui/graph — a high-performance graph / flowchart / node-editor visualization library that renders the full graph on Canvas when zoomed out (smooth with thousands of nodes) and swaps to HTML/React for rich interactions when zoomed in.

It exposes the whole graph declaratively from Python: pass blocks, connections, settings, colors and constants as plain data, and receive selection / connection / camera events back into your Reflex state.

Status: 0.2.0 (beta). Wraps @gravity-ui/graph@1.11.0. Requires Python ≥ 3.11 and Reflex ≥ 0.10 (React 19).


Installation

uv add reflex-gravityui-graph
# or
pip install reflex-gravityui-graph

The first time the demo (or your app) runs, Reflex installs the npm dependency @gravity-ui/graph automatically.

Quick start

import reflex as rx
from reflex_gravityui_graph import graph_canvas, Block, Connection, Anchor, EAnchorType

a = Block(id="a", x=0, y=0, name="Start",
          anchors=[Anchor(id="out", block_id="a", type=EAnchorType.OUT)])
b = Block(id="b", x=320, y=180, name="End",
          anchors=[Anchor(id="in", block_id="b", type=EAnchorType.IN)])
edge = Connection(source_block_id="a", source_anchor_id="out",
                  target_block_id="b", target_anchor_id="in")


def index() -> rx.Component:
    return graph_canvas(
        blocks=[a.to_dict(), b.to_dict()],
        connections=[edge.to_dict()],
        width="100%",
        height="600px",
    )


app = rx.App()
app.add_page(index)

GraphCanvas fills its container, so always give the component an explicit height (height="600px") or a sized parent.

Why a JSX bridge?

@gravity-ui/graph's React API is hook + imperative: you create a Graph with the useGraph hook, push entities with setEntities, and start() the render loop once the canvas is attached. Reflex components can't call React hooks directly, so this package ships a tiny local bridge (graph_canvas.jsx) that encapsulates that lifecycle and presents a flat, declarative, JSON-serializable prop surface. See docs/sdd/02-architecture.md.

API

graph_canvas(...) / GravityGraph

Prop Type Description
blocks list[dict] Nodes (id, is, x, y, width, height, name, optional anchors, selected, group, meta).
connections list[dict] Edges (sourceBlockId/targetBlockId, optional anchor ids, label, styles, dashed, selected).
settings dict TGraphSettingsConfig (bezier, arrows, labels, drag/zoom, anchors, …).
colors dict RecursivePartial<TGraphColors> view colors.
constants dict RecursivePartial<TGraphConstants> view constants.
config_name str Underlying graph configuration name.
auto_start bool Start the render loop on attach (default True).
zoom_on_start bool Fit camera to graph on attach (default True).
zoom_target str | list "center", a rect, or a list of block ids.
zoom_padding int Padding (px) when fitting on start.
render_html_blocks bool Render rich HTML/React blocks at detailed zoom.

Events (each delivers one plain dict to your handler):

on_block_selection_change, on_connection_created, on_connection_selection_change, on_camera_change, on_block_drag_end, on_state_change.

Domain value objects

Block, Connection, Anchor, EAnchorType, GraphData build and validate the entity payloads in Python (duplicate-id and dangling-edge checks included).

Recipe helpers (reproduce the upstream Storybook stories)

one_block, two_connected_blocks, colored_connections, block_with_anchors, generate_layered_blocks (hundred / thousand / five-thousand block graphs), grouped_graph, default_settings, and the THEMES color presets.

Demo app

A full demo with one page per example category lives in reflex_gravityui_graph_demo/:

uv sync --extra dev
cd reflex_gravityui_graph_demo
uv run reflex run

Pages: Basics · Connections · Scale · Grouping · Camera & Zoom · Theming · Interaction & Events.

Development

This project uses uv.

uv sync --extra dev               # create .venv with Reflex >= 0.10 + dev tools
uv run pytest -q                  # run the test suite
(cd reflex_gravityui_graph_demo && uv run reflex compile)  # demo compiles

# Regenerate the committed .pyi stub after changing the component's props/events
uv run --with ruff python -m reflex_base.utils.pyi_generator custom_components/reflex_gravityui_graph/graph.py

uv build                          # build wheel/sdist into dist/

Reflex 0.10 note: the reflex component init/build/publish/share CLI was removed in Reflex 0.10. This repo builds with plain uv build (setuptools) and ships the .pyi stub generated by Reflex's own pyi_generator (command above).

Releasing

Releases are published to PyPI by the publish.yml workflow via Trusted Publishing — no API token is stored anywhere. To cut a release:

  1. Bump version in pyproject.toml, add a CHANGELOG.md entry, and merge to main.

  2. Tag the merge commit on main and push the tag:

    git switch main && git pull
    git tag -a v0.2.1 -m "v0.2.1"
    git push origin v0.2.1
    

The workflow checks that the tag is on main and matches the pyproject.toml version, runs the tests, builds, and uploads to PyPI (GitHub environment pypi).

See docs/sdd/ for the full Spec-Driven Design artifacts (overview, PRD, architecture, component spec, plan, tasks) and docs/research/ for the upstream research notes.

Credits

License

Apache-2.0 © Ernesto Crespo. @gravity-ui/graph is MIT © YANDEX LLC.

Metadata

Release files for reflex-gravityui-graph 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for reflex-gravityui-graph 0.2.1
File Size Uploaded Provenance Actions
reflex_gravityui_graph-0.2.1.tar.gz 26.2 kB With provenance Details for reflex_gravityui_graph-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for reflex-gravityui-graph 0.2.1
File Interpreter ABI Platform Actions
reflex_gravityui_graph-0.2.1-py3-none-any.whl Python 3 none any Details for reflex_gravityui_graph-0.2.1-py3-none-any.whl

Total release size: 48.6 kB

Release files / reflex_gravityui_graph-0.2.1.tar.gz

Download URL reflex_gravityui_graph-0.2.1.tar.gz
Size 26.2 kB
Tags Source
SHA-256 checksum
How to use checksums
fb59efe14e1119b130e99da63a253187450dea736d25bdc1d37f4faafc79f55c
BLAKE2b-256 checksum
How to use checksums
e8d5b3c380551a3c2091b9780cd0e5140610a485818e9eb7c74b9b37b6373331
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 Oct 24, 2026.

Transparency log

Release files / reflex_gravityui_graph-0.2.1-py3-none-any.whl

Download URL reflex_gravityui_graph-0.2.1-py3-none-any.whl
Size 22.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e5d75e256ff2bfcceca47c3b5c9b44db5b1620967852f70a07c1e3e54a57c9a
BLAKE2b-256 checksum
How to use checksums
17965155dba612de306bc823d4b4df76487e8d102a9b606016fe27ce65e54e47
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 Oct 24, 2026.

Transparency log

Security for reflex-gravityui-graph 0.2.1

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 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for reflex_gravityui_graph-0.2.1.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 24, 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