env-flag
Get boolean values from environment variables in Python.
from env_flag import env_flag
# When unset, default to `False`.
debug = not env_flag('PRODUCTION')
# When unset, use explicit default.
is_local = get_bool('IS_LOCAL', default=True)
Values are coerced as follows:
-
When the variable is unset, or set to the empty string, return
default. -
When the variable is set to a truthy value, return
True. These are the truthy values:- 1
- true, yes, on
-
When the variable is set to the anything else, return
False. Example falsy values:- 0
- no
-
Ignore case and leading/trailing whitespace.
Provides MyPy-compatible type annotations.
Development
./dev.py init
./dev.py test
./dev.py lint
./dev.py black
Contribute
- Issue Tracker: https://github.com/metabolize/env-flag/issues
- Source Code: https://github.com/metabolize/env-flag
Pull requests welcome!
Support
If you are having issues, please let us know.
Acknowledgements
This function was inspired by node-env-flag, the equivalent for Node.js. It was developed at Body Labs by Paul Melnikow and later open sourced. It was forked in 2019 by Paul Melnikow. Thanks to a repository and package transfer from Body Labs, the fork has been merged back into the original.
License
The project is licensed under the two-clause BSD license.
Metadata
Release files for env-flag 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| env-flag-2.1.0.tar.gz | 2.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| env_flag-2.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.4 kB
Release files / env-flag-2.1.0.tar.gz
| Download URL | env-flag-2.1.0.tar.gz |
|---|---|
| Size | 2.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0569a6b10b2f712363500bb2b8104b27f2ca7e6fd8ba1ba77b1027f653fb2f04
|
|
BLAKE2b-256 checksum How to use checksums |
7bc15d4ec034c2b6b8f0eae08bac207654ea499346666b7e94f63ab6ebae8166
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.5
|
Release files / env_flag-2.1.0-py3-none-any.whl
| Download URL | env_flag-2.1.0-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e8ff9edcc8fe5731c65ff81601514f9d9c3ad620c8eef4c5842a01f626b2bb8a
|
|
BLAKE2b-256 checksum How to use checksums |
1daaf46b00e99985e1a8c253d24854ca33fccdf48ad4b985cf7bd005b6cc6488
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.5
|