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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file speckenv-3.1.tar.gz
.
File metadata
- Download URL: speckenv-3.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 312bdf9ce5661db1e430489b341160cac37b37802a71f34c39a896d3590966c1 |
|
MD5 | ae2997aa56afef4bfca04f3badf1eaf1 |
|
BLAKE2b-256 | f13179b10bccd97aeb1b7636bf1b3d883cb4307810d65a1b6772ba5303eeb152 |
File details
Details for the file speckenv-3.1-py3-none-any.whl
.
File metadata
- Download URL: speckenv-3.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 727ffeb50ab22383687c13f00baae95588f41dcf1a152ec120d03a0558e2df33 |
|
MD5 | d7bf8c08f682f49d26655fd9d3897c88 |
|
BLAKE2b-256 | b733be8a84194450bf414cd995f5e103814432c9e171f944e8f22582cfab39b9 |