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.2.tar.gz
.
File metadata
- Download URL: speckenv-3.2.tar.gz
- Upload date:
- Size: 5.1 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 | ebc4f93f2f567a254a2027cc6d32f3f366910aa98daaf178ebd3853922397b12 |
|
MD5 | f95212afa406c8f1b994d09be04ff8a1 |
|
BLAKE2b-256 | 765c0fceafd35857d94e2ec9c070e910b68778df2674ca57b2a6a36b56c3e2e8 |
File details
Details for the file speckenv-3.2-py3-none-any.whl
.
File metadata
- Download URL: speckenv-3.2-py3-none-any.whl
- Upload date:
- Size: 5.4 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 | 2a3be1848717da2dbbb175d9d4f65e0f9c189fa7c84bafd88965eb231ba5b072 |
|
MD5 | 138152ac020419c12ef830e3948126b4 |
|
BLAKE2b-256 | 4228f023590b5d0847182836750ed5c8fa15e8a1d88116186d0e0aae38e8947c |