Skip to content

LikeC4 Authoring

The LikeC4 project, model and deployment live in c4.contrib.likec4. See the authoring guide.

c4.contrib.likec4.Project

A LikeC4 project ready to render as .c4 text.

Attributes:

Name Type Description
name

Optional project title.

view_key

View exported as an image when the renderer is not given one; the only view is used when neither is set.

specification property

specification: Specification

Return the project's vocabulary.

model property

model: Model

Return the project's model.

deployment property

deployment: Deployment

Return the project's deployment.

views property

views: Views

Return the project's views.

render

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

Render this project as LikeC4 DSL.

Parameters:

Name Type Description Default
renderer BaseRenderer[Project] | None

Optional LikeC4 renderer to use.

None

save

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

Render the project and save the DSL to path.

Parameters:

Name Type Description Default
path str | Path

Destination file path.

required
renderer BaseRenderer[Project] | None

Optional LikeC4 renderer to use.

None

c4.contrib.likec4.Model

The element hierarchy and relationships of a project.

Attributes:

Name Type Description
elements list[Element]

Every element in creation order.

relationships list[Relationship]

Every relationship in creation order.

roots property

roots: list[Element]

Return the top-level elements in declaration order.

element

element(
    kind: str,
    title: str | None = None,
    *,
    parent: Element | None = None,
    **kwargs: Any,
) -> Element

Create an element of a declared kind.

Without parent the element nests into the innermost element whose with block is active, or becomes a root element.

Parameters:

Name Type Description Default
kind str

Declared element kind.

required
title str | None

Display title.

None
parent Element | None

Explicit parent element.

None
**kwargs Any

Any other Element argument.

{}

person

person(title: str | None = None, **kwargs: Any) -> Element

Create an element of the person kind.

Equivalent to element("person", ...); the kind must be declared.

Parameters:

Name Type Description Default
title str | None

Display title.

None
**kwargs Any

Any other element argument.

{}

Raises:

Type Description
ValueError

If the person kind is not declared.

system

system(title: str | None = None, **kwargs: Any) -> Element

Create an element of the system kind.

Equivalent to element("system", ...); the kind must be declared.

Parameters:

Name Type Description Default
title str | None

Display title.

None
**kwargs Any

Any other element argument.

{}

Raises:

Type Description
ValueError

If the system kind is not declared.

container

container(
    title: str | None = None, **kwargs: Any
) -> Element

Create an element of the container kind.

Equivalent to element("container", ...); the kind must be declared.

Parameters:

Name Type Description Default
title str | None

Display title.

None
**kwargs Any

Any other element argument.

{}

Raises:

Type Description
ValueError

If the container kind is not declared.

component

component(
    title: str | None = None, **kwargs: Any
) -> Element

Create an element of the component kind.

Equivalent to element("component", ...); the kind must be declared.

Parameters:

Name Type Description Default
title str | None

Display title.

None
**kwargs Any

Any other element argument.

{}

Raises:

Type Description
ValueError

If the component kind is not declared.

database

database(
    title: str | None = None, **kwargs: Any
) -> Element

Create an element of the database kind.

Equivalent to element("database", ...); the kind must be declared.

Parameters:

Name Type Description Default
title str | None

Display title.

None
**kwargs Any

Any other element argument.

{}

Raises:

Type Description
ValueError

If the database kind is not declared.

external

external(
    title: str | None = None, **kwargs: Any
) -> Element

Create an element of the external kind.

Equivalent to element("external", ...); the kind must be declared.

Parameters:

Name Type Description Default
title str | None

Display title.

None
**kwargs Any

Any other element argument.

{}

Raises:

Type Description
ValueError

If the external kind is not declared.

relate

relate(
    source: Element,
    target: Element,
    title: str | None = None,
    **kwargs: Any,
) -> Relationship

Create a relationship between two elements of this model.

Parameters:

Name Type Description Default
source Element

Initiating element.

required
target Element

Receiving element.

required
title str | None

Relationship label.

None
**kwargs Any

Any other Relationship.create argument.

{}

c4.contrib.likec4.Element

Bases: _RelationOperators

A model element of a declared kind; elements nest without limit.

Attributes:

Name Type Description
kind

Declared element kind.

title

Display title.

alias

Explicit identifier; derived from the title when omitted.

parent

Parent element, or None for a root element.

children list[Element]

Child elements in declaration order.

summary

Short summary, at most 150 characters.

description

Markdown description.

technology

Implementation technology.

tags

Tags applied to the element, without #.

style dict[str, StyleValue]

Element-local style properties.

icon

Icon reference such as tech:go.

metadata

Custom metadata.

links

Hyperlinks.

name property

name: str

Return the title, or the alias when there is no title.

element

