A Python DSL for C4 model diagrams.
c4-diagrams
c4-diagrams is a Python DSL for defining C4 model architecture diagrams as code.
The package provides first-class abstractions for C4 entities — people, systems, containers, components, boundaries, and relationships — allowing you to describe software architecture in Python and render it into multiple diagram formats.
Features
- Declarative Python DSL for C4 modeling
- First-class C4 entities and relationships
- Multiple rendering backends
- Suitable for documentation, ADRs, and architecture reviews
- Portable core DSL for the common C4 subset, with backend-specific features available through contrib extensions
Rendering backends
| Backend | What you describe | Formats | Docs |
|---|---|---|---|
| PlantUML | Portable diagram, rendered as C4-PlantUML | PNG, SVG, EPS, LaTeX, TXT, UTXT | PlantUML backend |
| Mermaid | Portable diagram, rendered as Mermaid C4 (experimental) | PNG, SVG, PDF | Mermaid backend |
| D2 | Portable diagram, rendered as D2 | PNG, SVG, PDF | D2 backend |
| Structurizr | Structurizr Workspace (model, views, styles) |
PNG, SVG, PDF | Structurizr backend |
| LikeC4 | LikeC4 Project (specification, model, views) |
PNG, JPG | LikeC4 backend |
Getting started
c4-diagrams requires Python 3.10 or higher.
pip install c4-diagrams
Example
Here’s an example of a system context diagram defined in Python:
# diagram.py
from c4 import Person, Rel, System, SystemContextDiagram
with SystemContextDiagram("Online Shop") as diagram:
customer = Person("Customer", "Buys goods online.")
shop = System("Online Shop", "Takes orders from customers.")
payments = System("Payment Provider", "Processes card payments.")
customer >> Rel("Buys goods") >> shop
shop >> Rel("Takes payments") >> payments
To export the diagram to a rendered artifact (PlantUML by default), run:
c4 export diagram.py > diagram.png
This generates the diagram below:
diagram.png
The same diagram renders with Mermaid and D2, and Structurizr and LikeC4 have their own authoring models. See the documentation for all backends, and the Examples page for more diagram types.
Project Links
License
This project bundles files from the C4-PlantUML project. C4-PlantUML is licensed under the MIT License.
Contribution
Contribution guidelines for this project
Acknowledgements
Repository initiated with fpgmaas/cookiecutter-uv.
Metadata
Release files for c4-diagrams 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| c4_diagrams-0.8.0.tar.gz | 235.9 kB | With provenance | Details for c4_diagrams-0.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| c4_diagrams-0.8.0-py3-none-any.whl | Python 3 | none | any | Details for c4_diagrams-0.8.0-py3-none-any.whl |
Total release size: 544.1 kB
Release files / c4_diagrams-0.8.0.tar.gz
| Download URL | c4_diagrams-0.8.0.tar.gz |
|---|---|
| Size | 235.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fe206ed1805400331e27eb326e864eaaef3035d0f675aef57813ba16b197dfbc
|
|
BLAKE2b-256 checksum How to use checksums |
0cf5b20fd70475167841461bf30746a65318b55fad7d46b50e810096abb66644
|
| 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 Nov 13, 2026.
Transparency logRelease files / c4_diagrams-0.8.0-py3-none-any.whl
| Download URL | c4_diagrams-0.8.0-py3-none-any.whl |
|---|---|
| Size | 308.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
167881a7c8b1f6e4d41450207d914ef5802f0d37ad43812813a9546ab249c840
|
|
BLAKE2b-256 checksum How to use checksums |
a6a4a6d34f431f98e915f047a2b58591468d6e757de2561bb1b45909c4c9c70c
|
| 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 Nov 13, 2026.
Transparency logSecurity for c4-diagrams 0.8.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
Both files in this release have been uploaded with provenance metadata.
Attestation for c4_diagrams-0.8.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 13, 2026.
Transparency logA 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.