Skip to main content

langgraph-codegen

Generate runnable LangGraph code from a concise graph notation.

Write a graph like this (plan_and_execute.lgraph):

# Plan and Execute Agent
START:PlanExecute -> plan_step -> execute_step -> replan_step
replan_step -> is_done ? END : execute_step

and lgcodegen plan_and_execute turns it into a runnable LangGraph program with a state class, node stubs, conditional edge functions, and the compiled graph — all with mock implementations you replace incrementally with real code.

The full notation is specified in graph_notation.md. The short version:

Pattern Meaning
START:StateClass -> node Entry point (or bare START to derive the class name from the file name)
a -> b -> c Chained edges
a -> b, c -> d Fan-out then fan-in
a -> cond ? b : c Boolean conditional routing
a -> switch(b, c, END) Switch routing (function returns the next node name)
a -> field | worker -> b Parallel workers over a state list field (Send API)
STATE: ClassName + field: type Explicit state field declarations

Here are the five graphs from the LangChain "Building Effective Agents" video in this notation:

# Agent
START:MessagesState -> llm_call
llm_call -> should_continue ? environment : END
environment -> llm_call
# Evaluator Optimizer
START:State -> llm_call_generator -> llm_call_evaluator
llm_call_evaluator -> route_joke ? END : llm_call_generator
# Orchestrator Worker
START:State -> orchestrator
orchestrator -> sections | llm_call -> synthesizer -> END
# Parallelization
START:State -> call_llm_1, call_llm_2, call_llm_3 -> aggregator -> END
# Prompt Chaining
START:State -> generate_joke
generate_joke -> check_punchline ? improve_joke : END
improve_joke -> polish_joke -> END

Install

pip install langgraph-codegen

Or from source:

git clone https://github.com/jojohannsen/langgraph-codegen
cd langgraph-codegen
pip install -e ".[dev]"

Quick Start

# List built-in examples (shown in --help epilog)
lgcodegen --help

# Show a built-in example's notation
lgcodegen plan_and_execute --show

# Generate everything into a plan_and_execute/ folder
lgcodegen plan_and_execute

# Run it (mock nodes print their names and track state)
cd plan_and_execute && python main.py

Output of the run — every node is a working mock, conditions route randomly:

NODE: plan_step
NODE: execute_step
NODE: replan_step
CONDITION: is_done. Result: False
NODE: execute_step
NODE: replan_step
CONDITION: is_done. Result: True
{'nodes_visited': ['plan_step', 'execute_step', 'replan_step', 'execute_step', 'replan_step'], 'counter': 5}

CLI

lgcodegen my_workflow.lgraph            # generate all files into my_workflow/
lgcodegen my_workflow.lgraph --state    # state class only
lgcodegen my_workflow.lgraph --nodes    # node functions only
lgcodegen my_workflow.lgraph --graph    # graph builder only
lgcodegen my_workflow.lgraph --stdout   # print instead of writing files
lgcodegen my_workflow.lgraph --show     # print the spec and exit
lgcodegen my_workflow.lgraph --verify   # check generated files execute
lgcodegen my_workflow.lgraph -o outdir  # custom output directory

Generated files for input my_workflow.lgraph:

File Contents
my_workflow_state.py State class (TypedDict) with reducers and initialize_state()
my_workflow_nodes.py Node function stubs (working mocks)
my_workflow_graph.py Conditions, workers, and the compiled StateGraph
main.py Entry point: draws the graph PNG and invokes it
my_workflow.lgraphx Expanded intermediate form of the notation

Replace any mock by editing the generated node functions — the graph wiring stays the same.

Library API

from langgraph_codegen import gen_graph

graph_spec = """
START:StateClass -> first_node
first_node -> should_go_on ? second_node : END
second_node -> END
"""

print(gen_graph("my_graph", graph_spec))

Other generators: gen_state, gen_nodes, gen_conditions, gen_worker_functions, plus parse_spec for the parsed representation.

Development

pip install -e ".[dev]"
pytest              # unit tests
./testit            # generate + execute all 14 examples, writes run.md
./clean             # remove generated example folders

Requires Python 3.10+ and langgraph >= 1.0.

Release files for langgraph-codegen 3.0.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 langgraph-codegen 3.0.0
File Size Uploaded
langgraph_codegen-3.0.0.tar.gz 37.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langgraph-codegen 3.0.0
File Interpreter ABI Platform
langgraph_codegen-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size:66.1 kB

Release files / langgraph_codegen-3.0.0.tar.gz

Download URL langgraph_codegen-3.0.0.tar.gz
Size 37.0 kB
Tags Source
SHA-256 checksum
How to use checksums
50006b36e96248397f8d4d475ee588a24a1974576bcb1afb2fc036133c44771c
BLAKE2b-256 checksum
How to use checksums
cd7ebe80154082d9211d6334842351898f2ee190be4442de83aacb63ca620753
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 14, 2026.

Transparency log

Release files / langgraph_codegen-3.0.0-py3-none-any.whl

Download URL langgraph_codegen-3.0.0-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
516b541003f64de488ac7bf66342713e30b22e469f7358f1fec6483b326af7c4
BLAKE2b-256 checksum
How to use checksums
3dbbf6d0c21224d23dfbde7f2aaafef6ef016ebe48a30ce8f7ff2a1a4d9a74f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.2.1

2 release files

2.0.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.47

2 release files

0.1.46

2 release files

0.1.45

2 release files

0.1.43

2 release files

0.1.34

2 release files

0.1.33

2 release files

0.1.32

2 release files

0.1.31

2 release files

0.1.30

2 release files

0.1.29

2 release files

0.1.28

2 release files

0.1.26

2 release files

0.1.25

2 release files

0.1.24

2 release files

0.1.23

2 release files

0.1.22

2 release files

0.1.21

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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