Skip to content

Embedded Module (EM)

SDK API reference for the tlm_cloud_sdk.embedded package.

Use this package to interact with the Embedded Manager programmatically. EMClient gives you typed access to projects, builds, GitLab connections, and storage buckets, and EMApiClient reads refs and em-configs and starts builds — the same interfaces that power the tlm-cli em commands.


EMClient

tlm_cloud_sdk.embedded.client.EMClient

Client interface for accessing Embedded Manager API interfaces.

This class exposes a property-based interface for accessing the Embedded Manager API model interfaces. Each property returns an interface responsible for interacting with a specific Embedded Manager model.

Parameters:

Name Type Description Default
session CloudSession | None

The authenticated session whose /resources endpoint to bind.

None
resource_api JsonApiProtocol | None

Instead of session, any provider of an ORM session (e.g. a test double). With neither, the models keep the session already bound, if any. The binding is process-wide and covers every model served by /resources, not only the ones of this client.

None

Examples:

>>> client = EMClient(session)
>>> projects = client.em_project.get_list("firmware_id", "fw-1")
Source code in packages/tlm-cloud-sdk/tlm_cloud_sdk/embedded/client.py
class EMClient:
    """Client interface for accessing Embedded Manager API interfaces.

    This class exposes a property-based interface for accessing the Embedded Manager API
    model interfaces. Each property returns an interface responsible for interacting
    with a specific Embedded Manager model.

    Args:
        session: The authenticated session whose ``/resources`` endpoint to bind.
        resource_api: Instead of ``session``, any provider of an ORM session (e.g. a test double).
            With neither, the models keep the session already bound, if any.
            The binding is process-wide and covers every model served by ``/resources``, not only
            the ones of this client.

    Examples:
        >>> client = EMClient(session)
        >>> projects = client.em_project.get_list("firmware_id", "fw-1")
    """

    def __init__(self, session: CloudSession | None = None, *, resource_api: JsonApiProtocol | None = None) -> None:
        if session is not None and resource_api is not None:
            raise TypeError("Pass either session or resource_api, not both.")
        provider = ResourceApi(session) if session is not None else resource_api
        if provider is None:
            return

        bind_session(ResourcesApiModel, provider.api)

    @property
    def em_project(self) -> EmProjectInterface:
        """Returns the interface for interacting with EmProject resources.

        Returns:
            EmProjectInterface: The interface for managing EmProject models.

        Examples:
            >>> client.em_project.get("firmware_id", "fw-1")
        """
        interface: EmProjectInterface = EMInterfaceFactory.get_interface("em_project")
        return interface

    @property
    def em_build(self) -> EmBuildInterface:
        """Returns the interface for interacting with EmBuild resources.

        Returns:
            EmBuildInterface: The interface for managing EmBuild models.

        Examples:
            >>> client.em_build.get("build_ref", "main")
        """
        interface: EmBuildInterface = EMInterfaceFactory.get_interface("em_build")
        return interface

    @property
    def gitlab_connection(self) -> GitlabConnectionInterface:
        """Returns the interface for interacting with GitlabConnection resources.

        Returns:
            GitlabConnectionInterface: The interface for managing GitlabConnection models.

        Examples:
            >>> client.gitlab_connection.get("name", "dave-gitlab")
        """
        interface: GitlabConnectionInterface = EMInterfaceFactory.get_interface("gitlab_connection")
        return interface

    @property
    def storage_bucket(self) -> StorageBucketInterface:
        """Returns the interface for interacting with StorageBucket resources.

        Returns:
            StorageBucketInterface: The interface for managing StorageBucket models.

        Examples:
            >>> client.storage_bucket.get("name", "em-artifacts")
        """
        interface: StorageBucketInterface = EMInterfaceFactory.get_interface("storage_bucket")
        return interface

em_build property

Returns the interface for interacting with EmBuild resources.

Returns:

Name Type Description
EmBuildInterface EmBuildInterface

The interface for managing EmBuild models.

Examples:

>>> client.em_build.get("build_ref", "main")

em_project property

Returns the interface for interacting with EmProject resources.

Returns:

Name Type Description
EmProjectInterface EmProjectInterface

The interface for managing EmProject models.

Examples:

>>> client.em_project.get("firmware_id", "fw-1")

gitlab_connection property

Returns the interface for interacting with GitlabConnection resources.

Returns:

Name Type Description
GitlabConnectionInterface GitlabConnectionInterface

The interface for managing GitlabConnection models.

Examples:

>>> client.gitlab_connection.get("name", "dave-gitlab")

storage_bucket property

Returns the interface for interacting with StorageBucket resources.

