Layered configuration powered by Pydantic
Project description
pychu
Layered configuration loading built on Pydantic.
With Pychu, you can define your program's configuration as a Pydantic model, then load it from multiple providers. Providers are ordered as levels of layers, thus allowing upper layers to override values from lower layers.
At the moment, the following providers are implemented :
- Program arguments
- Environment variables
- JSON
- TOML (with the
pychu[toml]extension) - YAML (with the
pychu[yaml]extension)
Requirements
Pychu requires Python 3.6+ and Pydantic 1.7.3+.
Installing
Pychu can be installed through pip.
$ pip3 install pychu # Install the basic version
$ pip3 install pychu[yaml] # Install the YAML extension
Example
The following example loads configuration from a JSON file, but also allows overriding using program arguments.
from pydantic import BaseModel
from pychu.args import args
from pychu.json import json
from pychu import load
class RabbitMQ(BaseModel):
host: str
username: str
password: str
port: int = 5671
rabbitmq = load(
target=RabbitMQ,
providers=[
args(),
json("./config.json")
]
)
print(rabbitmq)
$ cat config.json
{"host": "localhost", "port": 5671, "username": "user", "password": "pass"}
$ ./example.py
host='localhost' username='user' password='pass' port=5671
$ ./example.py --port 5672
host='localhost' username='user' password='pass' port=5672
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 Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pychu-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pychu-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.7.0 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0358b29831fcb3f7379b13dfe73e4886da4397665bcac51be6954e4c81707db1
|
|
| MD5 |
e38979f1e641d3d6030076673f95c1f5
|
|
| BLAKE2b-256 |
0944cb34392b39c607cced25e1ac3eddf61c4ac3cd8055d06e8cb23d46912923
|