Skip to main content

Python environment toolchain

Project description

https://travis-ci.org/pedroburon/python-envtools.svg?branch=master https://coveralls.io/repos/github/pedroburon/python-envtools/badge.svg?branch=master

Useful environment toolchain for python

override_environment

Context Processor that overrides environment vars.

>>> @override_environment(DEBUG=False, FOO="Bar")
>>> def foo():
>>>     print(os.getenv("FOO"))
>>>     return os.getenv("DEBUG")
>>> foo()
FOO
"DEBUG"
>>> with override_environment(DEBUG="False", FOO="Bar"):
>>>     print(os.getenv("FOO"))
>>>     os.getenv("DEBUG")
FOO
"DEBUG"

configure_logging

Wrap a configDict inside configure_logging, then logging level could be controlled by environment variables

LOGGING = configure_logging({
    "loggers": {
        "module": {
            "handlers": ["console"],
            "level": "INFO",
        },
    }
})

For this example, environment variable must be set as LOGGING_LEVEL_module=DEBUG.

get_env

Similar to os.getenv() but evaluates string content (default) into simple python types.

>>> os.environ['FOO'] = "1"
>>> os.getenv('FOO')
"1"
>>> get_env('FOO')
1

>>> os.environ['FOO'] = "bar"
>>> get_env('FOO')
"bar"

>>> os.environ['FOO'] = "True"
>>> os.getenv('FOO')
"True"
>>> get_env('FOO')
True

>>> os.environ['FOO'] = "[1,2,3]"
>>> os.getenv('FOO')
"[1,2,3]"
>>> get_env('FOO')
[1, 2, 3]

it works for list, tuples, dictionaries, numbers, booleans and strings. And is safe!

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

python-envtools-0.0.1rc1.tar.gz (5.5 kB view details)

Uploaded Source

File details

Details for the file python-envtools-0.0.1rc1.tar.gz.

File metadata

File hashes

Hashes for python-envtools-0.0.1rc1.tar.gz
Algorithm Hash digest
SHA256 542043415dece01bace1d626bae7e512b227548454ffb2e794976d835814cab5
MD5 2e97140789bdcfd64f12777e1d773079
BLAKE2b-256 650aab7a5a44dca60669859f74cf5c68ccb8bbd2d3b5ed90d738f825046d881e

See more details on using hashes here.

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