A Python DSL for generating C4 diagrams
Project description
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
- Renderer-agnostic DSL (same code → different outputs)
Rendering backends
Currently supported and planned backends:
-
- local rendering via
plantumlCLI orplantuml.jar - remote rendering via PlantUML server
- local rendering via
-
Mermaid — WIP
The following backends are being explored but are not currently planned:
Getting started
c4-diagrams requires Python 3.10 or higher.
pip install c4-diagrams
Example
Here’s an example of System Context diagram defined in Python:
# diagram.py
from c4 import *
with SystemContextDiagram("Acme Shop Platform") as diagram:
user = Person(
"Customer",
"A registered customer who browses products and places orders.",
)
with EnterpriseBoundary("Acme Corp"):
web_app = System(
"Web Application",
"Customer-facing website for browsing products and placing orders.",
)
api_backend = System(
"Backend API",
"Handles authentication, order processing, and business logic.",
)
email_provider = SystemExt(
"Email Provider",
"Delivers transactional emails.",
)
user >> RelRight("Uses") >> web_app
web_app >> RelRight("Calls API") >> api_backend
api_backend >> RelDown("Sends emails via") >> email_provider
To export the diagram to a rendered artifact, run:
c4 export diagram.py > diagram.png
This generates the diagram below:
diagram.png
For details (renderers, diagram types, API), see the documentation.
Project Links
License
Contribution
Contribution guidelines for this project
Repository initiated with fpgmaas/cookiecutter-uv.
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 c4_diagrams-0.4.2.tar.gz.
File metadata
- Download URL: c4_diagrams-0.4.2.tar.gz
- Upload date:
- Size: 92.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
123ed614fbf8748a2930c799ac724f446f2db705885cc3e075fffad89f5eea5c
|
|
| MD5 |
c2db529d520bf6779676bf1c22790607
|
|
| BLAKE2b-256 |
1f91009136cf823e1e8cac6bbaab1b1bd817df67e93b34c59e86b791af22239e
|
Provenance
The following attestation bundles were made for c4_diagrams-0.4.2.tar.gz:
Publisher:
on-release-main.yml on sidorov-as/c4-diagrams
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
c4_diagrams-0.4.2.tar.gz -
Subject digest:
123ed614fbf8748a2930c799ac724f446f2db705885cc3e075fffad89f5eea5c - Sigstore transparency entry: 1224709159
- Sigstore integration time:
-
Permalink:
sidorov-as/c4-diagrams@75bd1dcd7aa7496cb3287e14788409d8ab208c07 -
Branch / Tag:
refs/tags/0.4.2 - Owner: https://github.com/sidorov-as
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-main.yml@75bd1dcd7aa7496cb3287e14788409d8ab208c07 -
Trigger Event:
release
-
Statement type:
File details
Details for the file c4_diagrams-0.4.2-py3-none-any.whl.
File metadata
- Download URL: c4_diagrams-0.4.2-py3-none-any.whl
- Upload date:
- Size: 105.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75a67a8c13f8000a2ee816b27d5ccfaeaf2fb231faca4813f27e187ec81ed7c8
|
|
| MD5 |
4fb2943e2ebc67e4c53aa48b3ccb1c29
|
|
| BLAKE2b-256 |
3aa4fe56c39fd62198564571a946da42a726868b911caa9f90aea45781d61938
|
Provenance
The following attestation bundles were made for c4_diagrams-0.4.2-py3-none-any.whl:
Publisher:
on-release-main.yml on sidorov-as/c4-diagrams
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
c4_diagrams-0.4.2-py3-none-any.whl -
Subject digest:
75a67a8c13f8000a2ee816b27d5ccfaeaf2fb231faca4813f27e187ec81ed7c8 - Sigstore transparency entry: 1224709213
- Sigstore integration time:
-
Permalink:
sidorov-as/c4-diagrams@75bd1dcd7aa7496cb3287e14788409d8ab208c07 -
Branch / Tag:
refs/tags/0.4.2 - Owner: https://github.com/sidorov-as
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on-release-main.yml@75bd1dcd7aa7496cb3287e14788409d8ab208c07 -
Trigger Event:
release
-
Statement type: