A Springy Little Configuration Reader
Influenced by Spring Boot's YAML configuration features, this library reads system configuration settings from environment variables and YAML files.
Installation
To install using pip:
pip install pyspry
Usage
By default, a file named config.yml in the current directory will be loaded and parsed for
configuration settings. These can be accessed through the pyspry.settings module.
For example, consider the following config.yml file:
DATABASES:
default:
AUTOCOMMIT: true
NAME: db.sqlite3
DEBUG: true
DEFAULT_CHARSET: utf-8
These configuration settings can be accessed as follows:
>>> from pyspry import settings
>>> settings.DEBUG
True
>>> settings.DEFAULT_CHARSET
'utf-8'
Specifying Alternate Config Files
Set the environment variable PYSPRY_CONFIG_PATH to override the default path to the configuration
file:
>>> import os; os.environ["PYSPRY_CONFIG_PATH"]
'sample-config.yml'
>>> from pyspry import settings
>>> settings.PYSPRY_STATICFILES_FINDERS
['django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder']
Variable Prefixes
Set the environment variable PYSPRY_VAR_PREFIX to filter which settings are loaded:
>>> import os; os.environ["PYSPRY_VAR_PREFIX"]
'PYSPRY'
>>> from pyspry import settings
>>> "TEST_RUNNER" in settings # the prefix is automatically inserted
True
>>> "IGNORED_SETTING" in settings # see the last line in 'sample-config.yml'
False
Nested Structures
If the configuration includes nested data structures, each layer of nesting can be traversed using
_-separated names:
>>> settings.LOGGING["version"] == settings.LOGGING_version == 1
True
>>> settings.LOGGING["loggers"]["pyspry"]["level"] == \
... settings.LOGGING_loggers_pyspry_level == 'DEBUG'
True
Environment Variables
In many cases, it can be useful to set one-off overrides for a setting. This can be done with an environment variable:
>>> import importlib, os
>>> settings.LOGGING_loggers_pyspry_level
'DEBUG'
>>> os.environ["PYSPRY_LOGGING_loggers_pyspry_level"] = "INFO"
>>> settings = importlib.reload(settings)
>>> settings.LOGGING["loggers"]["pyspry"]["level"]
'INFO'
Django Integration
This package was originally designed for use with the Django framework. To use it:
# after installing the package, specify it as the settings module
export DJANGO_SETTINGS_MODULE=pyspry.settings
django-admin diffsettings
Development
The following system dependencies are required:
poetrypre-commit- (optional)
direnv - (optional)
docker
Common development commands are managed by poethepoet; run
poe --help for an up-to-date list of commands:
Poe the Poet - A task runner that works well with poetry.
version 0.20.0
USAGE
poe [-h] [-v | -q] [--root PATH] [--ansi | --no-ansi] task [task arguments]
GLOBAL OPTIONS
-h, --help Show this help page and exit
--version Print the version and exit
-v, --verbose Increase command output (repeatable)
-q, --quiet Decrease command output (repeatable)
-d, --dry-run Print the task contents but don't actually run it
--root PATH Specify where to find the pyproject.toml
--ansi Force enable ANSI output
--no-ansi Force disable ANSI output
CONFIGURED TASKS
setup-versioning Install the 'poetry-dynamic-versioning' plugin to the local 'poetry' installation
docs Generate this package's docs
docserver Use 'pdoc' to launch an HTTP server for this package's docs
lab Run Jupyter Lab
lint Lint this package
test Test this package and report coverage
Reports
Metadata
Release files for pyspry 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyspry-1.0.2.tar.gz | 23.8 kB | Without provenance | Details for pyspry-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyspry-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for pyspry-1.0.2-py3-none-any.whl |
Total release size: 39.2 kB
Release files / pyspry-1.0.2.tar.gz
| Download URL | pyspry-1.0.2.tar.gz |
|---|---|
| Size | 23.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8afa14f0fce0de1b84227777f2c896b895a1d43fc83936e8ad6b9e52c9cbb21c
|
|
BLAKE2b-256 checksum How to use checksums |
af0555a57d2bb29e5014f655c333235f913c06e678d3d79a031a92c1e1fc05f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.11.5 Linux/5.4.109+
|
Release files / pyspry-1.0.2-py3-none-any.whl
| Download URL | pyspry-1.0.2-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
698feab7f33e945784f3b50bffac2f77fbf8d6f8f85d309101a81c6407693488
|
|
BLAKE2b-256 checksum How to use checksums |
129bef9a318d6313ad427d1ff18a592c8641467ac205892bb4d9d22a7e5e6e51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.11.5 Linux/5.4.109+
|
Security for pyspry 1.0.2
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.