Skip to main content

A Python DSL for generating C4 diagrams

Project description

c4-diagrams logo

A Python DSL for C4 model diagrams.

c4-diagrams

Release PyPI - Python Version Build status Maintainability Code Coverage License Ask DeepWiki

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

Currently supported backends:

  • PlantUML

    • local rendering via plantuml CLI or plantuml.jar
    • remote rendering via PlantUML server
  • Mermaid

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 a system context diagram defined in Python:

# diagram.py
from c4 import (
    EnterpriseBoundary,
    Person,
    System,
    SystemContextDiagram,
    SystemExt,
)
from c4.contrib.plantuml import RelDown, RelRight


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:

readme-diagram

diagram.png

For details (renderers, diagram types, API), see the documentation.

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


Repository initiated with fpgmaas/cookiecutter-uv.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

c4_diagrams-0.6.0.tar.gz (128.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

c4_diagrams-0.6.0-py3-none-any.whl (163.5 kB view details)

Uploaded Python 3

File details

Details for the file c4_diagrams-0.6.0.tar.gz.

File metadata

  • Download URL: c4_diagrams-0.6.0.tar.gz
  • Upload date:
  • Size: 128.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for c4_diagrams-0.6.0.tar.gz
Algorithm Hash digest
SHA256 1dbff14c1b75389a76dba20b8b65b8b0748a9d1b4b0f4ce273b52951dc158340
MD5 ffe30d34dc20d7e252300f785eebedbd
BLAKE2b-256 3816fc87989989f03954ceb5faec242b39f5bec8fe940b090f18a209e83f7146

See more details on using hashes here.

Provenance

The following attestation bundles were made for c4_diagrams-0.6.0.tar.gz:

Publisher: on-release-main.yml on sidorov-as/c4-diagrams

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file c4_diagrams-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: c4_diagrams-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 163.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for c4_diagrams-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e9d09224da0896af5305e1993c3c457e7c8cddb0330b7955c66265b97146530
MD5 f4d4743f92cbac6f2d80f4b21ea92c87
BLAKE2b-256 34fde4659505fe2fde04b46f3ffbc4c431e4aeda2ff49e986f52da26a9ca11a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for c4_diagrams-0.6.0-py3-none-any.whl:

Publisher: on-release-main.yml on sidorov-as/c4-diagrams

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page