This package can create a config dict from environment variables, performing validations and mappings in the process.
Fork (and an unendorsed spiritual successor) of evarify. This library is NOT a drop-in replacement for evarify.
- This is currently in alpha stage. It may contain bugs and sharp edges.
- The package API is also not stable.
- Simple API with sane defaults that is easy to use.
- Simple Implementation following current industry standard practices.
- Easy to understand, maintain and fork.
- Reasonably performant.
- Eventually, a stable API.
- Extreme performance.
- Support for other configuration formats such as files (
yaml
,.env
etc.) or command-line flags.
With pip:
python3 -m pip install git+https://github.com/npalladium/env-loader.git
With poetry:
poetry add git+https://github.com/npalladium/env-loader.git
Refer 'pip install' From a Git Repository for how this works.
A simple example:
from env_loader import (
EnvironmentVariable,
EnvironmentVariableLoader,
EnvLoaderError,
)
env_definitions = {
"ENV_VAR1": EnvironmentVariable(name="ENV_VAR1"),
"ENV_VAR2": EnvironmentVariable(name="ENV_VAR2_DIFF_NAME"),
"ENV_VAR3": EnvironmentVariable(
name="ENV_VAR3",
is_required=False,
),
"ENV_VAR4": EnvironmentVariable(
name="ENV_VAR3",
default_val="qwertyuiop",
),
}
load_env = EnvironmentVariableLoader(env_definitions)
env_values = load_env() # returns a defaultdict
# If ENV_VAR1 and ENV_VAR2_DIFF_NAME are not present, you will get the following error:
# MissingEnvironmentVariablesError: Missing required environment variables: ['ENV_VAR1', 'ENV_VAR2_DIFF_NAME']
env_var3 = env_values["ENV_VAR3"]
- README
- Usage instructions
- Library philosophy, goals and non-goals
- Documentation
- Tests
- Improve types
- Publish to PyPI
- Portions Copyright Gregory Taylor
- Portions Copyright Nikhil Reddy
- The current library is licensed under the MIT License.
- evarify is licensed under the MIT License.