Skip to main content

bpmn-io

bpmn.io's bpmn-moddle and bpmn-auto-layout, transposed to pure Python.

Read, check, build, lay out and write BPMN 2.0 XML from Python, with the exact object model and semantics of the reference JavaScript implementation, and no runtime dependency.

Status: the full port is implemented (moddle, moddle-xml, bpmn-moddle, bpmn-auto-layout, bpmnlint) with byte-identical conformance gates; release 0.1.0 is in preparation. Nothing is published on PyPI yet.

bpmn-io is an independent project, not affiliated with bpmn.io or Camunda.

Why this exists

BPMN is a natural target for AI agents written in Python (Google ADK, LangGraph, plain SDK agents, …): an agent can draft a process, check it, lay it out and hand a valid .bpmn file to a human or to an engine. Until now the only faithful implementation of the BPMN 2.0 meta-model (bpmn-moddle) and of automatic diagram layout (bpmn-auto-layout) lived in JavaScript, so a Python agent had to shell out to Node or skip validation altogether.

bpmn-io removes that gap: a 100 % mapped Python port, so the objects, the warnings and the XML you get are the ones bpmn-js, Camunda Modeler and the bpmn.io toolchain produce and expect.

Design principles

  • Literal transposition. Algorithms and test-suites of moddle, moddle-xml, bpmn-moddle and bpmn-auto-layout are ported one-to-one, at the pinned upstream versions listed in UPSTREAM.toml. Every upstream test case must be claimed by a Python test (scripts/port_coverage.py, enforced in CI).
  • Same descriptors. The BPMN 2.0, DI, DC and bioc moddle descriptors are vendored verbatim (sha256-pinned in UPSTREAM.lock), so $type names, properties and serialization rules are identical.
  • Differential oracle. CI also runs the upstream JavaScript packages through Node and compares canonical dumps and emitted XML with the Python port (tests/oracle/).
  • Zero runtime dependency. The lenient SAX parser (saxen) is transposed too, so parsing behaviour, warnings and error positions match upstream exactly.
  • MIT, attributed. See LICENSE and THIRD_PARTY_NOTICES.md.

Usage

from bpmn_io import BpmnModdle, check, layout_process

moddle = BpmnModdle()

# read
result = moddle.from_xml(xml)  # ParseResult(root_element, references, warnings, elements_by_id)
definitions = result.root_element

# check (L0 integrity: warnings, unresolved references, unknown attributes)
report = check(xml)
assert report.ok, report.errors

# build
task = moddle.create("bpmn:Task", {"name": "Review"})
definitions.get("rootElements")[0].get("flowElements").append(task)

# lay out (generates DI for diagrams without one)
laid_out = layout_process(xml)

# write
out = moddle.to_xml(definitions, {"format": True})
print(out.xml)
bpmn-io check process.bpmn            # exit 0 when clean, 1 on errors
bpmn-io check process.bpmn --json     # {"ok": true, "errors": [], "warnings": [], ...}
bpmn-io roundtrip process.bpmn        # parse + serialize back to stdout
bpmn-io layout process.bpmn           # automatic DI layout to stdout
bpmn-io lint --init                   # write a .bpmnlintrc (extends bpmnlint:recommended)
bpmn-io lint process.bpmn             # semantic (L2) lint; exit 1 on errors

API

Name Module Contract
BpmnModdle bpmn_io.bpmn_moddle default model (six descriptors), lax from_xml, to_xml
create_moddle bpmn_io.bpmn_moddle BpmnModdle plus additional descriptor packages
check / Report bpmn_io.check L0 integrity: warnings, unresolved references, unknown attributes
Linter bpmn_io.lint bpmnlint port (L2 semantic rules): lint(root, config) returns reports by rule name; built-in configs bpmnlint:all, bpmnlint:correctness, bpmnlint:recommended
layout_process / Layouter bpmn_io.auto_layout automatic DI layout; LayoutError on failure
is_a bpmn_io.bpmn_moddle.types TypeGuard narrowing on descriptor literal types
ParseResult / ParseError bpmn_io.moddle_xml read result / failure
SerializationResult bpmn_io.bpmn_moddle to_xml result (xml, warnings)
DESCRIPTOR_NAMES / load_descriptor bpmn_io.descriptors vendored descriptor registry
UPSTREAM_VERSIONS bpmn_io.upstream pinned upstream versions

Examples

1. Build a moddle model

from bpmn_io import BpmnModdle

moddle = BpmnModdle()
definitions = moddle.create(
    "bpmn:Definitions", {"id": "D", "targetNamespace": "http://bpmn.io/schema/bpmn"}
)
process = moddle.create("bpmn:Process", {"id": "Hiring", "isExecutable": True})
start = moddle.create("bpmn:StartEvent", {"id": "Apply", "name": "Candidate applies"})
task = moddle.create("bpmn:Task", {"id": "Screen", "name": "Screen resume"})
flow = moddle.create("bpmn:SequenceFlow", {"id": "F1", "sourceRef": start, "targetRef": task})
process.get("flowElements").extend([start, task, flow])
definitions.get("rootElements").append(process)

