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/
uv publish                        # publish to PyPI (needs an API token)

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).

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.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 reflex-gravityui-graph 0.2.0
File Size Uploaded Provenance Actions
reflex_gravityui_graph-0.2.0.tar.gz 25.8 kB Without provenance Details for reflex_gravityui_graph-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 47.9 kB

Release files / reflex_gravityui_graph-0.2.0.tar.gz

Download URL reflex_gravityui_graph-0.2.0.tar.gz
Size 25.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e1266744f0a4be558b48c670a51e8b7eeac8e2fc21fe56020ba259dce70a162d
BLAKE2b-256 checksum
How to use checksums
a7368f85e5da2c2f5ac2094f12f482056985cfdeb492b02cbc6b9749447a637c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

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

Download URL reflex_gravityui_graph-0.2.0-py3-none-any.whl
Size 22.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc3c0ad7f3a3ce72b90e83e175abf8c3dd32a843e56d23a44954fd7347c89844
BLAKE2b-256 checksum
How to use checksums
707398c72176d8de7c40adf5a812bc26ab2b879afdb613c630a1389f61327b78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

Security for reflex-gravityui-graph 0.2.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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