Skip to main content

Layered configuration powered by Pydantic

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pychu-1.0.1-py3-none-any.whl (8.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page