Skip to main content

AI-friendly architecture diagrams with grid-based positioning

Project description

diagrams-for-ai

CI PyPI

AI-friendly architecture diagrams with grid-based positioning.

diagrams-for-ai is a Python library that renders beautiful cloud architecture diagrams without Graphviz. Nodes are placed on a simple grid using row and col coordinates, making it trivial for an AI to generate diagrams programmatically.

Why diagrams-for-ai?

  • Grid-based positioning -- Place nodes with row and col. No fighting with Graphviz layout.
  • AI-friendly -- Explicit coordinates are easy for language models to produce and reason about.
  • Real icons -- Leverages the diagrams package for hundreds of icons across AWS, GCP, Azure, Kubernetes, and more.
  • Beautiful connections -- Four line styles: curved (bezier), straight, orthogonal, and step. Use via waypoints for custom routing with any number of corners.
  • SVG & PNG output -- Portable SVG with embedded icons, or raster PNG via Pillow.
  • Familiar syntax -- Use >>, <<, and - operators to connect nodes, just like the original diagrams library.
  • Hi-res rendering -- Use scale=2 (or higher) to uniformly multiply all pixel dimensions for sharp output on retina screens and in PDFs. Set icon_size per diagram for full control over icon proportions.
  • Mermaid import -- Parse annotated Mermaid flowcharts (.mmd files) into diagrams. Grid positions and icons are embedded as Mermaid comments, so the same file renders in GitHub, IDEs, and diagrams-for-ai.

Installation

uv add diagrams-for-ai

Or with pip:

pip install diagrams-for-ai

The diagrams package (which provides the icons) is installed automatically as a dependency.

Quick example

from diagrams_for_ai import Diagram, Node

with Diagram("Hello", rows=2, cols=2, outformat="png", show=False):
    a = Node("Service A", icon="aws/compute/ec2", row=0, col=0)
    b = Node("Service B", icon="aws/database/rds", row=1, col=1)
    a >> b

Full example

from diagrams_for_ai import Cluster, Diagram, Edge, LineStyle, Node

with Diagram("AWS Web Service", rows=5, cols=7, outformat=["svg", "png"], show=False):

    with Cluster("Public Subnet", row=0, col=1, width=5, height=2,
                 bg_color="#FFF3E0", border_color="#FFB74D"):
        users = Node("Users", icon="aws/general/users", row=0, col=3)
        cdn = Node("CloudFront", icon="aws/network/cloudfront", row=1, col=3)

    with Cluster("Private Subnet", row=2, col=0, width=7, height=3,
                 bg_color="#E8F5E9", border_color="#81C784"):
        lb = Node("ALB", icon="aws/network/elastic-load-balancing", row=2, col=3)
        web1 = Node("Web 1", icon="aws/compute/ec2", row=3, col=1)
        web2 = Node("Web 2", icon="aws/compute/ec2", row=3, col=5)
        db = Node("Aurora", icon="aws/database/aurora", row=4, col=3)

    users >> cdn >> lb
    lb >> [web1, web2]
    web1 >> db
    web2 >> Edge(style="dashed", line_style=LineStyle.ORTHO) >> db

Features

Connection styles

Style Usage Description
Curved a >> b Smooth bezier curves (default)
Straight a >> Edge(line_style=LineStyle.STRAIGHT) >> b Direct lines
Orthogonal a >> Edge(line_style=LineStyle.ORTHO) >> b Right-angle routing
Step a >> Edge(line_style=LineStyle.STEP) >> b Horizontal-then-vertical

Edge customization

a >> Edge(label="HTTPS", color="#2ECC71", style="dashed") >> b

Waypoint routing

Route connections through intermediate grid cells with via:

a >> Edge(via=[(0, 3), (2, 3)]) >> b

Clusters

with Cluster("VPC", row=0, col=0, width=4, height=3,
             bg_color="#E8F4FD", border_color="#B0C4DE"):
    # nodes inside the cluster
    ...

Mermaid import

Write your architecture in Mermaid with position annotations in comments:

%% @config name="Hello" rows=2 cols=2
graph TD
    %% @node A pos=0,0 icon=aws/compute/ec2
    %% @node B pos=1,1 icon=aws/database/rds
    A[Service A] --> B[Service B]

Then render it with diagrams-for-ai:

from diagrams_for_ai import Diagram

d = Diagram.from_mermaid_file("architecture.mmd", show=False)
d.render()

See Mermaid Import docs for the full annotation syntax.

Hi-res rendering

Use scale for sharper output in PDFs, print, or retina displays:

with Diagram("Hi-Res", rows=2, cols=2, scale=2, outformat="png", show=False):
    a = Node("Service A", icon="aws/compute/ec2", row=0, col=0)
    b = Node("Service B", icon="aws/database/rds", row=1, col=1)
    a >> b

Or in Mermaid:

%% @config name="Hi-Res" rows=2 cols=2 scale=2

Set icon_size to control the base icon size per diagram (default 64px):

with Diagram("Large Icons", rows=2, cols=2, icon_size=80, outformat="png", show=False):
    ...

Icon providers

AWS, GCP, Azure, Kubernetes, on-premises, and 13 more providers -- all from the diagrams package.

Node("Server", icon="aws/compute/ec2", row=0, col=0)
Node("Pod", icon="k8s/compute/pod", row=0, col=1)
Node("Postgres", icon="onprem/database/postgresql", row=0, col=2)

Development

# Install dependencies
uv sync

# Run tests
uv run pytest

# Serve docs locally
uv run mkdocs serve

License

MIT -- see LICENSE for details.

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

diagrams_for_ai-0.2.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

diagrams_for_ai-0.2.0-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file diagrams_for_ai-0.2.0.tar.gz.

File metadata

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

File hashes

Hashes for diagrams_for_ai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c4883af80a236c0a36dc2acf269d424a66ec046380761349c66863cfe3394355
MD5 ce9aa4b031baf6110703ace6c6ae20d5
BLAKE2b-256 ec73322cb81bf6287313d911c3d5d66a16cca058afb9629745b47b2e7359c182

See more details on using hashes here.

Provenance

The following attestation bundles were made for diagrams_for_ai-0.2.0.tar.gz:

Publisher: publish.yml on tomascorrea/diagrams-for-ai

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

File details

Details for the file diagrams_for_ai-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for diagrams_for_ai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5cb10d28f9da76c8556afd5994a9118c82cfcad0df9999316ab11162177a0003
MD5 1b58786016f7634f7e2dee05c8c9831d
BLAKE2b-256 38611c805ca6b9b1bcd522cfe0f0f8eb017e6a304ca4a0cb3cb88b7188619ba2

See more details on using hashes here.

Provenance

The following attestation bundles were made for diagrams_for_ai-0.2.0-py3-none-any.whl:

Publisher: publish.yml on tomascorrea/diagrams-for-ai

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