React Flow graph engine for pytransitions state machines
Project description
transitions_reactflow
A React Flow graph engine extension for the pytransitions state machine library.
Features
- ✅ React Flow compatible graph data
- ✅ Hierarchical states with
childrenparameter - ✅ Smart filtering of unused states
- ✅ Unique edge IDs for duplicate transitions
- ✅ Full type hints with .pyi stub files
- ✅ Comprehensive test suite
Installation
pip install transitions-reactflow
Or install from source:
git clone https://github.com/johnsonlm/transitions-reactflow
cd transitions-reactflow
pip install -e .
Quick Start
from transitions_reactflow import ReactFlowMachine
# Define states with hierarchy
states = [
'idle',
{'name': 'processing', 'children': ['validating', 'payment']},
'completed'
]
# Define transitions
transitions = [
{'trigger': 'start', 'source': 'idle', 'dest': 'processing_validating'},
{'trigger': 'validate', 'source': 'processing_validating', 'dest': 'processing_payment'},
{'trigger': 'finish', 'source': 'processing_payment', 'dest': 'completed'}
]
# Create machine and get graph data
machine = ReactFlowMachine(states=states, transitions=transitions, initial='idle')
graph_data = machine.get_graph()
# Returns: {'nodes': [...], 'edges': [...]}
Usage
With Flask Backend
from flask import Flask, jsonify
from flask_cors import CORS
from transitions_reactflow import ReactFlowMachine
app = Flask(__name__)
CORS(app) # Enable CORS for frontend requests
machine = ReactFlowMachine(states=states, transitions=transitions, initial='idle')
@app.route('/graph-data')
def get_graph_data():
return jsonify(machine.get_graph())
With React Frontend
import ReactFlow from 'reactflow';
function StateMachineFlow() {
const [data, setData] = useState(null);
useEffect(() => {
fetch('/graph-data').then(res => res.json()).then(setData);
}, []);
return data && <ReactFlow nodes={data.nodes} edges={data.edges} fitView />;
}
Hierarchical States
Use children for nested states:
states = [
'idle',
{'name': 'error', 'children': ['validation', 'payment', 'network']}
]
# Creates: error, error_validation, error_payment, error_network
Note: Unused parent states are automatically filtered from the graph.
API
ReactFlowMachine
Extends transitions.extensions.GraphMachine.
get_graph(title=None, roi_state=None)→{'nodes': [...], 'edges': [...]}add_states(states)- supports hierarchical definitions- All standard pytransitions methods
ReactFlowGraph
Extends transitions.extensions.diagrams_base.BaseGraph.
get_graph(title=None, roi_state=None)→ React Flow data- Standard BaseGraph methods
Graph Data Format
The get_graph() method returns React Flow compatible data:
Nodes:
{
"id": "state_name",
"data": {"label": "state_name"},
"position": {"x": 0, "y": 0}
}
Edges:
{
"id": "e-source-target",
"source": "source_state",
"target": "target_state",
"label": "trigger_name"
}
Development
# Tests
pytest tests/
# Coverage
pytest --cov=transitions_reactflow tests/
# Type checking
mypy transitions_reactflow/
License
MIT - see LICENSE file
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Credits
Built on top of the pytransitions library.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file transitions_reactflow-0.1.0.tar.gz.
File metadata
- Download URL: transitions_reactflow-0.1.0.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21a21b6911c876734ce64df594e83efb1a41ae2287a19a2aab0c716f0602f75a
|
|
| MD5 |
6110cb05abef1a954c2ab01f43039ed3
|
|
| BLAKE2b-256 |
19495bb739fc8a59e7d9aa2feaf6225dd31e03e1073f9bf181680443554d9ca2
|
Provenance
The following attestation bundles were made for transitions_reactflow-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on JohnsonLM/transitions-reactflow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
transitions_reactflow-0.1.0.tar.gz -
Subject digest:
21a21b6911c876734ce64df594e83efb1a41ae2287a19a2aab0c716f0602f75a - Sigstore transparency entry: 927325028
- Sigstore integration time:
-
Permalink:
JohnsonLM/transitions-reactflow@4bfe5ccb33904103335134a31eb74511ea1d968f -
Branch / Tag:
refs/tags/v0.1.0-alpha - Owner: https://github.com/JohnsonLM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@4bfe5ccb33904103335134a31eb74511ea1d968f -
Trigger Event:
release
-
Statement type:
File details
Details for the file transitions_reactflow-0.1.0-py3-none-any.whl.
File metadata
- Download URL: transitions_reactflow-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83e9ac3a2f81ffaff279d208e9c1370da654e4feb7f3e699cd0734eb6ead3309
|
|
| MD5 |
e8098c278a83e418631b630e941893e5
|
|
| BLAKE2b-256 |
108369138ca3a256d06ddd951a9a77a326093a3a9525526687e108781bce5567
|
Provenance
The following attestation bundles were made for transitions_reactflow-0.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on JohnsonLM/transitions-reactflow
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
transitions_reactflow-0.1.0-py3-none-any.whl -
Subject digest:
83e9ac3a2f81ffaff279d208e9c1370da654e4feb7f3e699cd0734eb6ead3309 - Sigstore transparency entry: 927325029
- Sigstore integration time:
-
Permalink:
JohnsonLM/transitions-reactflow@4bfe5ccb33904103335134a31eb74511ea1d968f -
Branch / Tag:
refs/tags/v0.1.0-alpha - Owner: https://github.com/JohnsonLM
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@4bfe5ccb33904103335134a31eb74511ea1d968f -
Trigger Event:
release
-
Statement type: