LikeC4 Rendering Backends¶
The renderer and the local export backend. See the renderers guide.
c4.contrib.likec4.renderer.LikeC4Renderer ¶
Bases: BaseRenderer['Project']
A renderer for converting a LikeC4 project into .c4 DSL.
validate ¶
validate(diagram: Project) -> None
Validate LikeC4-specific rendering constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagram
|
Project
|
Project to validate. |
required |
render ¶
render(diagram: Project) -> str
Render a LikeC4 project into LikeC4 DSL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagram
|
Project
|
Project to render. |
required |
render_bytes ¶
render_bytes(
diagram: Project, *, format: DiagramFormat
) -> bytes
Render a project and export it through the backend.
render_file ¶
render_file(
diagram: Project,
output_path: Path,
*,
format: DiagramFormat,
overwrite: bool = True,
) -> Path
Render a project and write the exported image through the backend.
c4.contrib.likec4.renderer.BaseLikeC4Backend ¶
Bases: ABC
Export LikeC4 DSL text to an image.
to_bytes
abstractmethod
¶
to_bytes(
source: str,
*,
format: DiagramFormat | str,
view_key: str | None = None,
) -> bytes
Export LikeC4 DSL source and return the generated image bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
LikeC4 DSL source to export. |
required |
format
|
DiagramFormat | str
|
Target diagram format. |
required |
view_key
|
str | None
|
Key of the view to export. |
None
|
Raises:
| Type | Description |
|---|---|
LikeC4RenderingError
|
If rendering fails. |
to_file ¶
to_file(
source: str,
output_path: str | Path,
*,
format: DiagramFormat | None,
overwrite: bool = True,
view_key: str | None = None,
) -> Path
Export LikeC4 DSL source and write the generated image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
LikeC4 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
|
view_key
|
str | None
|
Key of the view to export. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
FileExistsError
|
If the output exists and |
LikeC4RenderingError
|
If rendering fails. |
c4.contrib.likec4.renderer.LocalLikeC4Backend ¶
Bases: BaseLikeC4Backend
Export LikeC4 views using the local likec4 CLI.
Image export needs Node.js and Playwright Chromium.
Env vars
- LIKEC4_BIN: executable name/path (default: 'likec4')
to_bytes ¶
to_bytes(
source: str,
*,
format: DiagramFormat | str,
view_key: str | None = None,
) -> bytes
Export one view of LikeC4 DSL source to PNG or JPG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
LikeC4 DSL source to export. |
required |
format
|
DiagramFormat | str
|
|
required |
view_key
|
str | None
|
Key of the view to export. |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
Rendered image content as raw bytes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the format is not supported. |
LikeC4BackendConfigurationError
|
If |
LikeC4LocalRenderingError
|
If the CLI fails or produces no file. |
c4.contrib.likec4.renderer.LikeC4Error ¶
Bases: C4Exception
Base exception class for LikeC4's contrib integration.
c4.contrib.likec4.renderer.LikeC4RenderingError ¶
Bases: LikeC4Error
Raised when rendering a LikeC4 project fails.
c4.contrib.likec4.renderer.LikeC4ValidationError ¶
Bases: LikeC4RenderingError
Raised when a project cannot be rendered to valid LikeC4 DSL.
c4.contrib.likec4.renderer.LikeC4BackendConfigurationError ¶
Bases: LikeC4Error
Raised when a LikeC4 export backend is misconfigured.
c4.contrib.likec4.renderer.LikeC4LocalRenderingError ¶
Bases: LikeC4RenderingError
Raised when the local likec4 CLI fails to export a view.