Skip to main content

A Python library that makes creating PlantUML diagrams intuitive via type hints

Project description

plantuml-compose

A Python library that makes creating PlantUML diagrams intuitive and type-safe.

Why plantuml-compose?

PlantUML is powerful but its text syntax can be cryptic. What does A -[#red,dashed]-> B mean? What options are available for a state transition?

plantuml-compose solves this by providing:

  • Discoverable APIs: Use your IDE's autocomplete to explore options
  • Type safety: Catch errors before rendering, not after
  • Pure factory functions: Compose diagrams declaratively with nesting
  • Full PlantUML coverage: Every diagram type, every feature

Quick Start

from plantuml_compose import sequence_diagram, render

d = sequence_diagram(title="API Call")
p = d.participants
e = d.events

client = p.actor("Client")
server = p.participant("Server")
d.add(client, server)

d.phase("Request", [
    e.message(client, server, "GET /users"),
    e.reply(server, client, "200 OK"),
])

print(render(d))

The Pattern

Every diagram follows the same shape:

# 1. Create diagram — get namespace(s)
d = state_diagram(title="Lifecycle")
el = d.elements
t = d.transitions

# 2. Create elements via namespace factories
idle = el.state("Idle")
active = el.state("Active")

# 3. Register elements
d.add(idle, active)

# 4. Create and register connections
d.connect(
    t.transitions(
        (el.initial(), idle, "start"),
        (idle, active, "go"),
        (active, el.final(), "done"),
    )
)

# 5. Render
print(render(d))

Namespaces organize the API — type d.elements. or d.transitions. and your IDE shows every available factory method.

Bulk helpers reduce repetition:

# Instead of individual calls:
t.transition(a, b, label="x"),
t.transition(b, c, label="y"),
t.transition(c, d, label="z"),

# Use the plural form:
t.transitions(
    (a, b, "x"),
    (b, c, "y"),
    (c, d, "z"),
)

# Or fan-out from one source:
r.arrows_from(api,
    (db, "queries"),
    (cache, "reads"),
    (queue, "publishes"),
)

Styling

Two levels of styling are available on every diagram type.

Inline styles on individual elements and connections:

# Element styling
el.state("Error", style={"background": "#FFCDD2", "line_color": "red"})

# Connection styling — string shorthand or dict
t.transition(a, b, style="dashed")
t.transition(a, b, style={"color": "red", "pattern": "dotted"})

# Arrow length (layout hint)
r.arrow(a, b, length=1)   # short: ->
r.arrow(a, b, length=3)   # long:  --->

# Custom arrow heads
r.arrow(a, b, left_head="o", right_head=">>")  # o-->>

Diagram-wide styling via diagram_style=:

d = class_diagram(
    title="Model",
    diagram_style={
        "class_": {"background": "#E3F2FD", "round_corner": 10},
        "arrow": {"line_color": "gray", "font_size": 10},
        "note": {"background": "#FFF9C4"},
        "stereotypes": {
            "important": {"background": "pink", "font_style": "bold"},
        },
    },
)

Every element property is documented in ElementStyleDict — hover over it in your IDE to see all available keys (background, line_color, font_color, font_name, font_size, padding, margin, round_corner, shadowing, max_width, and more).

Supported Diagram Types

Behavioral

Type Use When Guide
Sequence Message flows between participants API calls, protocols
State Entity lifecycle tracking Order status, workflows
Activity Process flow with decisions and parallelism Business processes, algorithms
Use Case System boundaries and actor goals Requirements, features
Timing State changes over time Hardware signals, protocol timing

Structural

Type Use When Guide
Class Types, attributes, and relationships Domain models, API types
Object Specific instances and values Test scenarios, snapshots
Component System architecture Services, modules, dependencies
Deployment Software on infrastructure Servers, containers, cloud
Network Network topology IP addressing, segments

Hierarchical

Type Use When Guide
Mind Map Brainstorming and organizing ideas Feature planning, concepts
WBS Breaking down work Project planning, tasks
Gantt Scheduling with dependencies Timelines, sprint planning

Data & UI

Type Use When Guide
JSON Visualizing JSON data API responses, config
YAML Visualizing YAML data Config files, specs
Salt UI wireframes Forms, layouts, menus

Composition

Feature Guide
Sub-diagrams Embed diagrams inside notes and messages

Installation

pip install plantuml-compose

Requires Python 3.13+.

Development

# Install dependencies
uv sync

# Run tests
uv run pytest

# Validate output against PlantUML
plantuml --check-syntax output.puml

License

MIT

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

plantuml_compose-1.0.0.tar.gz (135.1 kB view details)

Uploaded Source

Built Distribution

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

plantuml_compose-1.0.0-py3-none-any.whl (178.0 kB view details)

Uploaded Python 3

File details

Details for the file plantuml_compose-1.0.0.tar.gz.

File metadata

  • Download URL: plantuml_compose-1.0.0.tar.gz
  • Upload date:
  • Size: 135.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"25.11","id":"xantusia","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for plantuml_compose-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fd81c197de8f30304b3b4b0d2d2be80db8dfe109772cd92a2baaf345b97feea8
MD5 c1c9f3534f98bd5769c8cb33821a7fed
BLAKE2b-256 ca43c3677af72a3b77360f112a21be64cc458d1e50f95dc87b642a20c001f72d

See more details on using hashes here.

File details

Details for the file plantuml_compose-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: plantuml_compose-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 178.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"25.11","id":"xantusia","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for plantuml_compose-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc915896b4647a243c94886659bf52ce1cac084d86a2a0e38f02a880afd1cec3
MD5 b6d716a85afa5415e059233970a915ee
BLAKE2b-256 60baeb142121bb1ae1825c9c9a8470fcd1d38fb84e0c2af9b985bbc9e17e1e13

See more details on using hashes here.

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