pip install envless-envenvless-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
| Export | Signature |
|---|---|
env | Every variable, coerced. Raises MissingVariableError for a name that is not set |
optional | The same view, None for a name that is not set |
load | (*, revalidate: bool = False) -> dict[str, str] |
aload | async (*, revalidate: bool = False) -> dict[str, str], in a worker thread |
override | (values: Mapping[str, str]) -> Override, a context manager with close() |
Override | The type override() returns |
envless_env.client
| Export | Signature |
|---|---|
env | Client variables only. Raises ServerOnlyError for a server variable |
optional | The 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
| Export | Notes |
|---|---|
env | Every variable, like envless_env.server.env |
load, aload | As above |
encrypt, decrypt, passphrase_strength, ENCRYPTION_PARAMETERS | The crypto helpers, also in envless_env.crypto |
Env, OptionalEnv | The types of the views |
EnvlessEnvError, LoadError, NotLoadedError, MissingVariableError, ServerOnlyError, ReadOnlyError, SerialisationError | The 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
| Export | Signature |
|---|---|
load | (*, token, project, environment, product=None, passphrase=None, key=None, workspace_id=None, endpoint=None, http_client=None) -> dict[str, str] |
aload | The same arguments, async, in a worker thread |
See Serverless.
envless_env.crypto
| Export | Signature |
|---|---|
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_PARAMETERS | The 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
| Module | Export |
|---|---|
envless_env.django | context_processor(request) -> dict, client variables as envless in templates |
envless_env.flask | init_app(app, *, config=True) -> dict[str, str] |
envless_env.fastapi | lifespan, and with_envless(inner) to wrap your own lifespan |
envless_env.pydantic | EnvlessSettingsSource, 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.
| Error | Raised when | Also a |
|---|---|---|
LoadError | A load fails. See when a load fails | |
NotLoadedError | A read before the first load | |
MissingVariableError | A read through env of a name that is not set. Carries variable | AttributeError, KeyError |
ServerOnlyError | A read of a server variable through envless_env.client. Carries variable | |
ReadOnlyError | Setting or deleting a name on a view | AttributeError |
SerialisationError | Pickling or iterating a view | TypeError |