A library for loading and accessing environment variable values from various sources.
Project description
eggviron
Manage loading key:value pairs at runtime from various sources. Values can then
be accessed from os.environ similar to the
python-dotenv library.
Additionally, the Eggviron object provides a dictionary-like interface for
accessing all loaded values. All keys and values are stored as strings with
methods in Eggviron for converting to int, float, and bool as needed.
Don't want to mutate the os.environ? Turn off mutation when using the
Eggviron class.
Loaders allow the selection of source for the key:value pairs and which order they are loaded in. Prevent clobbering existing values when loading multiple sources by default.
Example:
from eggviron import Eggviron
from eggviron import EnvFileLoader
from eggviron import AWSParamStoreLoader
environ = Eggviron().load(
# Load the local '.env' file
EnvFileLoader(),
# Load all key:value pairs from AWS Parameter Store
AWSParamStoreLoader(parameter_path="/prod/frontend-api/"),
)
print(f"Using local account: {environ['ACCOUNT_ID']}")
print(f"New UI feature flag: {environ.get_bool('FEATURE_FLAG_NEW_UI')}")
Logging
- Logger name:
eggviron - No handlers, levels, or formatters are applied to the core library
- Minimal logging is used.
API Reference
Eggviron(*, raise_on_overwrite: bool = True, mutate_environ: bool = True)
A key:value store optionally loaded through Loaders. By default, key:value pairs added
- raise_on_overwrite: If True a KeyError will be raised when an existing key is overwritten by an assignment or load() action.
- mutate_environ: If True then the os.environ values are mutated when .load() is run or Eggviron is updated.
load(loader: Loader) -> Eggviron
Use loader(s) to update the loaded values. Loaders are used in the order provided. Key:value pairs are added to os.environ after each loader is run if mutation is allow.
get(key: str, default: str | None = None) -> str
Get a value from the Eggviron. If default is None and the key is not found, a
KeyError will be raised.
get_int(key: str, default: int | None = None) -> int
Get a value from the Eggviron, converting it to an int. If default is None and
the key is not found, a KeyError will be raised.
get_float(key: str, default: float | None = None) -> float
Get a value from the Eggviron, converting it to an float. If default is None and
the key is not found, a KeyError will be raised.
get_bool(key: str, default: bool | None = None) -> bool
Get a value from the Eggviron, converting it to an bool. If default is None and
the key is not found, a KeyError will be raised.
Valid boolean values are "true", "false", "1", and "0" (case insensitive)
EnvironLoader()
Load current os.environ key:value pairs into the Eggviron instance.
EnvFileLoader(filename: str = "./.env")
Load a local '.env' file into the Eggviron instance.
AWSParamStoreLoader (*, parameter_path: str, parameter_name: str, aws_region: str | None = None, truncate_key: bool = False, recursive: bool = False)
Load all key:value pairs found under given path from AWS Parameter Store (SSM). Requires AWS access keys to be set in the environment variables. Only parameter_path or parameter_name is accepted, not both.
- parameter_path: Path of parameters. e.g.: /Finance/Prod/IAD/WinServ2016/
- parameter_name: Parameter name to load. e.g.: /Finance/Prod/IAD/WinServ2016/license33
- aws_region: Region to load from. Defaults to AWS_DEFAULT_REGION environment variable
- truncate_key: When True only the final component of the path will be used as the key
- recursive: Recursively load all nested paths under given parameter_path
The AWSParamStoreLoader requires boto3 and botocore to be installed. If
eggviron is installed with the aws extra, these packages will be included.
For convenience, AWSParamStoreLoader will raise AWSParamStoreException for
all boto3 client errors with detailed attributes for troubleshooting.
AWSParamStoreException(message: str, code: str | None, request_id: str | None, http_status_code: int | None = None, http_headers: dict[str, str] = {}, retry_attemps: int | None = None)
Raised from all botocore.exceptions.ClientError and
botocore.exceptions.BotoCoreError exceptions in AWSParamStoreLoader. If
available, contains the required information for troubleshooting the error.
env file format
The env file format supports many formatting features.
# Comments are allowed
; With either leading charater
simple=value # Inline comments are supported
complex = value; there must be a leading whitespace for inline comments
quoted = 'First layer of matching quotes is stripped'
trickery="We're #1 but only because of the quotes here"
# leading export keywords are stripped
export TOKEN = sometoken
; Whitespace around key:pairs is trimmed except when quoted
whitespace = trimmed
{
"simple": "value",
"complex": "value; there must be a leading whitespace for inline comments",
"quoted": "First layer of matching quotes is stripped",
"trickery": "We're #1 but only because of the quotes here",
"TOKEN": "sometoken",
"whitespace": "trimmed"
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file eggviron-1.0.0.tar.gz.
File metadata
- Download URL: eggviron-1.0.0.tar.gz
- Upload date:
- Size: 86.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36ff9be59fb3e847de7453e7209b048da9a3266b4a5cbe93ae444550e77add1d
|
|
| MD5 |
ba8485bf3450cdf0be490196161c11ca
|
|
| BLAKE2b-256 |
41b795df584ddb46f0dc43aebf567f716109882ee4c8aa97bc5f7da134db62bb
|
Provenance
The following attestation bundles were made for eggviron-1.0.0.tar.gz:
Publisher:
pypi-publish.yml on Preocts/eggviron
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
eggviron-1.0.0.tar.gz -
Subject digest:
36ff9be59fb3e847de7453e7209b048da9a3266b4a5cbe93ae444550e77add1d - Sigstore transparency entry: 428700048
- Sigstore integration time:
-
Permalink:
Preocts/eggviron@bb9ab36137419d26e1b36ec338f074388165bdfa -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/Preocts
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@bb9ab36137419d26e1b36ec338f074388165bdfa -
Trigger Event:
release
-
Statement type:
File details
Details for the file eggviron-1.0.0-py3-none-any.whl.
File metadata
- Download URL: eggviron-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37fcc249689a38d07a8197174879eff26b46dd1529dcb8f234b9c857a576ab9c
|
|
| MD5 |
26bbde5840240289f3716f7de6086809
|
|
| BLAKE2b-256 |
55c52ff48563a42ffb15349ccf3d9951678d706ef4c8e4de159437b22a5b11fb
|
Provenance
The following attestation bundles were made for eggviron-1.0.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on Preocts/eggviron
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
eggviron-1.0.0-py3-none-any.whl -
Subject digest:
37fcc249689a38d07a8197174879eff26b46dd1529dcb8f234b9c857a576ab9c - Sigstore transparency entry: 428700059
- Sigstore integration time:
-
Permalink:
Preocts/eggviron@bb9ab36137419d26e1b36ec338f074388165bdfa -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/Preocts
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@bb9ab36137419d26e1b36ec338f074388165bdfa -
Trigger Event:
release
-
Statement type: