Skip to content

LikeC4 Views

Views are created on project.views. See the views guide.

c4.contrib.likec4.Views

The views of a project in declaration order.

Attributes:

Name Type Description
all list[ElementView | DeploymentView | DynamicView]

Every view in creation order, whatever its type.

element_view

element_view(
    key: str, title: str | None = None, **kwargs: Any
) -> ElementView

Create an element view.

Parameters:

Name Type Description Default
key str

View key.

required
title str | None

Optional title.

None
**kwargs Any

of, description, tags and links.

{}

deployment_view

deployment_view(
    key: str, title: str | None = None, **kwargs: Any
) -> DeploymentView

Create a deployment view.

Parameters:

Name Type Description Default
key str

View key.

required
title str | None

Optional title.

None
**kwargs Any

description, tags and links.

{}

dynamic_view

dynamic_view(
    key: str, title: str | None = None, **kwargs: Any
) -> DynamicView

Create a dynamic view.

Parameters:

Name Type Description Default
key str

View key.

required
title str | None

Optional title.

None
**kwargs Any

variant, description, tags and links.

{}

c4.contrib.likec4.ElementView

Bases: _PredicateView

A view over model elements.

Attributes:

Name Type Description
key

Unique view key.

title

Optional title.

description

Optional Markdown description.

scope

Element the view is of, or None.

tags

View tags, without #.

links tuple[Link, ...]

Hyperlinks.

rules list[Any]

Include, exclude, style and autoLayout rules in the order they were added.

auto_layout

auto_layout(
    direction: str = "TopBottom",
    rank_sep: int | None = None,
    node_sep: int | None = None,
) -> Self

Add an autoLayout rule.

Parameters:

Name Type Description Default
direction str

TopBottom, LeftRight, BottomTop or RightLeft.

'TopBottom'
rank_sep int | None

Optional spacing between ranks.

None
node_sep int | None

Optional spacing between nodes; needs rank_sep.

None

layout property

layout: AutoLayoutRule | None

Return the last autoLayout rule, if any.

include

include(
    *items: Any, navigate_to: str | None = None
) -> Self

Add an include rule.

Parameters:

Name Type Description Default
*items Any

Elements, Wildcard, Children, Descendants, Between, Incoming, Outgoing, InOut, Where or RawPredicate objects.

()
navigate_to str | None

Key of the view to open on click.

None

exclude

exclude(*items: Any) -> Self

Add an exclude rule.

Parameters:

Name Type Description Default
*items Any

Same kinds of item as include.

()

style

style(*targets: Any, **properties: Any) -> Self

Add a style rule.

Parameters:

Name Type Description Default
*targets Any

Items to style.

()
**properties Any

Element style properties.

{}

c4.contrib.likec4.DeploymentView

Bases: _PredicateView

A view over deployment nodes and instances.

include takes no navigate_to: with overrides are not emitted in deployment views.

auto_layout

auto_layout(
    direction: str = "TopBottom",
    rank_sep: int | None = None,
    node_sep: int | None = None,
) -> Self

Add an autoLayout rule.

Parameters:

Name Type Description Default
direction str

TopBottom, LeftRight, BottomTop or RightLeft.

'TopBottom'
rank_sep int | None

Optional spacing between ranks.

None
node_sep int | None

Optional spacing between nodes; needs rank_sep.

None

layout property

layout: AutoLayoutRule | None

Return the last autoLayout rule, if any.

exclude

exclude(*items: Any) -> Self

Add an exclude rule.

Parameters:

Name Type Description Default
*items Any

Same kinds of item as include.

()

style

style(*targets: Any, **properties: Any) -> Self

Add a style rule.

Parameters:

Name Type Description Default
*targets Any

Items to style.

()
**properties Any

Element style properties.

{}

include

include(*items: Any) -> Self

Add an include rule.

Parameters:

Name Type Description Default
*items Any

Deployment nodes or instances, Wildcard, Children, Descendants or RawPredicate objects.

()

c4.contrib.likec4.DynamicView

Bases: _View

A dynamic view: an ordered, flat list of steps.

The steps live in a list of immutable nodes so that block nodes can be added later without changing the flat-step API.

Attributes:

Name Type Description
key

Unique view key.

title

Optional title.

description

Optional Markdown description.

variant DynamicVariant

diagram (default) or sequence.

auto_layout

auto_layout(
    direction: str = "TopBottom",
    rank_sep: int | None = None,
    node_sep: int | None = None,
) -> Self

Add an autoLayout rule.

Parameters:

Name Type Description Default
direction str

TopBottom, LeftRight, BottomTop or RightLeft.

'TopBottom'
rank_sep int | None

Optional spacing between ranks.

None
node_sep int | None

Optional spacing between nodes; needs rank_sep.

None

layout property

layout: AutoLayoutRule | None

Return the last autoLayout rule, if any.

steps property

steps: tuple[DynamicStep, ...]

Return the steps in order.

step

step(
    source: Element,
    target: Element,
    title: str | None = None,
    **properties: Any,
) -> Self

Add a source -> target step.

Parameters:

Name Type Description Default
source Element

Sending element.

required
target Element

Receiving element.

required
title str | None

Step label.

None
**properties Any

description, technology, notes, navigate_to and color.

{}

back

back(
    receiver: Element,
    sender: Element,
    title: str | None = None,
    **properties: Any,
) -> Self

Add a receiver <- sender step.

Parameters:

Name Type Description Default
receiver Element

Element on the left of the arrow; it receives.

required
sender Element

Element on the right of the arrow; it sends.

required
title str | None

Step label.

None
**properties Any

Same as step.

{}

c4.contrib.likec4.DynamicStep dataclass

One interaction of a dynamic view.

Attributes:

Name Type Description
source Element

Element that appears on the left of the arrow.

target Element

Element that appears on the right of the arrow.

title str | None

Step label.

description str | None

Longer Markdown description.

technology str | None

Technology of the interaction.

notes str | None

Markdown notes.

navigate_to str | None

Key of a dynamic view to open on click.

color str | None

Theme or custom color name.

backward bool

True for source <- target.

c4.contrib.likec4.Wildcard dataclass

The * predicate: the scope of a view or all top-level elements.

c4.contrib.likec4.Children dataclass

The direct children of element (element.*).

c4.contrib.likec4.Descendants dataclass

All nested elements of element (element.**).

c4.contrib.likec4.Rel

Rel(
    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,
) -> _RelExpression

Start a relationship expression: a >> Rel("calls") >> b.

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

Parameters:

Name Type Description Default
title str | None

Relationship label.

None
description str | None

Longer Markdown description.

None
technology str | None

Technology used by the relationship.

None
kind str | None

Declared relationship kind.

None
bidirectional bool

Declare the relationship with <->.

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

Tags applied to the relationship, without #.

None
metadata Mapping[str, Any] | None

Custom metadata.

None
links list[Any] | tuple[Any, ...] | None

Hyperlinks.

None
navigate_to str | None

Key of the dynamic view to open on click.

None
**style Any

Relationship-local style properties.

{}

c4.contrib.likec4.Where dataclass

item where tag is #tag and kind is kind filter over another item.

Attributes:

Name Type Description
item Any

Element, Wildcard, Children or Descendants.

tag str | None

Tag name written without #.

kind str | None

Element kind name.

c4.contrib.likec4.RawPredicate dataclass

Predicate text emitted verbatim; the renderer cannot check it.