Skip to main content

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

Metadata

Release files for configurenv 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for configurenv 1.0.0
File Size Uploaded Provenance Actions
configurenv-1.0.0.tar.gz 8.9 kB Without provenance Details for configurenv-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for configurenv 1.0.0
File Interpreter ABI Platform Actions
configurenv-1.0.0-py3-none-any.whl Python 3 none any Details for configurenv-1.0.0-py3-none-any.whl

Total release size: 17.2 kB

Release files / configurenv-1.0.0.tar.gz

Download URL configurenv-1.0.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
eef7cbd5a423d5b3024d445bde82be4d1af7ada762bb121ffc8b43b1da9ddbad
BLAKE2b-256 checksum
How to use checksums
4f4b6d82a18779a40cf83d107ef944d199557da7cb07f166143ce9b10e3b25db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release files / configurenv-1.0.0-py3-none-any.whl

Download URL configurenv-1.0.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24e1a35143e5e14dc634af016fa05f49ba2f31a5686f6937d1ae9d077815d73c
BLAKE2b-256 checksum
How to use checksums
6fd97518cb2022c86c2b31ba7259f96c370ee4f53454f62ce89f16045d9d01d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Security for configurenv 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page