print(moddle.to_xml(definitions, {"format": True}).xml[:120])
# <?xml version="1.0" encoding="UTF-8"?>
# <bpmn:definitions ... id="D" ...><bpmn:process id="Hiring" isExecutable="true">...

Sketch of the tree you just built (Apply ─F1─▶ Screen, both contained in Hiring):

Definitions "D"
└── Process "Hiring"
    ├── StartEvent "Apply"
    ├── Task "Screen"
    └── SequenceFlow "F1" (Apply → Screen)

2. Lint a file (integrity check)

from bpmn_io import BpmnModdle, check

xml = open("process.bpmn").read()
report = check(xml)  # string level: parse + warnings
print(report.ok, [w.message for w in report.warnings])
# True ['unresolved reference <Flow_Missing>']

report = check(BpmnModdle().from_xml(xml).root_element)  # model level: strict
print(report.ok, report.errors)
# False ['unknown attribute <bogus>']

check is the L0 integrity gate (unparsable input, unknown attributes, dangling references) — the same findings the CLI reports with exit code 1. Semantic business rules are the L2 lint below.

from bpmn_io import BpmnModdle
from bpmn_io.lint import Linter
from bpmn_io.lint.resolver import NodeResolver

root = BpmnModdle().from_xml(xml).root_element
reports = Linter(resolver=NodeResolver()).lint(root, {"extends": "bpmnlint:recommended"})
# {'label-required': [{'id': 'ShipOrder', 'message': 'Element is missing label/name',
#                      'path': ['name'], 'meta': {...}, 'category': 'error'}]}

All 28 bpmnlint rules are ported (bpmnlint:all), with the upstream off|warn|error|info (and numeric 0..3) flags, extends configs and plugin resolution via entry_points(group="bpmnlint.plugins"). Custom rules are plain factories returning {"check": ..., "meta": ...}.

3. Lay out a diagram-less file

from bpmn_io import layout_process

bare = open("no-di.bpmn").read()  # a process without any BPMNDiagram
laid_out = layout_process(bare)  # grid placement + generated DI
assert "BPMNDiagram" in laid_out
open("with-di.bpmn", "w").write(laid_out)

4. Render it with bpmn-js

The Python lib does the modelling; bpmn-js does the pixels. docs/examples/ ships a ready-made pair:

  • example.bpmn — a hiring process generated by bpmn-io itself (same create calls as §1 above, finished with layout_process);
  • viewer.html — a minimal viewer (bpmn-js Viewer from CDN, file picker included).
cd docs/examples && python3 -m http.server 8080
# open http://localhost:8080/viewer.html

The viewer fetches example.bpmn by default; drop any .bpmn produced by the bpmn-io CLI (bpmn-io layout …) into the picker to render your own files.

Development

uv sync                      # Python 3.11+, all dependency groups
uv run pytest                # Python test-suite
uv run ruff check . && uv run ruff format --check . && uv run mypy
uv run python scripts/sync_upstream.py --check     # vendored upstream files untouched
uv run python scripts/port_coverage.py             # upstream test-suite port status
(cd tests/oracle && npm ci --ignore-scripts) && uv run pytest -m oracle   # Node differential tests

See CONTRIBUTING.md for the porting workflow and the release process.

Upstream versions

Upstream Version
saxen 11.2.0
min-dash 5.1.0
moddle 8.2.1
moddle-xml 12.3.1
bpmn-moddle 10.3.1
bpmn-in-color-moddle 0.2.0
bpmn-auto-layout 1.3.0
bpmnlint 11.15.0
bpmnlint-utils 1.1.1
@bpmn-io/moddle-utils 0.3.0

Metadata

Release files for bpmn-io 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bpmn-io 0.2.2
File Size Uploaded Provenance Actions
bpmn_io-0.2.2.tar.gz 1.1 MB With provenance Details for bpmn_io-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bpmn-io 0.2.2
File Interpreter ABI Platform Actions
bpmn_io-0.2.2-py3-none-any.whl Python 3 none any Details for bpmn_io-0.2.2-py3-none-any.whl

Total release size: 1.2 MB

Release files / bpmn_io-0.2.2.tar.gz

Download URL bpmn_io-0.2.2.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
e330f69b8cf5048308f927e4269b10ae1d49e6c232f36c909ead719596d6f9d3
BLAKE2b-256 checksum
How to use checksums
331c1f28b2292325368fceee6031917aed7d4d3f895359883d0956f14e1c1e22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 17, 2026.

Transparency log

Release files / bpmn_io-0.2.2-py3-none-any.whl

Download URL bpmn_io-0.2.2-py3-none-any.whl
Size 163.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
20f7aee5385d982ba5ab7c92802a5ccdf852a51c524001ff20f3f5972f786605
BLAKE2b-256 checksum
How to use checksums
08476275cfcf142b435347bdea106f0ec6bf10e8addacf10588f2505a0e3a099
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 17, 2026.

Transparency log

Security for bpmn-io 0.2.2

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bpmn_io-0.2.2.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 Oct 17, 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.

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