Skip to content

Container Diagram

c4.diagrams.container.ContainerDiagram

Bases: Diagram

Represents a C4 Container diagram.

c4.diagrams.container.Container

Bases: Element

Represents an application or service container in a C4 Container diagram.

A container can be a web application, API, worker, or any executable unit of deployment. It may optionally include technology and shape hints.

__init__

__init__(
    label: Required[str] = REQUIRED,
    description: str | None = None,
    technology: str | None = None,
    sprite: str | None = None,
    tags: list[str] | None = None,
    link: str | None = None,
    base_shape: str | None = None,
    alias: Maybe[str] = MISSING,
) -> None

Parameters:

Name Type Description Default
label Required[str]

Human-readable name of the container.

REQUIRED
description str | None

Optional description of the container's purpose.

None
technology str | None

The technology stack used by the container.

None
sprite str | None

Optional sprite identifier for visual representation.

None
tags list[str] | None

Optional tags for styling or grouping.

None
link str | None

Optional URL for external documentation or navigation.

None
base_shape str | None

Optional base shape override for rendering.

None
alias Maybe[str]

Unique identifier for the container.

MISSING

set_property_header

set_property_header(*args: str) -> Self

Sets the column headers for the element's property table.

This must be called either before adding any property rows, or the header length must match the number of values.

Parameters:

Name Type Description Default
*args str

Column names to use as the property header.

()

Returns:

Type Description
Self

The updated diagram element.

Raises:

Type Description
ValueError

If header length does not match the number of values.

without_property_header

without_property_header() -> Self

Disables the rendering of the header row in the property table.

Returns:

Type Description
Self

The updated diagram element.

add_property

add_property(*args: str) -> Self

Adds a row to the property table.

The number of arguments must match the number of header columns.

Parameters:

Name Type Description Default
*args str

Values for each column in the property row.

()

Returns:

Type Description
Self

The updated diagram element.

Raises:

Type Description
ValueError

If the number of values does not match the header length.

c4.diagrams.container.ContainerDb

Bases: ElementWithTechnology

Represents a container specifically modeled as a database.

c4.diagrams.container.ContainerQueue

Bases: ElementWithTechnology

Represents a container modeled as a message queue or event broker.

c4.diagrams.container.ContainerExt

Bases: Container

Represents an external container (outside the system boundary).

c4.diagrams.container.ContainerDbExt

Bases: ContainerDb

Represents an external database container.

c4.diagrams.container.ContainerQueueExt

Bases: ContainerQueue

Represents an external message queue or broker.

c4.diagrams.container.ContainerBoundary

Bases: Boundary

Represents a boundary grouping containers within a system.

__init__

__init__(
    label: Required[str] = REQUIRED,
    description: str | None = None,
    tags: list[str] | None = None,
    link: str | None = None,
    alias: Maybe[str] = MISSING,
) -> None

Parameters:

Name Type Description Default
label Required[str]

Displayed label of the boundary. Defaults to empty.

REQUIRED
description str | None

Optional human-readable description of the boundary.

None
tags list[str] | None

Optional tags for styling or grouping.

None
link str | None

URL associated with the boundary for navigation or documentation.

None
alias Maybe[str]

Unique identifier for the boundary.

MISSING

set_property_header

set_property_header(*args: str) -> Self

Sets the column headers for the element's property table.

This must be called either before adding any property rows, or the header length must match the number of values.

Parameters:

Name Type Description Default
*args str

Column names to use as the property header.

()

Returns:

Type Description
Self

The updated diagram element.

Raises:

Type Description
ValueError

If header length does not match the number of values.

without_property_header

without_property_header() -> Self

Disables the rendering of the header row in the property table.

Returns:

Type Description
Self

The updated diagram element.

add_property

add_property(*args: str) -> Self

Adds a row to the property table.

The number of arguments must match the number of header columns.

Parameters:

Name Type Description Default
*args str

Values for each column in the property row.

()

Returns:

Type Description
Self

The updated diagram element.

Raises:

Type Description
ValueError

If the number of values does not match the header length.