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. |
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. |
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 |
{}
|
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 |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
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 |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
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 |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
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 |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
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 |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
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 |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
relate ¶
relate(
source: Element,
target: Element,
title: str | None = None,
**kwargs: Any,
) -> Relationship
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 |
|
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 |
|
metadata |
Custom metadata. |
|
links |
Hyperlinks. |
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 |
{}
|
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 |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
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 |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
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 |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
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 |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
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 |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
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 |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
set_style ¶
set_style(**properties: Any) -> Self
Merge element-local style properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**properties
|
Any
|
Element style properties. |
{}
|
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. |
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 |
{}
|
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 |
None
|
**kwargs
|
Any
|
Any other |
{}
|
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 |
{}
|
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 |
|
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. |
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 |
{}
|
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 |
{}
|
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 |
|
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. |
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.
c4.contrib.likec4.Link
dataclass
¶
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. |