Skip to main content

pychu

pytest pypi license

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

Metadata

Release files for pychu 1.0.1

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

Built distribution (wheel)

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

Release files / pychu-1.0.1-py3-none-any.whl

Download URL pychu-1.0.1-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0358b29831fcb3f7379b13dfe73e4886da4397665bcac51be6954e4c81707db1
BLAKE2b-256 checksum
How to use checksums
0944cb34392b39c607cced25e1ac3eddf61c4ac3cd8055d06e8cb23d46912923
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.0.1 This release

1 release file

1.0.0

1 release file

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