Skip to main content

No project description provided

Project description

configurenv

Utilities for simplifying application configuration

Description

This package provides two functions: envsubst and load_config_from_file.

envsubst was created to allow runtime substitution of environment variables into otherwise static configuration files.

load_config_from_file was created to extend Flask app configuration by reading configuration values from files specified by keys of the shape {NAME}_FILE. After passing those configuration values though envsubst (using the existing configuration as the context environment), it updates the {NAME} key of the original configuration.

Dependencies

Installation

pip install configurenv

Usage

envsubst

With this environment:

SERVER_NAME=test.example.com

Running this Python code:

from configurenv import envsubst

url = envsubst('http://${SERVER_NAME}/endpoint')

Results in url having the value 'http://test.example.com/endpoint'.

load_config_from_file

Typical usage is in the setup phase of a Flask app, after loading the initial config from somewhere else (often from environment variables).

With this environment:

MYAPP_USERNAME=jdoe
MYAPP_COLORMAP_FILE=colors.yml

And this colors.yml file:

danger: red
warning: yellow
alert: orange
info: blue

Running this Python code:

from flask import Flask
from configurenv import load_config_from_files

app = Flask(__name__)
app.config.from_prefixed_env('MYAPP')

load_config_from_files(app.config)

Will result in app.config containing these keys and values:

{
    'USERNAME': 'jdoe',
    'COLORMAP_FILE': 'colors.yml',
    'COLORMAP': {
        'danger': 'red',
        'warning': 'yellow',
        'alert': 'orange',
        'info': 'blue',
    },
}

The colors.yml could also refer to other configuration values.

With this environment:

MYAPP_USERNAME=jdoe
MYAPP_DANGER_COLOR=hotpink
MYAPP_COLORMAP_FILE=colors.yml

And this colors.yml file:

danger: ${DANGER_COLOR}
warning: yellow
alert: orange
info: blue

Running the same Python code as above will result in app.config containing these keys and values:

{
    'USERNAME': 'jdoe',
    'DANGER_COLOR': 'hotpink',
    'COLORMAP_FILE': 'colors.yml',
    'COLORMAP': {
        'danger': 'hotpink',
        'warning': 'yellow',
        'alert': 'orange',
        'info': 'blue',
    },
}

Development Setup

git clone git@github.com:umd-lib/configurenv.git
cd configurenv
pyenv install $(cat .python-version) --skip-existing
python -m venv .venv --prompt "$(basename $PWD)-py$(cat .python-version)"
source .venv/bin/activate
pip install -e .[test]

Testing

Using pytest:

pytest

With test coverage information:

pytest --cov-report=term-missing --cov src

Code Style

Using ruff:

ruff check

History

envsubst originated in the Plastron project of the UMD Libraries; see also plastron.utils.envsubst

load_config_from_files originated in Solrizer project of the UMD Libraries; see also solrizer.web.load_config_from_files

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

configurenv-1.0.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

configurenv-1.0.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file configurenv-1.0.0.tar.gz.

File metadata

  • Download URL: configurenv-1.0.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for configurenv-1.0.0.tar.gz
Algorithm Hash digest
SHA256 eef7cbd5a423d5b3024d445bde82be4d1af7ada762bb121ffc8b43b1da9ddbad
MD5 adeb0735c54e9c6c3fee450303599b8a
BLAKE2b-256 4f4b6d82a18779a40cf83d107ef944d199557da7cb07f166143ce9b10e3b25db

See more details on using hashes here.

File details

Details for the file configurenv-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: configurenv-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for configurenv-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 24e1a35143e5e14dc634af016fa05f49ba2f31a5686f6937d1ae9d077815d73c
MD5 6e0734daa5ed1d02699b8d2caaab2f8c
BLAKE2b-256 6fd97518cb2022c86c2b31ba7259f96c370ee4f53454f62ce89f16045d9d01d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page