Skip to main content

No project description provided

Project description

speckenv because a speck is a synonym for a dot and because Speck is awesome.

Usage

Read the settings contained in ./.env into os.environ:

from speckenv import read_speckenv

read_speckenv()

Note that read_speckenv uses os.environ.setdefault to set new values, which means that if a particular key exists more than once in the file the first value is retained, not the last.

If the file is named differently or resides in a different path, pass the full path as first argument to read_speckenv.

Read individual values:

from speckenv import env

# Standard usage:
SETTING1 = env("SETTING1")

# Fallback, if SETTING2 is not set (truthyness doesn't matter):
SETTING2 = env("SETTING2", default="bla")

# Fail hard if missing:
SETTING3 = env("SETTING3", required=True)

# Coerce the value before returning it (coercion is also applied to
# default values):
SETTING4 = env("SETTING4", coerce=bool)

The following values are evaluated as Python literals:

BOOL=True  # And False, None etc.
NUMBER=42
SWEET_HOME=["localhost", "127.0.0.1"]

Additional whitespace around the equals sign is supported. Empty lines and lines starting with a # are ignored:

THIS_IS_IGNORED
# COMMENTED_OUT=VALUE
THIS = WORKS

NOTE! You should treat everything except for the first argument to both env and read_speckenv as keyword-only. Since speckenv still supports Python 2 this isn’t enforced by the code right now.

It may be useful to use a mapping separate from os.environ. This is easily possible by overriding the default mapping argument:

from speckenv import env, read_speckenv

mapping = {}
read_speckenv("file_with_variables.env", mapping=mapping)
setting1 = env("SETTING1", mapping=mapping)

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

speckenv-2.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

speckenv-2.0-py2.py3-none-any.whl (4.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file speckenv-2.0.tar.gz.

File metadata

  • Download URL: speckenv-2.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.7

File hashes

Hashes for speckenv-2.0.tar.gz
Algorithm Hash digest
SHA256 3163d6621ab99d7c21c55758e1a8544fe23172f75ad62c43bc089901efa6c478
MD5 6b63549f6d12258154963d055d7dcf8d
BLAKE2b-256 5143fade570b1a39fe3bc4108edb38481fb9959ab6742a5b0bab036a128c415d

See more details on using hashes here.

File details

Details for the file speckenv-2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: speckenv-2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.7

File hashes

Hashes for speckenv-2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6abdd9e8fba48db875b435b9e69800990af9d648ba5db5913c9094ea7f001768
MD5 b4d2c3169bcb0516c3f9f5eecf96d274
BLAKE2b-256 2c34096cda19688c72aeebe91bc476beac425fc30889fd95a513cbc9677a6971

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