Add your description here
Project description
justgraph
A lightweight graph-based state machine.
from dataclasses import dataclass
from justgraph import State, FieldUpdate, Graph
from justgraph.reducers import ExtendList, Increment
@dataclass
class ChatState(State):
messages: list[str]
counter: int
graph = Graph([ChatState])
@graph.node("greet")
def greet(state: ChatState) -> list[FieldUpdate]:
return [
FieldUpdate(ChatState, "messages", ExtendList(["hello"])),
FieldUpdate(ChatState, "counter", Increment(1)),
]
@graph.node("log")
def log(state: ChatState) -> list[FieldUpdate]:
print(state.messages)
return []
graph.set_entry_point("greet").add_edge("greet", "log")
app = graph.compile()
app.invoke([ChatState(messages=[], counter=0)])
# ['hello']
Custom Reducers
Subclass Reducer[T] and implement apply(old: T) -> T:
from justgraph import Reducer, FieldUpdate
class Multiply(Reducer[int]):
def __init__(self, factor: int):
self._factor = factor
def apply(self, old: int) -> int:
return old * self._factor
# Use it like any built-in reducer
FieldUpdate(ChatState, "counter", Multiply(3))
Features
- Nodes — functions that receive state and return
FieldUpdates - Edges — wire nodes into a directed graph
- Conditional edges — route based on state
- Parallel fan-out — branches run concurrently via
ThreadPoolExecutor - Reducers —
ExtendList,Increment,Replace, or custom - Multiple states — nodes can depend on different state types
Examples
uv run examples/chat.py
uv run examples/fan_out.py
uv run examples/conditional.py
Tests
uv run pytest
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
justgraph-0.1.1.tar.gz
(4.0 kB
view details)
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 justgraph-0.1.1.tar.gz.
File metadata
- Download URL: justgraph-0.1.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92f41e3c84015168e37cc069b1a7d7c6b6f16d55dfa1b3116fd2672a1ba793bf
|
|
| MD5 |
83e58398311382926ac15c23e205b24b
|
|
| BLAKE2b-256 |
ee770da19a05093b6e47cac20ec9b44ccd04be2d5381c5091301e111760cd66a
|
File details
Details for the file justgraph-0.1.1-py3-none-any.whl.
File metadata
- Download URL: justgraph-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
231594fb48f49af866b464a26597ba28169970f8a706a2c0434e7cc56c04cbcf
|
|
| MD5 |
49fa780e64ae591d887f3a28c0082349
|
|
| BLAKE2b-256 |
747d00a2c27dc73163a4e8cedb41e3f387547c557ebf2accd98ec89c0f1c4369
|