Manage and get process.env
Project description
env-get
Manage and retrieve env variables in Python.
Install
$ pip install env-get
Usage
from env_get import env
port = env('SERVER_PORT', env.integer, 80)
env(key, converter, defaults) -> Any
def Converter(v: Any, key: str, is_default: bool) -> Any:
- key
str: The environment variable key. - converter
Optional[Converter | List[Converter]]A converter function or a list of converter functions.- v the current value of the variable
- key the key of the environment variable
- is_default
Truemeans the environment variable is not set, even not set asFOO=
- defaults
Opitonal[Any]The optional default value if the environment variable is not found.
Returns Any the retrieved env variable.
Built-in Converter Functions
env.boolean: Converts the value to a boolean. Treats'true','1','Y','y','yes', andTrueasTrue.env.integer: Converts the value to an integer. Returns0if conversion fails.env.required: Ensures that the environment variable is set. Raises aEnvRequiredErrorif not.
Examples
Boolean Conversion
debug_mode = env('DEBUG_MODE', env.boolean, False)
Integer Conversion
port = env('PORT', env.integer, 8080)
Required Variable
from env_get import env, EnvRequiredError
try:
api_key = env('API_KEY', env.required)
except RangeError as e:
print(e) # Output: env "API_KEY" is required
Handling Multiple Converters
You can apply multiple converters by passing a list of converter functions.
value = env('SOME_VAR', [env.required, env.integer], 10)
License
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_get-1.1.0.tar.gz
(5.7 kB
view details)
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 env_get-1.1.0.tar.gz.
File metadata
- Download URL: env_get-1.1.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7cfcb2a659b3c34ad8cc52194b31b1cbe10ebb27b801d7a6ac3cf0f4d72713fb
|
|
| MD5 |
e356d02014852778d7dc3fa5ea4d6ef6
|
|
| BLAKE2b-256 |
a77368ca410cb688e29c823d105545222dd3c74c3b243506a3b3c6e760779397
|
File details
Details for the file env_get-1.1.0-py3-none-any.whl.
File metadata
- Download URL: env_get-1.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aec5a953065e985564f260139c8d935b63a81a386a628d6a6d958beb439be1d4
|
|
| MD5 |
a79af46eb5cd02ba01462b0c49c344c6
|
|
| BLAKE2b-256 |
0de026c5dc9efb7bfe4d8d2e1d42f4a292c06352dd2f7417e143c116b65c3ca6
|