Graph and state machine library
Project description
Pydantic Graph
Graph and finite state machine library.
This library is developed as part of Pydantic AI, however it has no dependency
on pydantic-ai or related packages and can be considered as a pure graph-based state machine library. You may find it useful whether or not you're using Pydantic AI or even building with GenAI.
As with Pydantic AI, this library prioritizes type safety and use of common Python syntax over esoteric, domain-specific use of Python syntax.
pydantic-graph allows you to define graphs using standard Python syntax. In particular, edges are defined using the return type hint of nodes.
Full documentation is available at ai.pydantic.dev/graph.
Here's a basic example:
from __future__ import annotations
from dataclasses import dataclass
from pydantic_graph import BaseNode, End, Graph, GraphRunContext
@dataclass
class DivisibleBy5(BaseNode[None, None, int]):
foo: int
async def run(
self,
ctx: GraphRunContext,
) -> Increment | End[int]:
if self.foo % 5 == 0:
return End(self.foo)
else:
return Increment(self.foo)
@dataclass
class Increment(BaseNode):
foo: int
async def run(self, ctx: GraphRunContext) -> DivisibleBy5:
return DivisibleBy5(self.foo + 1)
fives_graph = Graph(nodes=[DivisibleBy5, Increment])
result = fives_graph.run_sync(DivisibleBy5(4))
print(result.output)
#> 5
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 pydantic_graph-1.29.0.tar.gz.
File metadata
- Download URL: pydantic_graph-1.29.0.tar.gz
- Upload date:
- Size: 58.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87cd673f7333c2db312595696beff597f4de4f6767c954d4e65964f54cb4b073
|
|
| MD5 |
b94537d44137c33da8a81af672b6c5ee
|
|
| BLAKE2b-256 |
38daa27008203273e6adc8ebdfa1390ead7bc66d710229d9bd6955c98e07407a
|
Provenance
The following attestation bundles were made for pydantic_graph-1.29.0.tar.gz:
Publisher:
ci.yml on pydantic/pydantic-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_graph-1.29.0.tar.gz -
Subject digest:
87cd673f7333c2db312595696beff597f4de4f6767c954d4e65964f54cb4b073 - Sigstore transparency entry: 756316400
- Sigstore integration time:
-
Permalink:
pydantic/pydantic-ai@f6d1152b04db8f6d20b1cef3da4620602abfe2c6 -
Branch / Tag:
refs/tags/v1.29.0 - Owner: https://github.com/pydantic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@f6d1152b04db8f6d20b1cef3da4620602abfe2c6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pydantic_graph-1.29.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_graph-1.29.0-py3-none-any.whl
- Upload date:
- Size: 72.3 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 |
5b2e12902423007508ecd216b4d47e7c95b544530868adc32b93756dcb6b1ba0
|
|
| MD5 |
59dc6bd927e3d21e487aa7c187d6c1ba
|
|
| BLAKE2b-256 |
33ff52f4c1f6b65da79c4853dea925e46e7003be7391543550bebdf320e3a032
|
Provenance
The following attestation bundles were made for pydantic_graph-1.29.0-py3-none-any.whl:
Publisher:
ci.yml on pydantic/pydantic-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_graph-1.29.0-py3-none-any.whl -
Subject digest:
5b2e12902423007508ecd216b4d47e7c95b544530868adc32b93756dcb6b1ba0 - Sigstore transparency entry: 756316447
- Sigstore integration time:
-
Permalink:
pydantic/pydantic-ai@f6d1152b04db8f6d20b1cef3da4620602abfe2c6 -
Branch / Tag:
refs/tags/v1.29.0 - Owner: https://github.com/pydantic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@f6d1152b04db8f6d20b1cef3da4620602abfe2c6 -
Trigger Event:
push
-
Statement type: