Skip to main content
Version: 1.33.0 (latest) View Markdown

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

NameTypeDescription
profilestr | None | KeepA 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

ExceptionWhen
BadRequestThe runtime rejected the request as invalid. message, code and fields say why.
DataplaneTokenRejectedThe data plane rejected the token that the runtime issued for it.
NotAuthorizedThe caller lacks the access that this call needs. message says why.
ScopeMissingNo 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

NameTypeDescription
profilestr | NoneThe scope to write to, or WORKSPACE_PROFILE for the workspace-level one. Required, because a write always names one scope.
upsertsMapping[str, str] | NoneNames and values to store as plain text.
secretsMapping[str, str] | NoneNames and values to store as secrets.
deletesSequence[str] | NoneNames 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

ExceptionWhen
BadRequestThe runtime rejected the request as invalid. message, code and fields say why.
ConflictAnother change to the same scope is in progress (variables_scope_locked). A retry can succeed.
DataplaneTokenRejectedThe data plane rejected the token that the runtime issued for it.
NotAuthorizedThe caller lacks the access that this call needs. message says why.
ScopeMissingNo workspace in scope.
ValueErrorNothing 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

NameTypeDescription
namestrThe name of the variable.
valuestrIts value.
profilestr | NoneThe scope to write to, or WORKSPACE_PROFILE.
secretboolWhether 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

ExceptionWhen
BadRequestThe runtime rejected the request as invalid. message, code and fields say why.
ConflictAnother change to the same scope is in progress (variables_scope_locked). A retry can succeed.
DataplaneTokenRejectedThe data plane rejected the token that the runtime issued for it.
NotAuthorizedThe caller lacks the access that this call needs. message says why.
ScopeMissingNo workspace in scope.

Variables.delete()​

delete(name: str, *, profile: str | None) -> VariableChange

Remove one variable.

Arguments

NameTypeDescription
namestrThe name of the variable.
profilestr | NoneThe 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

ExceptionWhen
BadRequestThe runtime rejected the request as invalid. message, code and fields say why.
ConflictAnother change to the same scope is in progress (variables_scope_locked). A retry can succeed.
DataplaneTokenRejectedThe data plane rejected the token that the runtime issued for it.
NotAuthorizedThe caller lacks the access that this call needs. message says why.
ScopeMissingNo 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

NameTypeDescription
namestrThe name of the variable.
profilestr | NoneThe scope to read, or WORKSPACE_PROFILE.

Returns: Variable — The variable. Async mode returns an awaitable.

Raises

ExceptionWhen
BadRequestThe runtime rejected the request as invalid. message, code and fields say why.
DataplaneTokenRejectedThe data plane rejected the token that the runtime issued for it.
NotAuthorizedThe caller lacks the access that this call needs. message says why.
NotFoundNo variable of that name in that scope.
ScopeMissingNo 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

NameTypeDescription
namestrEnvironment variable name.
secretboolWhether the runtime stores it as a secret.
valuestr | NoneThe value, or None for a secret.
created_atdatetimeWhen the variable was created.
created_bystrID of the user who created the variable.
updated_atdatetimeWhen the variable was last updated.
updated_bystrID of the user who last updated the variable.

VariableChange​

What a change did to one name.

Attributes

NameTypeDescription
namestrEnvironment variable name.
statusVariableChangeStatusWhat 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

NameTypeDescription
profilestr | NoneProfile owning this scope; None is the workspace-wide scope.
variablestuple[Variable, ...]Variables in this scope, secrets redacted.

VariableChangeStatus​

What became of one name in a change.

Members

MemberValueDescription
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.

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.