infrasketchSVG architecture diagrams

Guide

A diagram is a with block. Resources created inside it belong to that diagram, and >> draws the arrow.

Install

pip install infrasketch

Azure

Azure resources live in infrasketch.azure. ResourceGroup, VNet, Subnet, and PrivateNetwork are boundaries. The icon says which service it is. The label is your name for that piece of the system, and the caption under it is the service name.

from infrasketch import Diagram, Https, Private
from infrasketch.azure import (
    ResourceGroup, VNet, Subnet, PrivateNetwork,
    Users, FrontDoor, StaticWebApp, AppService, Redis, SQLDatabase, KeyVault,
)

with Diagram("Web, API, and Redis", "platform.svg", subtitle="Production · West Europe"):
    customers = Users("Customers")
    with ResourceGroup("rg-edge"):
        door = FrontDoor("Entry")
    with ResourceGroup("rg-app"):
        with VNet("vnet-app"):
            with Subnet("snet-web"):
                web = StaticWebApp("Storefront")
            with Subnet("snet-api"):
                api = AppService("Orders API")
            with PrivateNetwork("data"):
                cache = Redis("Sessions")
                database = SQLDatabase("Orders")
                vault = KeyVault("Secrets")

    customers >> Https() >> door >> web >> api
    api >> [cache, database]
    api >> Private("secrets") >> vault

AWS

AWS resources live in infrasketch.aws. VPC, PublicSubnet, and PrivateSubnet are boundaries. The label and caption work the same way as on an Azure resource.

from infrasketch import Diagram
from infrasketch.aws import (
    APIGateway, CloudFront, DynamoDB, Lambda, PrivateSubnet, PublicSubnet, S3, Users, VPC,
)

with Diagram("Orders", "orders.svg", subtitle="Production · eu-west-1"):
    customers = Users("Customers")
    edge = CloudFront("Entry")
    with VPC("vpc-orders"):
        with PublicSubnet("public"):
            api = APIGateway("Orders")
        with PrivateSubnet("data"):
            checkout = Lambda("Checkout")
            orders = DynamoDB("Orders")
            images = S3("Images")
    customers >> edge >> api >> checkout
    checkout >> [orders, images]

Draw a diagram

Groups are context managers too, so the indentation is the architecture. direction="TB" flows top to bottom. spacing is "compact", "regular", or "relaxed". Pass autosave=False when you want the SVG string yourself:

with Diagram("Orders", autosave=False) as diagram:
    ...
svg = diagram.svg()
diagram.save("orders.svg")

Connectors

CodeResult
a >> bArrow from a to b
a >> [b, c]Arrow from a to each target
[a, b] >> cArrow from each source to c
a << bArrow pointing back at a
a - bLine with no arrowhead
a >> Edge("SQL", style="dashed") >> bLabelled connector
a >> Https() >> bBlue HTTPS
a >> Async("enqueue") >> bDashed queue or event
a >> Private() >> bDashed Private Link, with no label unless you pass one

style is "solid", "dashed", or "dotted". color is a hex color such as "#0078D4".

Boundaries

Import Azure boundaries from infrasketch.azure and AWS boundaries from infrasketch.aws. Group comes from infrasketch and draws a box that belongs to neither cloud.

Azure

GroupUse it for
Subscription("sub")A subscription
ResourceGroup("rg-app")A resource group
Region("West Europe")A region
VNet("vnet-app")A virtual network
Subnet("snet-api")A subnet
PrivateNetwork("data")Private endpoints or Private Link

AWS

GroupUse it for
AWSCloud("aws")The AWS cloud
Account("prod")An account
Region("eu-west-1")A region
VPC("vpc-app")A virtual private cloud
PublicSubnet("public")A public subnet
PrivateSubnet("private")A private subnet

Inside a boundary, connected resources flow in the diagram direction. Resources at the same step stack. arrange="row" forces a single row, arrange="column" a single column, and arrange="grid" with columns=3 a grid.

Names

Common Azure names come from infrasketch.azure: FunctionApp, ContainerApp, ACR, AKS, Redis, SQLDatabase, KeyVault, FrontDoor.

Common AWS names come from infrasketch.aws: Lambda, EC2, S3, DynamoDB, RDS, APIGateway, CloudFront, EKS.

Every icon in both sets is included. The icon browser shows the import line. From a terminal:

python -m infrasketch search private endpoint
python -m infrasketch categories
from infrasketch import search

for hit in search("cosmos"):
    print(hit.import_line)

FunctionApp("Orders") labels the box "Orders" and captions it "Function App". FunctionApp() uses the service name as the only label. caption=False hides the caption.

A resource with no icon draws a neutral placeholder. Pass icon="path/to.svg" to use your own artwork. Azure and AWS icons stay at their original colors and proportions.