Skip to content

template

CamundaTemplate

Bases: BaseModel

Camunda template object that follows (incompletely) the official template schema.

Attributes:

Name Type Description
template_schema str

Alias to $schema

name str
template_id Optional[str]
applies_to Optional[List[str]]
properties Optional[List[CamundaProperty]]
groups List[Group]
Source code in python_camunda_sdk/templates/template.py
class CamundaTemplate(BaseModel):
    """Camunda template object that follows (incompletely) the official
    template schema.

    Attributes:
        template_schema: Alias to `$schema`
        name:
        template_id:
        applies_to:
        properties:
        groups:
    """

    template_schema: str = Field(
        default=(
            "https://unpkg.com/@camunda/zeebe-element-templates-json-schema"
            "@0.9.0/resources/schema.json"
        ),
        alias="$schema",
    )

    name: str
    template_id: Optional[str] = Field(
        alias="id", default_factory=lambda: str(uuid4())
    )
    applies_to: Optional[List[str]] = Field(
        alias="appliesTo", default=["bpmn:ServiceTask"]
    )
    properties: Optional[List[CamundaProperty]]
    groups: List[Group]

generate_template(cls)

Generate Camunda template from the connector class definition.

Converts connector class into a Camunda template mapping class fields into template inputs.

Parameters:

Name Type Description Default
cls Connector

Connector class.

required
Example

class MyConnector(OutboundConnector):
    name: str = Field(description="Name")

    class ConnectorConfig:
        name = "MyConnector"
        type = "my_connector"
        timeout = 1
Will be converted to a template called MyConnector. The name field will be converted to an input name and label Name. Attributes of the ConnectorConfig class will be mapped to the attributes of the template.

Returns:

Type Description
CamundaTemplate

A camunda template object that can be converted to json for import into Camunda SAAS or desktop modeller.

Source code in python_camunda_sdk/templates/template.py
def generate_template(cls: Connector) -> CamundaTemplate:
    """Generate Camunda template from the connector class definition.

    Converts connector class into a Camunda template mapping class fields
    into template inputs.

    Parameters:
        cls: Connector class.

    Example:
        ```py
        class MyConnector(OutboundConnector):
            name: str = Field(description="Name")

            class ConnectorConfig:
                name = "MyConnector"
                type = "my_connector"
                timeout = 1
        ```
        Will be converted to a template called `MyConnector`. The `name`
        field will be converted to an input `name` and label
        `Name`. Attributes of the `ConnectorConfig` class will be mapped to
        the attributes of the template.

    Returns:
        A camunda template object that can be converted to json for import
            into Camunda SAAS or desktop modeller.
    """
    props = generate_input_props(cls)

    signature = inspect.signature(cls.run)

    return_annotation = signature.return_annotation

    if return_annotation != signature.empty:
        prop = CamundaProperty(
            label="Result variable",
            binding=Binding(type="zeebe:taskHeader", key="resultVariable"),
            type="String",
            group="output",
        )
        props.append(prop)

    task_type_prop = CamundaProperty(
        value=cls.config.type,
        type="Hidden",
        binding=Binding(type="zeebe:taskDefinition:type"),
    )

    props.append(task_type_prop)

    groups = [
        Group(id="input", label="Input"),
        Group(id="output", label="Output"),
    ]

    if issubclass(cls, InboundConnector):
        props.extend(generate_inbound_config_props(cls))
        groups.append(Group(id="config", label="Configuration"))

    template = CamundaTemplate(
        name=cls.config.name, properties=props, groups=groups
    )

    return template