Skip to main content

Pydantic Graph

CI Coverage PyPI python versions license

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 pydantic.dev/docs/ai/graph.

Here's a basic example:

from __future__ import annotations

from dataclasses import dataclass

from pydantic_graph import BaseNode, End, GraphBuilder, GraphRunContext, StepContext


@dataclass
class DivisibleBy5(BaseNode[None, object, int]):
    foo: int

    async def run(
        self,
        ctx: GraphRunContext[None],
    ) -> Increment | End[int]:
        if self.foo % 5 == 0:
            return End(self.foo)
        else:
            return Increment(self.foo)


@dataclass
class Increment(BaseNode[None]):
    foo: int

    async def run(self, ctx: GraphRunContext[None]) -> DivisibleBy5:
        return DivisibleBy5(self.foo + 1)


g = GraphBuilder(input_type=int, output_type=int)


@g.step
async def start(ctx: StepContext[None, None, int]) -> DivisibleBy5:
    return DivisibleBy5(ctx.inputs)


g.add(
    g.node(DivisibleBy5),
    g.node(Increment),
    g.edge_from(g.start_node).to(start),
)

fives_graph = g.build()


async def main():
    result = await fives_graph.run(inputs=4)
    print(result)
    #> 5

Metadata

Release files for pydantic-graph 2.66.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 pydantic-graph 2.66.0
File Size Uploaded Provenance Actions
pydantic_graph-2.66.0.tar.gz 46.8 kB With provenance Details for pydantic_graph-2.66.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-graph 2.66.0
File Interpreter ABI Platform Actions
pydantic_graph-2.66.0-py3-none-any.whl Python 3 none any Details for pydantic_graph-2.66.0-py3-none-any.whl

Total release size: 100.7 kB

Release files / pydantic_graph-2.66.0.tar.gz

Download URL pydantic_graph-2.66.0.tar.gz
Size 46.8 kB
Tags Source
SHA-256 checksum
How to use checksums
af31fd3ad5f3446556a270b14e1a43b12996f4bb52a0511f58f739dbacadb3f9
BLAKE2b-256 checksum
How to use checksums
9f60e098cf08a7cad7dce38f2dbb7b977e93ea6204e99f61c33bcc76df71a7bf
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 Nov 4, 2026.

Transparency log

Release files / pydantic_graph-2.66.0-py3-none-any.whl

Download URL pydantic_graph-2.66.0-py3-none-any.whl
Size 54.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b2a0aafc569c00fdb36879b1e80bed06ed5926979e2c1d44533222f208fd2ec
BLAKE2b-256 checksum
How to use checksums
7d0c2c2ff8a1ede97bb734a56e5b4991a9a98dd05b9ba9f5d8683e4acfdc9d34
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 Nov 4, 2026.

Transparency log

Security for pydantic-graph 2.66.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pydantic_graph-2.66.0.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 Nov 4, 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.

Release history Release notifications | RSS feed

This release

2.66.0 This release

2 release files Full provenance

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