Environment variables parsing and validation using python type hints
Project description
Envarify
Environment variables parsing and validation using python type hints
Usage
Having some environment variables:
export TIMEOUT_S=2.5
export API_KEY=some_key
export ENABLE_FEATURE=true
We can create a config object in Python:
from envarify import BaseConfig, EnvVar
class MyConfig(BaseConfig):
timeout_s: float = EnvVar("TIMEOUT_S")
api_key: str = EnvVar("API_KEY")
enable_feature: bool = EnvVar("ENABLE_FEATURE", default=False)
config = MyConfig.fromenv()
print(config)
#> MyConfig(timeout_s=2.5, api_key="some_key", enable_feature=True)
Missing environment variables
If there are some required environment variables that are not set, error will be raised:
config = MyConfig.fromenv()
#> MissingEnvVarsError: TIMEOUT_S, API_KEY
Testing
In unit tests for your application you don't have to worry about mocking the environment variables. Instead just create a mock config object:
mock_config = MyConfig(timeout_s=4.2, api_key="dummy", enable_feature=True)
Supported Types
Currently the following types are supported
- int
- float
- bool
- str
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
envarify-0.0.2.tar.gz
(6.1 kB
view details)
Built Distribution
File details
Details for the file envarify-0.0.2.tar.gz
.
File metadata
- Download URL: envarify-0.0.2.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19a40ed797b2e254fef5078b79cc893264e143f36cb67dab625d3168dd21746c |
|
MD5 | c8659c0cf3f456a29d52686d8c801f23 |
|
BLAKE2b-256 | 9598aa511b3e93a5966002fcf3f8469069d4a011e3a7b4443cd5e9326efd38a9 |
File details
Details for the file envarify-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: envarify-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76f1de087b3b1106a9f4a1993fef1f7574cfdbd00d6278a5d483ef1a8eff9433 |
|
MD5 | 5e81bf7558073a39a2d8142af94ff6d8 |
|
BLAKE2b-256 | 334def0d4ce5f9688b60d200453c22dfde0a64941e77cf2bd5b55280d7b1bb02 |