Creates a class used to query environmental variables with typehinting a conversion to basic Python types.
Project description
EnvProxy
EnvProxy
provides a class used to query environmental variables with typehinting a conversion to basic Python types.
You can query your environment easily and keep your typehinting.
Installation
Using pip
:
pip install env-proxy
Using poetry
:
poetry add env-proxy
Example
# Import EnvProxy
from env_proxy import EnvProxy
# Basic examples
## Environment variable "DATABASE_HOST"
database_host = EnvProxy.get_str("database-host")
## If you want the function to fail if the value does not exist, use methods with `_strict` suffix
database_nonsene = EnvProxy.get_str_strict("database-nonsense")
### ValueError: No value for key DATABASE_NONSENSE in environment
## Specify default for the (non-zero) variable "DATABASE_PORT"
database_port = EnvProxy.get_int("database-port") or 5432
# Specify custom prefix
class MyProxy(EnvProxy):
env_prefix: Optional[str] = "MYAPP"
## Now all variables are expected to be prefixed with MYAPP_
database_host = EnvProxy.get_str("database-host")
### Searches for MYAPP_DATABASE_HOST variable
Documentation
See docs
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
env_proxy-0.1.2.tar.gz
(1.9 kB
view hashes)
Built Distribution
Close
Hashes for env_proxy-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98d79d0f67f0c4c62033974d3b6e0c4e605b4216f4096bc2b6c9f332f3a0a9db |
|
MD5 | 0fd05a7c58e7c7fff052dc4e74ca64f8 |
|
BLAKE2b-256 | 490d129b3c19ce65ac7f8f1c85828393ce4f32d94915d42ce4671e79e30a5f60 |