Skip to main content
Version: devel 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.

A whole scope is read at once — there is no paging and no per-variable address.

Variables.list()​

list(*, profile: str | None | Keep = KEEP) -> tuple[VariableScope, ...]

Read the workspace's variables, by scope.

Arguments

NameTypeDescription
profilestr | None | KeepOmit for every scope. Pass a profile name for that profile's scope, or WORKSPACE_PROFILE for the workspace-level one.

Returns: tuple[VariableScope, ...] — One entry per scope read, always as scopes even when one was selected; awaitable in async mode.

Raises

ExceptionWhen
BadRequestThe request was rejected as invalid; message, code and fields say why.
DataplaneTokenRejectedThe data plane rejected the token the platform issued for it.
NotAuthorizedThe caller lacks the access this call needs; message says why.
ScopeMissingReached without a 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: 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. Removing an absent name is reported, not raised.

Returns: tuple[VariableChange, ...] — One result per name in the request; awaitable in async mode.

Raises

ExceptionWhen
BadRequestThe request was rejected as invalid; message, code and fields say why.
ConflictThe current state does not allow the call, e.g. the workspace is archived; code and message say why.
DataplaneTokenRejectedThe data plane rejected the token the platform issued for it.
NotAuthorizedThe caller lacks the access this call needs; message says why.
ScopeMissingReached without a workspace in scope.
ValueErrorNothing to do, or a name appears in more than one of the three arguments, where the outcome would be undefined.

Variables.set()​

set(name: str, value: str, *, profile: str | None, secret: bool = False) -> VariableChange

Store one variable.

Arguments

NameTypeDescription
namestrThe variable's name.
valuestrIts value.
profilestr | NoneThe scope to write to, or WORKSPACE_PROFILE.
secretboolStore it as a secret, so reads never return the value.

Returns: VariableChange — What the platform did with it; awaitable in async mode.

Raises

ExceptionWhen
BadRequestThe request was rejected as invalid; message, code and fields say why.
ConflictThe current state does not allow the call, e.g. the workspace is archived; code and message say why.
DataplaneTokenRejectedThe data plane rejected the token the platform issued for it.
NotAuthorizedThe caller lacks the access this call needs; message says why.
ScopeMissingReached without a workspace in scope.

Variables.delete()​

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

Remove one variable.

Arguments

NameTypeDescription
namestrThe variable's name.
profilestr | NoneThe scope to remove it from, or WORKSPACE_PROFILE.

Returns: VariableChange — What the platform did; a name that was not there comes back as attr:VariableChangeStatus.NOT_FOUND rather than raising. Awaitable in async mode.

Raises

ExceptionWhen
BadRequestThe request was rejected as invalid; message, code and fields say why.
ConflictThe current state does not allow the call, e.g. the workspace is archived; code and message say why.
DataplaneTokenRejectedThe data plane rejected the token the platform issued for it.
NotAuthorizedThe caller lacks the access this call needs; message says why.
ScopeMissingReached without a 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 this reads the whole scope.

Arguments

NameTypeDescription
namestrThe variable's name.
profilestr | NoneThe scope to read, or WORKSPACE_PROFILE.

Returns: Variable — The variable; awaitable in async mode.

Raises

ExceptionWhen
BadRequestThe request was rejected as invalid; message, code and fields say why.
DataplaneTokenRejectedThe data plane rejected the token the platform issued for it.
NotAuthorizedThe caller lacks the access this call needs; message says why.
NotFoundNo variable of that name in that scope.
ScopeMissingReached without a workspace in scope.

Variable​

One variable, as the platform reports it.

A secret's value is None because it is withheld, not empty.

Attributes

NameTypeDescription
namestrEnvironment variable name.
secretboolWhether the platform 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 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'Asked to be deleted, but was not there.
UNKNOWN'unknown'A status this SDK version does not know.

WORKSPACE_PROFILE​

WORKSPACE_PROFILE = None

The workspace-level variable scope, which every profile inherits.

Pass it as profile to read or write 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.