Skip to content

Structurizr Authoring

The Structurizr workspace, model and elements live in c4.contrib.structurizr. See the authoring guide.

c4.contrib.structurizr.Workspace

A native Structurizr workspace ready to render as DSL.

Attributes:

Name Type Description
properties dict[str, Any]

Custom workspace properties.

_model

Elements, relationships, and deployment topology.

_views

Ordered collection of declared views.

_styles

Workspace-level style declarations.

name property

name: str | None

Return the workspace name used in rendered output.

description property

description: str | None

Return the workspace description.

model property

model: Model

Return the workspace model.

views property

views: Views

Return the workspace view collection.

styles property

styles: Styles

Return the workspace style declarations.

element_styles property

element_styles: tuple[StructurizrStyleModel, ...]

Return workspace-level element style declarations.

relationship_styles property

relationship_styles: tuple[StructurizrStyleModel, ...]

Return workspace-level relationship style declarations.

render_options property writable

render_options: StructurizrRenderOptions | None

Return renderer options reserved for Structurizr output.

set_property

set_property(key: str, value: Any) -> Self

Set a workspace property and return this workspace.

Parameters:

Name Type Description Default
key str

Property name.

required
value Any

Property value.

required

render

render(
    renderer: BaseRenderer[Workspace] | None = None,
) -> str

Render this workspace as Structurizr DSL.

Parameters:

Name Type Description Default
renderer BaseRenderer[Workspace] | None

Optional Structurizr renderer to use.

None

save

save(
    path: str | Path,
    renderer: BaseRenderer[Workspace] | None = None,
) -> Path

Render the workspace and save the DSL to path.

Parameters:

Name Type Description Default
path str | Path

Destination file path.

required
renderer BaseRenderer[Workspace] | None

Optional Structurizr renderer to use.

None

c4.contrib.structurizr.Model

The elements, relationships, and deployment topology of a workspace.

Attributes:

Name Type Description
people list[Person]

People declared in the model.

software_systems list[SoftwareSystem]

Software systems declared in the model.

containers list[Container]

Containers declared in the model.

components list[Component]

Components declared in the model.

deployment_nodes list[DeploymentNode]

Deployment and infrastructure nodes in the model.

deployment_environments list[DeploymentEnvironment]

Named deployment environments in the model.

_relationships list[Relationship]

Relationships declared in the model.

Person

Person(name: str, **kwargs: Any) -> Person

Add a person to the model.

Parameters:

Name Type Description Default
name str

Display name of the person.

required
**kwargs Any

Element metadata accepted by Person.

{}

SoftwareSystem

SoftwareSystem(name: str, **kwargs: Any) -> SoftwareSystem

Add a software system to the model.

Parameters:

Name Type Description Default
name str

Display name of the software system.

required
**kwargs Any

Element metadata accepted by SoftwareSystem.

{}

Container

Container(
    name: str,
    *,
    owner: _SoftwareSystem | None = None,
    **kwargs: Any,
) -> Container

Add a container to a software system.

Parameters:

Name Type Description Default
name str

Display name of the container.

required
owner _SoftwareSystem | None

Owning software system, or the active context owner.

None
**kwargs Any

Element metadata accepted by Container.

{}

Component

Component(
    name: str,
    *,
    owner: _Container | None = None,
    **kwargs: Any,
) -> Component

Add a component to a container.

Parameters:

Name Type Description Default
name str

Display name of the component.

required
owner _Container | None

Owning container, or the active context owner.

None
**kwargs Any

Element metadata accepted by Component.

{}

DeploymentEnvironment

DeploymentEnvironment(name: str) -> DeploymentEnvironment

Return the named deployment environment, creating it if needed.

Parameters:

Name Type Description Default
name str

Deployment environment name.

required

get_deployment_environment

get_deployment_environment(
    name: str,
) -> _DeploymentEnvironment | None

Return the named deployment environment, or None.

Parameters:

Name Type Description Default
name str

Deployment environment name.

required

DeploymentNode

DeploymentNode(
    name: str,
    *,
    parent: _DeploymentNode | None = None,
    environment: str | None = None,
    **kwargs: Any,
) -> DeploymentNode

Add a deployment node to the model or active environment.

Parameters:

Name Type Description Default
name str

Display name of the deployment node.

required
parent _DeploymentNode | None

Optional parent deployment node.

None
environment str | None

Optional deployment environment name.

None
**kwargs Any

Element metadata accepted by DeploymentNode.

{}

InfrastructureNode

InfrastructureNode(
    name: str,
    *,
    parent: _DeploymentNode | None = None,
    **kwargs: Any,
) -> InfrastructureNode

Add an infrastructure node below a deployment node.

Parameters:

Name Type Description Default
name str

Display name of the infrastructure node.

required
parent _DeploymentNode | None

Parent deployment node, or the active context owner.

None
**kwargs Any

Element metadata accepted by InfrastructureNode.

{}

SoftwareSystemInstance

SoftwareSystemInstance(
    target: _SoftwareSystem,
    *,
    parent: _DeploymentNode | None = None,
    **kwargs: Any,
) -> SoftwareSystemInstance

Add an instance of a software system to a deployment node.

Parameters:

Name Type Description Default
target _SoftwareSystem

Software system represented by the instance.

required
parent _DeploymentNode | None

Parent deployment node, or the active context owner.

None
**kwargs Any

Instance metadata.

{}

ContainerInstance

