Skip to main content

Simple and lightweight environment variable ingestion

Project description

lightweight-environ

Simple and lightweight environment variable ingestion. No dependencies.

Designed for use with Django but it should be suitable for any Python 3 framework / project.

install

pip install lightweight-environ

usage

Given an environment:

MY_STRING=ford_prefect
MY_INTEGER=42
MY_FLOAT=6.283
MY_BOOLEAN=True
MY_LIST=DONT,PANIC
from lightweight_environ import Env

# Raises a KeyError exception if a variable does not exist
>>> Env.get('A_MISSING_VAR')
Traceback ...
# first optional arg is a default returned if a variable does not exist
>>> Env.get('A_MISSING_VAR', 'foo')
'foo'
# get() returns a string
>>> Env.get('MY_STRING')
'ford_prefect'
# get() _always_ returns a string
>>> Env.get('MY_INTEGER')
'42'
# integer coersion
>>> Env.int('MY_INTEGER')
42
# boolean coersion
>>> Env.bool('MY_BOOLEAN')
True
# Reading via bool does not raise a KeyError exception if a variable does not exist - it returns false
>>> Env.bool('A_MISSING_VAR')
False
# All methods support a default for missing keys
>>> Env.bool('A_MISSING_VAR', True)
True
# float coersion
>>> Env.float('MY_FLOAT')
6.283
# list coersion from a string of comma separated values
>>> Env.list('MY_LIST')
['DONT', 'PANIC']
>>> Env.list('A_MISSING_VALUE', 'Oh,freddled,gruntbuggly')
['Oh', 'freddled', 'gruntbuggly']
>>> Env.list('A_MISSING_VALUE', ['Oh', 'freddled', 'gruntbuggly'])
['Oh', 'freddled', 'gruntbuggly']

# has() tests for variable existence
Env.has('A_MISSING_VALUE')
False
Env.has('MY_INTEGER')
True

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

lightweight-environ-0.1.1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

lightweight_environ-0.1.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file lightweight-environ-0.1.1.tar.gz.

File metadata

  • Download URL: lightweight-environ-0.1.1.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for lightweight-environ-0.1.1.tar.gz
Algorithm Hash digest
SHA256 25740fbfea2a17b16bc46b8aedef2d903d9026762b4424efa3a442e00c1d0039
MD5 80bf0f1ca7777bbe5649e22986f6603b
BLAKE2b-256 b4112749d41b3e731995fce0db92019183750504f7f45dcf1c0b6352e6d19c58

See more details on using hashes here.

File details

Details for the file lightweight_environ-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for lightweight_environ-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2df9b9f65cab36e4bbb45177cef1a4dfc0b0209db6b71dcf5a47f96a1eb4af08
MD5 d536dbe6e42ba87522b15a933bcb9230
BLAKE2b-256 9490f715c37037658934640d858c3fad398df9fbf7800e25803afb2271dce078

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