Python

Python runtime reference

Every module and export of envless-env: the env views, load and aload, override, the client snapshot, the explicit loader, the crypto helpers, the framework integrations and the errors.

bash
pip install envless-env

envless-env imports as envless_env, runs on Python 3.10 and newer, and depends on envless-sdk and anyio. Every module below is typed and ships py.typed.

envless_env.server

ExportSignature
envEvery variable, coerced. Raises MissingVariableError for a name that is not set
optionalThe same view, None for a name that is not set
load(*, revalidate: bool = False) -> dict[str, str]
aloadasync (*, revalidate: bool = False) -> dict[str, str], in a worker thread
override(values: Mapping[str, str]) -> Override, a context manager with close()
OverrideThe type override() returns

envless_env.client

ExportSignature
envClient variables only. Raises ServerOnlyError for a server variable
optionalThe same view, None for a name that is not set
snapshot() -> dict[str, str | int | float | bool], every client variable, coerced

Importing envless_env.client also adopts a client payload in ENVLESS_CLIENT_ENV, the variable @goenvless/env/next writes, when the process environment carries one.

envless_env

ExportNotes
envEvery variable, like envless_env.server.env
load, aloadAs above
encrypt, decrypt, passphrase_strength, ENCRYPTION_PARAMETERSThe crypto helpers, also in envless_env.crypto
Env, OptionalEnvThe types of the views
EnvlessEnvError, LoadError, NotLoadedError, MissingVariableError, ServerOnlyError, ReadOnlyError, SerialisationErrorThe errors, below
VERSION, __version__The package version

envless_env.register

Exports nothing. Importing it calls load(), so a failed load raises from the import.

envless_env.edge

ExportSignature
load(*, token, project, environment, product=None, passphrase=None, key=None, workspace_id=None, endpoint=None, http_client=None) -> dict[str, str]
aloadThe same arguments, async, in a worker thread

See Serverless.

envless_env.crypto

ExportSignature
encrypt(plaintext: str, passphrase: str, workspace_unique_id: str) -> str
decrypt(ciphertext: str, passphrase: str, workspace_unique_id: str) -> str
encrypt_with_key(key: WorkspaceKey | bytes, plaintext: str) -> str
decrypt_with_key(key: WorkspaceKey | bytes, ciphertext: str) -> str
workspace_key(passphrase: str, workspace_unique_id: str) -> WorkspaceKey
import_workspace_key(value: str) -> WorkspaceKey, base64url, 32 bytes
passphrase_strength(passphrase: str) -> PassphraseValidation
WorkspaceKey, ENCRYPTION_PARAMETERSThe key type and the recipe's constants

These are the same functions the Python SDK exports under its own names, encrypt being encrypt_value, decrypt being decrypt_value and workspace_key being derive_workspace_key, and they are byte for byte compatible with the dashboard, the CLI and every other Envless package. Derive the key once with workspace_key when you handle more than one value, since encrypt and decrypt run the 200,000 iteration KDF on every call.

python -m envless_env types

Writes a typed module for your variables. Flags: --output PATH, --project SLUG, --product SLUG, --env SLUGS and --check, which exits 1 when the file is stale and writes nothing. See Typed variables.

Integrations

ModuleExport
envless_env.djangocontext_processor(request) -> dict, client variables as envless in templates
envless_env.flaskinit_app(app, *, config=True) -> dict[str, str]
envless_env.fastapilifespan, and with_envless(inner) to wrap your own lifespan
envless_env.pydanticEnvlessSettingsSource, a pydantic-settings source

Each imports its framework only when you import it, and none of the frameworks is a dependency of envless-env.

Errors

Every error a load or a read raises inherits EnvlessEnvError, which inherits EnvlessError from envless-sdk, so one except EnvlessError catches all of them. Misusing an argument raises the usual built-in instead: override() with a value that is not a string and env[1] raise TypeError, and the crypto helpers raise ValueError for a malformed key or an empty passphrase. Names refused from os.environ are logged on the envless_env logger rather than raised.

ErrorRaised whenAlso a
LoadErrorA load fails. See when a load fails
NotLoadedErrorA read before the first load
MissingVariableErrorA read through env of a name that is not set. Carries variableAttributeError, KeyError
ServerOnlyErrorA read of a server variable through envless_env.client. Carries variable
ReadOnlyErrorSetting or deleting a name on a viewAttributeError
SerialisationErrorPickling or iterating a viewTypeError