Skip to main content

PyStructurizr

license PyPI version Pylint

PyStructurizr provides a Python DSL inspired by Structurizr, and is intended for generating C4 diagrams.

Overview

Structurizr builds upon "diagrams as code", allowing you to create multiple software architecture diagrams from a single model. A popular way of creating Structurizr workspaces is the Structurizr DSL.

However, Structurizr DSL has some downsides:

  1. It's a custom language, with its own syntax rules and limitations
  2. It has rather primitive support for splitting your diagram code over multiple files, with only #include-like support rather than proper imports. That makes it really hard to maintain C4 models with a team.

PyStructurizr solves that. It implements the same concepts as Structurizr DSL, but now in plain Python. That means you can use the full power and flexibility of Python to define your diagrams!

Example

Consider the following example (as shown on Structurizr's homepage), in Structurizr DSL:

workspace {
    model {
        user = person "User"
        softwareSystem = softwareSystem "Software System" {
            webapp = container "Web Application" {
                user -> this "Uses"
            }
            container "Database" {
                webapp -> this "Reads from and writes to"
            }
        }
    }
    views {
        container softwareSystem {
            include *
            autolayout lr
        }
    }
}

In PyStructurizr, this becomes:

from pystructurizr.dsl import Workspace

# Create the model(s)
with Workspace() as workspace:
    with workspace.Model(name="model") as model:
        user = model.Person("User")
        with model.SoftwareSystem("Software System") as software_system:
            webapp = software_system.Container("Web Application")
            db = software_system.Container("Database")

    # Define the relationships
    user.uses(webapp, "Uses")
    webapp.uses(db, "Reads from and writes to")

# Create a view onto the model
workspace.ContainerView(
    software_system, 
    "My Container View",
    "The container view of our simply software system."
)

For such a simple example, the benefits are not super obvious, but look at the example in this repo for something more realistic.

CLI

PyStructurizr comes with a DSL that allows to convert your Python code to Structurizr DSL, or to immediately generate SVG versions of the diagrams. You can even upload directly to your favorite cloud storage provider: this is ideal if you want to include diagrams on blogs, wiki's, etc.

Finally, there's a development mode so you can get live preview of the diagram you're working on in your webbrowser.

Installation

pip install pystructurizr

Usage

Convert to Structurizr DSL

pystructurizr dump --view <path_to_view_file>

Live preview

pystructurizr dev --view <path_to_view_file>

Convert to SVG and upload to cloud storage

pystructurizr build --view <path_to_view_file> --gcs-credentials <path_to_credentials_json_file> --bucket-name <string> --object-name <string>

Note that this command uses kroki.io under the hood to generate your SVG file. The benefit is that you don't need to install any tools that understand Structurizr DSL on your machine. The downside is that your diagram code is sent to an online service.

License

MIT License

Acknowledgements

Metadata

Release files for pystructurizr 0.1.3

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

Source distribution (sdist)

Source distribution for pystructurizr 0.1.3
File Size Uploaded
pystructurizr-0.1.3.tar.gz 14.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pystructurizr 0.1.3
File Interpreter ABI Platform
pystructurizr-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 26.5 kB

Release files / pystructurizr-0.1.3.tar.gz

Download URL pystructurizr-0.1.3.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f5b06c24e17c3a52a9e1092e9e2e152ac6c59d3aec1231a569789b0cb86e444a
BLAKE2b-256 checksum
How to use checksums
eb5db7ff080ba851a53e0a9e6a3c03768e9189a5f441b62e8ecdd790dff516f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.7

Release files / pystructurizr-0.1.3-py3-none-any.whl

Download URL pystructurizr-0.1.3-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1eb771ce5851e1c86fc2fdd2f189cb8a1dc96e6aa6b374f3dcad0bdf04291536
BLAKE2b-256 checksum
How to use checksums
7e7d9dee36213a509402a7f135acc6d76a378a9c0b4bf3eb7a670661e76297e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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