Skip to main content

Configuration from Environment embedded in yaml.

Project description

Overview

Code style: black

Release

Test

Keep secrets out of env variables in production by using env files. Merge env files into configuration dynamically. Keep env file and env variable handling out of the application by making application dependent only on the configuration file. Prefer deserilization from yaml over configuration of partially initialized objects.

An argument parser that accepts:

  • A required yaml file for configuration/deserialization.
  • An optional env file for secrets.

Features:

  • MIT license
  • Interpolate environment variables directly into yaml configuration.
  • Optional replacement of environment variables with an environment variable file.
  • Use C Yaml safe load/dump or yaml safe load/dump.
  • Pass in env to parser with os.environ as a default.
  • Pass in argv to parser with sys.argv[1:] as a default.
  • Yaml type registration functions.

Relative configargparse, python-dotenv, envyaml, and yamlenv:

  • Dependency injection through depth-first deserialization of yaml is better than two-pass, breadth-first initialization followed by a configuration.
  • Contract for env variables is between configuration file and env xor the env file, the app no longer cares much about env or secrets as it uses the interpolated configuration file.
  • No ${MY_VAR:my-default} --unexpected env var syntax for default values, an expensive pattern match, and allows typos of MY_VAR to pass silently--.
  • No "N/A" or null default when environment variable does not exist --allows configuration errors to pass silently to become runtime errors--.
  • Env file is optional, but when provided it does not merge with existing environment variables --better tracability in production deployment--.
  • Yaml type registration retains the registered yaml tag in a closure.
  • Env yaml type registration retains the registered env variable set in a closure.

Install

pip install "."

Develop, Lint & Test

Setup virtual environment:

python3.10 -m venv .venv

Or setup homebrew environment:

brew install python@3.10
/opt/homebrew/Cellar/python@3.10/.../Frameworks/Python.framework/Versions/Current/python@3.10 -m venv .venv

Once virtual environment is setup:

. .venv/bin/activate
pip install -U pip setuptools wheel
pip install -e ".[dev]"
pre-commit install

Session:

. .venv/bin/activate
...
pytest
...
pre-coommit run --all-files
...
git commit -m 'Message'
...
deactivate

Docker, Lint & Test

docker compose up test
docker compose up pre-commit
docker compose up build-wheel && docker compose up install-wheel
...
docker compose down

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

cfgenvy-2.2.1-py39.py310.py311.py312-none-any.whl (6.8 kB view details)

Uploaded Python 3.10 Python 3.11 Python 3.12 Python 3.9

File details

Details for the file cfgenvy-2.2.1-py39.py310.py311.py312-none-any.whl.

File metadata

File hashes

Hashes for cfgenvy-2.2.1-py39.py310.py311.py312-none-any.whl
Algorithm Hash digest
SHA256 c8a29e85a2a5bcdba9bd1dab21984831a8590240e39a538f948cc26a95bd1656
MD5 c12a9a7fc9363dc186163b6a002e587d
BLAKE2b-256 17fcf995328fefa24527eab37ca53f7f61b9e6f2aa8d774f443b5e737e4256ca

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