Variables
New to the SDK? Getting started shows how to connect and use it.
Variables
The variables of one workspace, across its scopes.
The SDK reads a whole scope at once. There is no paging and no per-variable address.
Variables.list()
list(*, profile: str | None | Keep = KEEP) -> tuple[VariableScope, ...]
Read the variables of the workspace, by scope.
Arguments
| Name | Type | Description |
|---|---|---|
profile | str | None | Keep | A profile name reads the scope of that profile. WORKSPACE_PROFILE reads the workspace-level scope. KEEP, the default, reads every scope. |
Returns: tuple[VariableScope, ...] — One entry per scope read, as scopes even when the call selected one. Async mode returns an awaitable.
Raises
| Exception | When |
|---|---|
BadRequest | The runtime rejected the request as invalid. message, code and fields say why. |
DataplaneTokenRejected | The data plane rejected the token that the runtime issued for it. |
NotAuthorized | The caller lacks the access that this call needs. message says why. |
ScopeMissing | No workspace in scope. |
Variables.apply()
apply(
*,
profile: str | None,
upserts: Mapping[str, str] | None = None,
secrets: Mapping[str, str] | None = None,
deletes: Sequence[str] | None = None,
) -> tuple[VariableChange, ...]
Store and remove variables in one scope, in a single request.
Arguments
| Name | Type | Description |
|---|---|---|
profile | str | None | The scope to write to, or WORKSPACE_PROFILE for the workspace-level one. Required, because a write always names one scope. |
upserts | Mapping[str, str] | None | Names and values to store as plain text. |
secrets | Mapping[str, str] | None | Names and values to store as secrets. |
deletes | Sequence[str] | None | Names to remove. The result reports an absent name, and the call does not raise. |
Returns: tuple[VariableChange, ...] — One result per name in the request. Async mode returns an awaitable.
Raises
| Exception | When |
|---|---|
BadRequest | The runtime rejected the request as invalid. message, code and fields say why. |
Conflict | Another change to the same scope is in progress (variables_scope_locked). A retry can succeed. |
DataplaneTokenRejected | The data plane rejected the token that the runtime issued for it. |
NotAuthorized | The caller lacks the access that this call needs. message says why. |
ScopeMissing | No workspace in scope. |
ValueError | Nothing to do, or a name appears in more than one of the three arguments, which has no defined outcome. |
Variables.set()
set(name: str, value: str, *, profile: str | None, secret: bool = False) -> VariableChange
Store one variable.
Arguments
| Name | Type | Description |
|---|---|---|
name | str | The name of the variable. |
value | str | Its value. |
profile | str | None | The scope to write to, or WORKSPACE_PROFILE. |
secret | bool | Whether the runtime stores it as a secret. A read never returns a secret value. |
Returns: VariableChange — What the runtime did with it. Async mode returns an awaitable.
Raises
| Exception | When |
|---|---|
BadRequest | The runtime rejected the request as invalid. message, code and fields say why. |
Conflict | Another change to the same scope is in progress (variables_scope_locked). A retry can succeed. |
DataplaneTokenRejected | The data plane rejected the token that the runtime issued for it. |
NotAuthorized | The caller lacks the access that this call needs. message says why. |
ScopeMissing | No workspace in scope. |
Variables.delete()
delete(name: str, *, profile: str | None) -> VariableChange
Remove one variable.
Arguments
| Name | Type | Description |
|---|---|---|
name | str | The name of the variable. |
profile | str | None | The scope to remove it from, or WORKSPACE_PROFILE. |
Returns: VariableChange — What the runtime did. An absent name comes back as attr:VariableChangeStatus.NOT_FOUND, and the call does not raise. Async mode returns an awaitable.
Raises
| Exception | When |
|---|---|
BadRequest | The runtime rejected the request as invalid. message, code and fields say why. |
Conflict | Another change to the same scope is in progress (variables_scope_locked). A retry can succeed. |
DataplaneTokenRejected | The data plane rejected the token that the runtime issued for it. |
NotAuthorized | The caller lacks the access that this call needs. message says why. |
ScopeMissing | No workspace in scope. |
Variables.get()
get(name: str, *, profile: str | None) -> Variable
Return one variable from one scope.
There is no single-variable endpoint, so the call reads the whole scope.
Arguments
| Name | Type | Description |
|---|---|---|
name | str | The name of the variable. |
profile | str | None | The scope to read, or WORKSPACE_PROFILE. |
Returns: Variable — The variable. Async mode returns an awaitable.
Raises
| Exception | When |
|---|---|
BadRequest | The runtime rejected the request as invalid. message, code and fields say why. |
DataplaneTokenRejected | The data plane rejected the token that the runtime issued for it. |
NotAuthorized | The caller lacks the access that this call needs. message says why. |
NotFound | No variable of that name in that scope. |
ScopeMissing | No workspace in scope. |
Variable
One variable, as the runtime reports it.
The value of a secret is None because the runtime withholds it, not
because it is empty.
Attributes
| Name | Type | Description |
|---|---|---|
name | str | Environment variable name. |
secret | bool | Whether the runtime stores it as a secret. |
value | str | None | The value, or None for a secret. |
created_at | datetime | When the variable was created. |
created_by | str | ID of the user who created the variable. |
updated_at | datetime | When the variable was last updated. |
updated_by | str | ID of the user who last updated the variable. |
VariableChange
What a change did to one name.
Attributes
| Name | Type | Description |
|---|---|---|
name | str | Environment variable name. |
status | VariableChangeStatus | What happened to this variable: upserted (created or updated), removed, or not_found (a delete named a variable that does not exist). |
VariableScope
The variables that one profile sees, or the workspace-level set.
Attributes
| Name | Type | Description |
|---|---|---|
profile | str | None | Profile owning this scope; None is the workspace-wide scope. |
variables | tuple[Variable, ...] | Variables in this scope, secrets redacted. |
VariableChangeStatus
What became of one name in a change.
Members
| Member | Value | Description |
|---|---|---|
UPSERTED | 'upserted' | Stored, whether it existed before or not. |
REMOVED | 'removed' | Deleted. |
NOT_FOUND | 'not_found' | The change named it for deletion, but it did not exist. |
UNKNOWN | 'unknown' | A status that this SDK version does not know. |
WORKSPACE_PROFILE
WORKSPACE_PROFILE = None
The workspace-level variable scope, which every profile inherits.
With it as profile, a call reads or writes only that scope.