Cascade settings from multiple levels of specificity
Project description
Intro
One of the most common ways to let users customize the way an app works is to use config files. This means that many projects wind up including an implementation to read in the config values, specify defaults, control which values get looked up when, and enforce some sort of schema.
settingscascade is designed to handle this scenario. While it can be used in simple situations, it really shines when you need to pull in values from a variety of sources, have a rich set of defaults, and give users flexibility in configuring overrides at various levels. The model it uses is CSS, mimicking the way that css uses selectors to cascade settings from various levels of specificity. Your users specify rule blocks the same as they would in CSS-
# Each rule block has a selector, using CSS semantics
# this block is for a task element with the class "default"
task.default:
command: "echo hello"
on_complete: "echo world"
# You can specify top level settings as well for a final
# level of fallback
project_name: "my project"
Then your app can use the config
# Task represents an element (like a div or a in HTML).
# you can specify what values are valid for this element type
class Task(SettingsSchema):
_name_ = task
command: str
on_complete: str
config = SettingsManager(yaml.load("config.yml"), [Task])
# In your code, you can pull an element from the settingsmanager
# object and find the rules that apply. This is like an element
# <task class="default"></task>
task_config = config.task(class="default")
run_task(
command=task_config.command,
on_complete=task_config.on_complete,
name=config.project_name,
)
Read the full documentation at https://settingscascade.readthedocs.io/en/latest/
Installation
You can install settingscascade from pypi-
pip install settingscascade
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file settingscascade-0.5.0.tar.gz
.
File metadata
- Download URL: settingscascade-0.5.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.8.3 Linux/4.19.78-coreos
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1931eb3ff7f8cfee409f783e4d79a59bcf6aa67cd0aa62604e1c6eed82f42e80 |
|
MD5 | 90f932af143869c05dfe0a8aef9b7a94 |
|
BLAKE2b-256 | 80cdfb28c13aca93ab0d4acf3df2b00ea5688d649ab6c9734d59a2355e1af1db |
File details
Details for the file settingscascade-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: settingscascade-0.5.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.8.3 Linux/4.19.78-coreos
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72cd982d8cacbac2d3192051b4a3a07958000ae4a38fd9e0e3898aec2877038a |
|
MD5 | de31535d7fc3c1fc4a62389bdf6d54db |
|
BLAKE2b-256 | d1473868f13ddff69e97dfd007a76119ce988d719ddb98a55c439a36eb4402fd |