Returns:

Name Type Description
StorageBucketInterface StorageBucketInterface

The interface for managing StorageBucket models.

Examples:

>>> client.storage_bucket.get("name", "em-artifacts")

EMInterfaceFactory

tlm_cloud_sdk.embedded.client.EMInterfaceFactory

Bases: BaseInterfaceFactory

Factory class for retrieving Embedded Manager API interface instances.

This class provides access to interface classes responsible for interacting with the Embedded Manager API models (projects, builds, GitLab connections and storage buckets).

Attributes:

Name Type Description
_model_map dict

A mapping of model names to their interface classes.

Examples:

>>> interface = EMInterfaceFactory.get_interface("em_project")
>>> project = interface.new()
Source code in packages/tlm-cloud-sdk/tlm_cloud_sdk/embedded/client.py
class EMInterfaceFactory(BaseInterfaceFactory):
    """Factory class for retrieving Embedded Manager API interface instances.

    This class provides access to interface classes responsible for interacting
    with the Embedded Manager API models (projects, builds, GitLab connections and
    storage buckets).

    Attributes:
        _model_map (dict): A mapping of model names to their interface classes.

    Examples:
        >>> interface = EMInterfaceFactory.get_interface("em_project")
        >>> project = interface.new()
    """

    _model_map = {
        "em_project": EmProjectInterface,
        "em_build": EmBuildInterface,
        "gitlab_connection": GitlabConnectionInterface,
        "storage_bucket": StorageBucketInterface,
    }

EMApiClient

tlm_cloud_sdk.embedded.rest.EMApiClient

Bases: ServiceClient

Authenticated client for the ToloMEO embedded-manager REST endpoints.

Source code in packages/tlm-cloud-sdk/tlm_cloud_sdk/embedded/rest.py
class EMApiClient(ServiceClient):
    """Authenticated client for the ToloMEO ``embedded-manager`` REST endpoints."""

    _path = "tolomeo/embedded-manager"

    def refs(self, project_id: str) -> list[EmRef]:
        """List the branches and tags a build of the project can run on."""
        data = self.get(f"projects/{project_id}/refs").json()
        return [EmRef.model_validate(ref) for ref in data.get("refs", [])]

    def config(self, project_id: str, ref: str) -> EmConfigDocument:
        """Fetch the project's em-config document at ``ref``."""
        return EmConfigDocument.model_validate(self.get(f"projects/{project_id}/config", params={"ref": ref}).json())

    def create_build(self, project_id: str, request: CreateBuildRequest) -> EmBuildDto:
        """Start a build: the backend triggers the GitLab pipeline and returns the new build."""
        return EmBuildDto.model_validate(self.post(f"projects/{project_id}/builds", json=request.payload()).json())

    def live_build(self, build_id: str) -> EmBuildDto:
        """Return the build merged with a live GitLab read while it is not finished."""
        return EmBuildDto.model_validate(self.get(f"builds/{build_id}/live").json())

config(project_id, ref)

Fetch the project's em-config document at ref.

Source code in packages/tlm-cloud-sdk/tlm_cloud_sdk/embedded/rest.py
def config(self, project_id: str, ref: str) -> EmConfigDocument:
    """Fetch the project's em-config document at ``ref``."""
    return EmConfigDocument.model_validate(self.get(f"projects/{project_id}/config", params={"ref": ref}).json())

create_build(project_id, request)

Start a build: the backend triggers the GitLab pipeline and returns the new build.

Source code in packages/tlm-cloud-sdk/tlm_cloud_sdk/embedded/rest.py
def create_build(self, project_id: str, request: CreateBuildRequest) -> EmBuildDto:
    """Start a build: the backend triggers the GitLab pipeline and returns the new build."""
    return EmBuildDto.model_validate(self.post(f"projects/{project_id}/builds", json=request.payload()).json())

live_build(build_id)

Return the build merged with a live GitLab read while it is not finished.

Source code in packages/tlm-cloud-sdk/tlm_cloud_sdk/embedded/rest.py
def live_build(self, build_id: str) -> EmBuildDto:
    """Return the build merged with a live GitLab read while it is not finished."""
    return EmBuildDto.model_validate(self.get(f"builds/{build_id}/live").json())

refs(project_id)

List the branches and tags a build of the project can run on.

Source code in packages/tlm-cloud-sdk/tlm_cloud_sdk/embedded/rest.py
def refs(self, project_id: str) -> list[EmRef]:
    """List the branches and tags a build of the project can run on."""
    data = self.get(f"projects/{project_id}/refs").json()
    return [EmRef.model_validate(ref) for ref in data.get("refs", [])]