Skip to main content

Get boolean values from environment variables

Project description

env-flag

version python versions license build coverage code style

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

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.

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-flag-2.1.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

env_flag-2.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file env-flag-2.1.0.tar.gz.

File metadata

  • Download URL: env-flag-2.1.0.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for env-flag-2.1.0.tar.gz
Algorithm Hash digest
SHA256 0569a6b10b2f712363500bb2b8104b27f2ca7e6fd8ba1ba77b1027f653fb2f04
MD5 8fe949e46a455b664c5fe11ca20789c7
BLAKE2b-256 7bc15d4ec034c2b6b8f0eae08bac207654ea499346666b7e94f63ab6ebae8166

See more details on using hashes here.

Provenance

File details

Details for the file env_flag-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: env_flag-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for env_flag-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e8ff9edcc8fe5731c65ff81601514f9d9c3ad620c8eef4c5842a01f626b2bb8a
MD5 a43ec73d2c89da71bc57dd144ee02228
BLAKE2b-256 1daaf46b00e99985e1a8c253d24854ca33fccdf48ad4b985cf7bd005b6cc6488

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page