element(
    kind: str, title: str | None = None, **kwargs: Any
) -> Element

Create a child element.

Parameters:

Name Type Description Default
kind str

Declared element kind.

required
title str | None

Display title.

None
**kwargs Any

Any other Model.element argument.

{}

person

person(title: str | None = None, **kwargs: Any) -> Element

Create a child element of the person kind.

Equivalent to element("person", ...); the kind must be declared.

Parameters:

Name Type Description Default
title str | None

Display title.

None
**kwargs Any

Any other Model.element argument.

{}

Raises:

Type Description
ValueError

If the person kind is not declared.

system

system(title: str | None = None, **kwargs: Any) -> Element

Create a child element of the system kind.

Equivalent to element("system", ...); the kind must be declared.

Parameters:

Name Type Description Default
title str | None

Display title.

None
**kwargs Any

Any other Model.element argument.

{}

Raises:

Type Description
ValueError

If the system kind is not declared.

container

container(
    title: str | None = None, **kwargs: Any
) -> Element

Create a child element of the container kind.

Equivalent to element("container", ...); the kind must be declared.

Parameters:

Name Type Description Default
title str | None

Display title.

None
**kwargs Any

Any other Model.element argument.

{}

Raises:

Type Description
ValueError

If the container kind is not declared.

component

component(
    title: str | None = None, **kwargs: Any
) -> Element

Create a child element of the component kind.

Equivalent to element("component", ...); the kind must be declared.

Parameters:

Name Type Description Default
title str | None

Display title.

None
**kwargs Any

Any other Model.element argument.

{}

Raises:

Type Description
ValueError

If the component kind is not declared.

database

database(
    title: str | None = None, **kwargs: Any
) -> Element

Create a child element of the database kind.

Equivalent to element("database", ...); the kind must be declared.

Parameters:

Name Type Description Default
title str | None

Display title.

None
**kwargs Any

Any other Model.element argument.

{}

Raises:

Type Description
ValueError

If the database kind is not declared.

external

external(
    title: str | None = None, **kwargs: Any
) -> Element

Create a child element of the external kind.

Equivalent to element("external", ...); the kind must be declared.

Parameters:

Name Type Description Default
title str | None

Display title.

None
**kwargs Any

Any other Model.element argument.

{}

Raises:

Type Description
ValueError

If the external kind is not declared.

set_style

set_style(**properties: Any) -> Self

Merge element-local style properties.

Parameters:

Name Type Description Default
**properties Any

Element style properties.

{}

ancestors

ancestors() -> list[Element]

Return the parents from the nearest to the root.

descendants

descendants() -> list[Element]

Return all nested elements in depth-first declaration order.

c4.contrib.likec4.Relationship dataclass

A relationship between two model elements.

a >> b creates a relationship with no title; a >> b | "title" sets it while it is None and raises ValueError once a title exists.

Attributes:

Name Type Description
source Element

Element that initiates the relationship.

target Element

Element that receives the relationship.

title str | None

Relationship label.

description str | None

Longer Markdown description.

technology str | None

Technology used by the relationship.

kind str | None

Declared relationship kind, if any.

bidirectional bool

Whether the relationship is declared with <->.

tags tuple[str, ...]

Tags applied to the relationship, without #.

metadata dict[str, MetadataValue]

Custom metadata.

links tuple[Link, ...]

Hyperlinks.

style dict[str, StyleValue]

Relationship-local style properties.

navigate_to str | None

Key of the dynamic view to open on click.

create classmethod

create(
    source: Element,
    target: Element,
    title: str | None = None,
    *,
    description: str | None = None,
    technology: str | None = None,
    kind: str | None = None,
    bidirectional: bool = False,
    tags: list[str] | tuple[str, ...] | None = None,
    metadata: Mapping[str, Any] | None = None,
    links: list[Any] | tuple[Any, ...] | None = None,
    navigate_to: str | None = None,
    **style: Any,
) -> Relationship

Build a relationship, validating the supplied properties.

c4.contrib.likec4.Deployment

The deployment nodes, instances and relationships of a project.

Attributes:

Name Type Description
nodes list[DeploymentNode]

Every node in creation order.

instances list[DeploymentInstance]

Every instance in creation order.

relationships list[DeploymentRelationship]

Every deployment relationship in creation order.

roots property

roots: list[DeploymentNode]

Return the top-level nodes in declaration order.

node

node(
    kind: str,
    title: str | None = None,
    *,
    parent: DeploymentNode | None = None,
    **kwargs: Any,
) -> DeploymentNode

Create a deployment node of a declared kind.

Without parent the node nests into the innermost node whose with block is active, or becomes a root node.

Parameters:

Name Type Description Default
kind str

Declared deployment node kind.

required
title str | None

Display title.

