Structurizr Rendering Backends¶
The renderer and the Kroki and local export backends. See the renderers guide.
c4.contrib.structurizr.renderer.StructurizrRenderer ¶
Bases: BaseRenderer['Workspace']
A renderer for converting a Structurizr workspace into DSL.
validate ¶
validate(diagram: Workspace) -> None
Validate Structurizr-specific rendering constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagram
|
Workspace
|
Workspace to validate. |
required |
render ¶
render(diagram: Workspace) -> str
Render a Structurizr workspace into Structurizr DSL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagram
|
Workspace
|
Workspace to render. |
required |
render_bytes ¶
render_bytes(
diagram: Workspace, *, format: DiagramFormat
) -> bytes
Render a Diagram and export it through the optional backend.
render_file ¶
render_file(
diagram: Workspace,
output_path: Path,
*,
format: DiagramFormat,
overwrite: bool = True,
) -> Path
Render a Diagram and write exported output through the backend.
c4.contrib.structurizr.renderer.BaseStructurizrBackend ¶
Bases: ABC
Generate Structurizr diagrams from plain text.
to_bytes
abstractmethod
¶
to_bytes(
workspace: str,
*,
format: DiagramFormat | str,
render_options: StructurizrRenderOptions | None = None,
) -> bytes
Export Structurizr DSL source and return generated bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace
|
str
|
Structurizr DSL source to export. |
required |
format
|
DiagramFormat | str
|
Target diagram format. |
required |
render_options
|
StructurizrRenderOptions | None
|
Optional Structurizr renderer configuration. |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
Structurizr DSL source as raw bytes. |
Raises:
| Type | Description |
|---|---|
StructurizrRenderingError
|
If rendering fails. |
to_file ¶
to_file(
workspace: str,
output_path: str | Path,
*,
format: DiagramFormat | None,
overwrite: bool = True,
render_options: StructurizrRenderOptions | None = None,
) -> Path
Export Structurizr DSL source and write generated bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace
|
str
|
Structurizr DSL source to export. |
required |
output_path
|
str | Path
|
Destination file path. |
required |
format
|
DiagramFormat | None
|
Target format; inferred from |
required |
overwrite
|
bool
|
Whether to replace an existing destination file. |
True
|
render_options
|
StructurizrRenderOptions | None
|
Optional Structurizr renderer configuration. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the written output file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
FileExistsError
|
If the output file exists
and |
StructurizrRenderingError
|
If rendering fails. |
c4.contrib.structurizr.renderer.KrokiStructurizrBackend ¶
Bases: BaseStructurizrBackend
Generate Structurizr diagrams through a Kroki server.
to_bytes ¶
to_bytes(
workspace: str,
*,
format: DiagramFormat | str = PNG,
render_options: StructurizrRenderOptions | None = None,
) -> bytes
Export a Structurizr workspace through Kroki.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace
|
str
|
Structurizr DSL source to export. |
required |
format
|
DiagramFormat | str
|
Target diagram format. |
PNG
|
render_options
|
StructurizrRenderOptions | None
|
Reserved Structurizr renderer configuration. |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
Rendered image content as raw bytes. |
Raises:
| Type | Description |
|---|---|
StructurizrRenderingError
|
If rendering fails. |
c4.contrib.structurizr.renderer.LocalStructurizrBackend ¶
Bases: BaseStructurizrBackend
Export Structurizr views using the local structurizr CLI.
structurizr export renders every view of a workspace in one run, one
file per view (<view-key>.png plus a <view-key>-key.png legend), so
the backend picks the requested view from the output directory. PNG and
SVG export needs Playwright Chromium (see the Structurizr CLI docs).
Env vars
- STRUCTURIZR_BIN: executable name/path (default: 'structurizr')
to_bytes ¶
to_bytes(
workspace: str,
*,
format: DiagramFormat | str = PNG,
render_options: StructurizrRenderOptions | None = None,
) -> bytes
Export one view of Structurizr DSL source to PNG or SVG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workspace
|
str
|
Structurizr DSL source to export. |
required |
format
|
DiagramFormat | str
|
|
PNG
|
render_options
|
StructurizrRenderOptions | None
|
Reserved Structurizr renderer configuration. |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
Rendered image content as raw bytes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the format is not supported. |
StructurizrBackendConfigurationError
|
If the workspace has several views and no view key was given. |
StructurizrRenderingError
|
If the CLI fails or does not produce the requested view. |
c4.contrib.structurizr.renderer.StructurizrError ¶
Bases: C4Exception
Base exception class for Structurizr's contrib integration.
c4.contrib.structurizr.renderer.StructurizrRenderingError ¶
Bases: StructurizrError
Raised when rendering a Structurizr workspace fails.
c4.contrib.structurizr.renderer.StructurizrBackendConfigurationError ¶
Bases: StructurizrError
Raised when a Structurizr export backend is misconfigured.