ContainerInstance(
    target: _Container,
    *,
    parent: _DeploymentNode | None = None,
    **kwargs: Any,
) -> ContainerInstance

Add an instance of a container to a deployment node.

Parameters:

Name Type Description Default
target _Container

Container represented by the instance.

required
parent _DeploymentNode | None

Parent deployment node, or the active context owner.

None
**kwargs Any

Instance metadata.

{}

c4.contrib.structurizr.DeploymentEnvironment

A named deployment environment and its root deployment nodes.

Attributes:

Name Type Description
name

Environment name.

nodes list[DeploymentNode]

Root deployment nodes in the environment.

DeploymentNode

DeploymentNode(name: str, **kwargs: Any) -> DeploymentNode

Add a root deployment node to this environment.

Parameters:

Name Type Description Default
name str

Display name of the deployment node.

required
**kwargs Any

Element metadata accepted by DeploymentNode.

{}

c4.contrib.structurizr.StructurizrElement

Base class for elements declared in a Structurizr workspace model.

Attributes:

Name Type Description
alias

Unique Structurizr identifier for the element.

name

Display name of the element.

description

Optional description of the element.

technology

Optional implementation technology.

tags

Tags applied to the element.

properties

Custom element properties.

url

Optional hyperlink associated with the element.

tag

tag(*tags: str) -> Self

Add tags to this element and return it.

Parameters:

Name Type Description Default
*tags str

Tags to add, in declaration order.

()

property

property(key: str, value: Any) -> Self

Set a custom property on this element and return it.

Parameters:

Name Type Description Default
key str

Property name.

required
value Any

Property value.

required

style

style(**properties: Any) -> Self

Apply element style properties and return this element.

Parameters:

Name Type Description Default
**properties Any

Structurizr element style properties.

{}

uses

uses(
    other: StructurizrElement,
    description: str | None,
    *,
    technology: str | None = None,
    tags: list[str] | tuple[str, ...] | None = None,
    properties: Mapping[str, Any] | None = None,
    url: str | None = None,
    style: Mapping[str, Any] | None = None,
) -> Relationship

Declare that this element uses another element.

Parameters:

Name Type Description Default
other StructurizrElement

Destination element.

required
description str | None

Human-readable relationship label.

required
technology str | None

Optional technology used by the relationship.

None
tags list[str] | tuple[str, ...] | None

Tags applied to the relationship.

None
properties Mapping[str, Any] | None

Custom relationship properties.

None
url str | None

Optional hyperlink associated with the relationship.

None
style Mapping[str, Any] | None

Relationship-local style properties.

None

used_by

used_by(
    other: StructurizrElement,
    description: str | None,
    **kwargs: Any,
) -> Relationship

Declare that another element uses this element.

Parameters:

Name Type Description Default
other StructurizrElement

Source element.

required
description str | None

Human-readable relationship label.

required
**kwargs Any

Additional relationship metadata accepted by uses.

{}

c4.contrib.structurizr.Person

Bases: StructurizrElement

A person who interacts with one or more software systems.

c4.contrib.structurizr.SoftwareSystem

Bases: StructurizrElement

A software system in the workspace model.

Container

Container(name: str, **kwargs: Any) -> Container

Add a container owned by this software system.

c4.contrib.structurizr.Container

Bases: StructurizrElement

A deployable application or data store within a software system.

Component

Component(name: str, **kwargs: Any) -> Component

Add a component owned by this container.

c4.contrib.structurizr.Component

Bases: StructurizrElement

A component within a software-system container.

c4.contrib.structurizr.DeploymentNode

Bases: StructurizrElement

An infrastructure location on which software is deployed.

DeploymentNode

DeploymentNode(name: str, **kwargs: Any) -> DeploymentNode

Add a deployment node nested inside this node.

InfrastructureNode

InfrastructureNode(
    name: str, **kwargs: Any
) -> InfrastructureNode

Add an infrastructure node nested inside this node.

SoftwareSystemInstance

SoftwareSystemInstance(
    target: SoftwareSystem, **kwargs: Any
) -> SoftwareSystemInstance

Add an instance of a software system to this node.

ContainerInstance

ContainerInstance(
    target: Container, **kwargs: Any
) -> ContainerInstance

Add an instance of a container to this node.

c4.contrib.structurizr.InfrastructureNode

Bases: DeploymentNode

A deployment node representing supporting infrastructure.

c4.contrib.structurizr.SoftwareSystemInstance

Bases: _DeploymentInstance

A software system deployed on a deployment node.

c4.contrib.structurizr.ContainerInstance

Bases: _DeploymentInstance

A container deployed on a deployment node.

c4.contrib.structurizr.Rel

Rel(
    description: str | None = None,
    *,
    technology: str | None = None,
    tags: list[str] | tuple[str, ...] | None = None,
    properties: Mapping[str, Any] | None = None,
    url: str | None = None,
    style: Mapping[str, Any] | None = None,
) -> _RelationshipExpression

Start a relationship expression with optional metadata.

Only description may be positional; pass technology and the other options by name. The expression is immutable and can be reused.

Parameters:

Name Type Description Default
description str | None

Relationship description to render.

None
technology str | None

Optional technology used by the relationship.

None
tags list[str] | tuple[str, ...] | None

Tags applied to the relationship.

None
properties Mapping[str, Any] | None

Custom relationship properties.

None
url str | None

Optional hyperlink associated with the relationship.

None
style Mapping[str, Any] | None

Relationship-local style properties.

None