None
parent DeploymentNode | None

Explicit parent node.

None
**kwargs Any

Any other DeploymentNode argument.

{}

instance

instance(
    element: Element,
    name: str | None = None,
    *,
    parent: DeploymentNode | None = None,
    **kwargs: Any,
) -> DeploymentInstance

Add an instance of a model element to a node.

Parameters:

Name Type Description Default
element Element

Model element to instantiate.

required
name str | None

Optional instance identifier.

None
parent DeploymentNode | None

Node that holds the instance; defaults to the innermost node whose with block is active.

None
**kwargs Any

Any other DeploymentInstance argument.

{}

relate

relate(
    source: DeploymentNode | DeploymentInstance,
    target: DeploymentNode | DeploymentInstance,
    title: str | None = None,
    **kwargs: Any,
) -> DeploymentRelationship

Create a relationship between nodes or instances of this deployment.

Parameters:

Name Type Description Default
source DeploymentNode | DeploymentInstance

Initiating node or instance.

required
target DeploymentNode | DeploymentInstance

Receiving node or instance.

required
title str | None

Relationship label.

None
**kwargs Any

Any other DeploymentRelationship.create argument.

{}

c4.contrib.likec4.DeploymentNode

Bases: _RelationOperators

A deployment node of a declared deployment kind; nodes nest without limit.

Nodes have their own FQN namespace, independent of the logical model.

Attributes:

Name Type Description
kind

Declared deployment node kind.

title

Display title.

alias

Explicit identifier; derived from the title when omitted.

parent

Parent node, or None for a root node.

children list[DeploymentNode]

Child nodes in declaration order.

instances list[DeploymentInstance]

Instances held directly by this node.

description

Markdown description.

technology

Implementation technology.

tags

Tags applied to the node, without #.

style dict[str, StyleValue]

Node-local style properties.

metadata

Custom metadata.

links

Hyperlinks.

name property

name: str

Return the title, or the alias when there is no title.

node

node(
    kind: str, title: str | None = None, **kwargs: Any
) -> DeploymentNode

Create a child node.

Parameters:

Name Type Description Default
kind str

Declared deployment node kind.

required
title str | None

Display title.

None
**kwargs Any

Any other Deployment.node argument.

{}

instance

instance(
    element: Element, name: str | None = None, **kwargs: Any
) -> DeploymentInstance

Add an instance of a model element to this node.

Parameters:

Name Type Description Default
element Element

Model element to instantiate.

required
name str | None

Optional instance identifier.

None
**kwargs Any

Any other Deployment.instance argument.

{}

ancestors

ancestors() -> list[DeploymentNode]

Return the parents from the nearest to the root.

descendants

descendants() -> list[DeploymentNode]

Return all nested nodes in depth-first declaration order.

c4.contrib.likec4.DeploymentInstance

Bases: _RelationOperators

An instance of a model element deployed on a node.

Attributes:

Name Type Description
element

Instantiated model element.

alias

Instance identifier, or None for an anonymous instance.

parent

Node holding the instance.

title

Optional title override.

description

Markdown description.

technology

Implementation technology.

tags

Tags added to the element's own tags, without #.

style dict[str, StyleValue]

Instance-local style properties.

metadata

Custom metadata.

links

Hyperlinks.

name property

name: str

Return the instance name, or the instantiated element's name.

c4.contrib.likec4.DeploymentRelationship dataclass

A relationship between deployment nodes or instances.

Attributes:

Name Type Description
source DeploymentNode | DeploymentInstance

Initiating node or instance.

target DeploymentNode | DeploymentInstance

Receiving node or instance.

title str | None

Relationship label.

description str | None

Longer Markdown description.

technology str | None

Technology used by the relationship.

kind str | None

Declared relationship kind, if any.

bidirectional bool

Whether the relationship is declared with <->.

tags tuple[str, ...]

Tags applied to the relationship, without #.

metadata dict[str, MetadataValue]

Custom metadata.

links tuple[Link, ...]

Hyperlinks.

style dict[str, StyleValue]

Relationship-local style properties.

create classmethod

create(
    source: DeploymentNode | DeploymentInstance,
    target: DeploymentNode | DeploymentInstance,
    title: str | None = None,
    *,
    description: str | None = None,
    technology: str | None = None,
    kind: str | None = None,
    bidirectional: bool = False,
    tags: list[str] | tuple[str, ...] | None = None,
    metadata: Mapping[str, Any] | None = None,
    links: list[Any] | tuple[Any, ...] | None = None,
    **style: Any,
) -> DeploymentRelationship

Build a relationship, validating the supplied properties.

A hyperlink attached to an element, relationship or view.

Attributes:

Name Type Description
url str

Link target; may be relative to the document.

title str | None

Optional link title.