Generate runnable LangGraph code from a concise graph notation
Project description
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.
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 langgraph_codegen-3.0.0.tar.gz.
File metadata
- Download URL: langgraph_codegen-3.0.0.tar.gz
- Upload date:
- Size: 37.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50006b36e96248397f8d4d475ee588a24a1974576bcb1afb2fc036133c44771c
|
|
| MD5 |
1e7b9058250bd8c16724bb4a1ef5f861
|
|
| BLAKE2b-256 |
cd7ebe80154082d9211d6334842351898f2ee190be4442de83aacb63ca620753
|
Provenance
The following attestation bundles were made for langgraph_codegen-3.0.0.tar.gz:
Publisher:
publish-to-pypi.yml on jojohannsen/langgraph-codegen
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langgraph_codegen-3.0.0.tar.gz -
Subject digest:
50006b36e96248397f8d4d475ee588a24a1974576bcb1afb2fc036133c44771c - Sigstore transparency entry: 2170545727
- Sigstore integration time:
-
Permalink:
jojohannsen/langgraph-codegen@dfa5c28fda3960cbb03df777f6e9bbae77cc35bd -
Branch / Tag:
refs/tags/v3.0.0 - Owner: https://github.com/jojohannsen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@dfa5c28fda3960cbb03df777f6e9bbae77cc35bd -
Trigger Event:
push
-
Statement type:
File details
Details for the file langgraph_codegen-3.0.0-py3-none-any.whl.
File metadata
- Download URL: langgraph_codegen-3.0.0-py3-none-any.whl
- Upload date:
- Size: 29.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
516b541003f64de488ac7bf66342713e30b22e469f7358f1fec6483b326af7c4
|
|
| MD5 |
f643b810de7c2972a20a8015c87619a4
|
|
| BLAKE2b-256 |
3dbbf6d0c21224d23dfbde7f2aaafef6ef016ebe48a30ce8f7ff2a1a4d9a74f3
|
Provenance
The following attestation bundles were made for langgraph_codegen-3.0.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on jojohannsen/langgraph-codegen
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langgraph_codegen-3.0.0-py3-none-any.whl -
Subject digest:
516b541003f64de488ac7bf66342713e30b22e469f7358f1fec6483b326af7c4 - Sigstore transparency entry: 2170545798
- Sigstore integration time:
-
Permalink:
jojohannsen/langgraph-codegen@dfa5c28fda3960cbb03df777f6e9bbae77cc35bd -
Branch / Tag:
refs/tags/v3.0.0 - Owner: https://github.com/jojohannsen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@dfa5c28fda3960cbb03df777f6e9bbae77cc35bd -
Trigger Event:
push
-
Statement type: