Skip to content

cmem_client.repositories.variables¤

Repository for the variables of DataIntegration projects.

Provides VariablesRepository for creating, updating and deleting project variables and the execution variables of tasks. Project variables are keyed by project_id:variable_name, execution variables by project_id:task_id:variable_name, so a single repository spans the variables of all projects and their tasks.

Examples:

Create a variable in a project and read its value back:

>>> from cmem_client.client import Client
>>> from cmem_client.models.variable import Variable
>>> client = Client.from_env()
>>> client.variables.create_item(
...     Variable(name="greeting", project_id="my-project", value="hello")
... )
>>> client.variables["my-project:greeting"].value
>>> client.variables.get_item("my-project", "greeting").value

Create an execution variable on a task and read its value back:

>>> client.variables.create_item(
...     Variable(
...         name="limit", project_id="my-project", task_id="my-workflow", value="10", scope="execution"
...     )
... )
>>> client.variables.get_item("my-project", "limit", task_id="my-workflow").value

See what still uses a variable, list every variable of the deployment and delete one:

>>> client.variables.get_dependents("my-project:greeting")
>>> list(client.variables)
>>> client.variables.delete_item("my-project:my-workflow:limit")

Classes:

VariableCreateConfig¤

Bases: CreateConfig

Variable creation configuration.

Attributes:

  • model_config –

VariableDeleteConfig¤

Bases: DeleteConfig

Variable deletion configuration.

Attributes:

  • model_config –

VariableUpdateConfig¤

Bases: UpdateConfig

Variable update configuration.

Attributes:

  • model_config –

VariablesRepository¤

Bases: Repository, DeleteItemProtocol, CreateItemProtocol, UpdateItemProtocol

Repository for project variables, execution variables and global variables.

Manages the variables of all projects in the eccenca Corporate Memory DataIntegration (Build) environment together with the execution variables of their tasks. Project variables are stored with keys in the form project_id:variable_name, execution variables with keys in the form project_id:task_id:variable_name.

The global variables are part of the repository as well, with their name as key. They are defined in the configuration of DataIntegration, so they are read-only and can neither be created, updated nor deleted.

Fetching all variables masks sensitive ones, their value is empty. Use get_item() to read a single project or execution variable including its value.

Attributes:

  • tasks (dict[str, str]) – Labels of all tasks of all projects by project_id:task_id, including tasks without execution variables, as of the last fetch.
  • errors (dict[str, str]) – Errors the server reported for single variables on the last fetch, by variable ID. A variable has an error, e.g. if its template can not be resolved.

Functions:

  • create_item – Create (add) a new item to the repository
  • delete_all – Delete all items from the repository
  • delete_item – Delete an item from the repository
  • fetch_data – Fetch the global variables, those of all projects and the execution variables of their tasks.
  • get_dependents – Get the variables and tasks which still use a variable.
  • get_item – Get a single variable by project, name and optionally task.
  • items – Get the items of the repository
  • keys – Get the keys of the repository
  • raise_modification_error – Raise an exception if needed
  • update_item – Update an existing item in the repository.
  • values – Get the values of the repository

create_item¤

create_item(item, skip_if_existing=False, configuration=None)

Create (add) a new item to the repository

Parameters:

  • item (ItemType) – The item to add to the repository
  • skip_if_existing (bool) – If true, creating already existing items will be ignored
  • configuration (CreateItemConfig_contra | None) – Optional configuration

Raises:

delete_all¤

delete_all()

Delete all items from the repository

delete_item¤

delete_item(key, skip_if_missing=False, configuration=None)

Delete an item from the repository

Parameters:

  • key (str) – The key of the item to delete
  • skip_if_missing (bool) – If True, it is ignored if the deleted item even exists
  • configuration (DeleteItemConfig) – Optional configuration for deletion

Raises:

errors¤

errors: dict[str, str]

fetch_data¤

fetch_data()

Fetch the global variables, those of all projects and the execution variables of their tasks.

Raises:

  • RepositoryReadError – If Build does not provide the variables in one request, because it is too old.

get_dependents¤

get_dependents(key)

Get the variables and tasks which still use a variable.

A variable which is used cannot be deleted. The server reports only some of its dependents on a failed deletion, while this lists all of them.

Parameters:

  • key (str) – Combined variable key in the format project_id:variable_name or project_id:task_id:variable_name.

Returns:

Raises:

  • HTTPStatusError – If the variable is not found or the request fails.

get_item¤

get_item(project_id, variable_name, task_id=None)

Get a single variable by project, name and optionally task.

Parameters:

  • project_id (str) – The project ID.
  • variable_name (str) – The variable name.
  • task_id (str | None) – The task ID of an execution variable. Omit it for a project variable.

Returns:

Raises:

  • HTTPStatusError – If the variable is not found or the request fails.

items¤

items()

Get the items of the repository

keys¤

keys()

Get the keys of the repository

logger¤

logger: logging.Logger

Gets the client logger

raise_modification_error¤

raise_modification_error(response)

Raise an exception if needed

tasks¤

tasks: dict[str, str]

update_item¤

update_item(item, configuration=None)

Update an existing item in the repository.

Parameters:

  • item (ItemType) – The item to update in the repository.
  • configuration (UpdateItemConfig_contra | None) – Optional configuration for the update operation.

Raises:

values¤

values()

Get the values of the repository

Comments