typed 12-factor app configuration helper
Project description
basecfg
basecfg
is a Python library designed to simplify and standardize the process of configuring a Python application, particularly a Dockerized application.
Users of this library create a class which inherits from basecfg.BaseCfg
. For each configuration option an app should support, a type-annotated class attribute is defined using a call to opt
.
Once a config class is instantiated it automatically populates the configuration from these sources:
- default values declared in the configuration class
- a JSON config file (such as a Kubernetes ConfigMap)
- a
.env
file (indocker run
envfile format) - environment variables
- docker secrets
- command-line arguments
Example
This file is an excerpt from a more extensive example implementation of the library:
#!/usr/bin/env python3
from typing import Optional
from basecfg import BaseCfg, opt
class ExampleAppConf(BaseCfg):
server_username: str = opt(
default="demoperson",
doc="The username to use on the server",
)
server_password: Optional[str] = opt(
default=None,
doc="The password to use on the server",
redact=True,
)
verbose: bool = opt(
default=False,
doc="whether to log verbosely",
)
batch_size: Optional[int] = opt(
default=None,
doc="how many objects to transfer at a time",
)
Project details
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 basecfg-2.0.0.tar.gz
.
File metadata
- Download URL: basecfg-2.0.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 287e14fc5e2815d5777845239ca2233f1605fd0bec938db530b71f4caed05f50 |
|
MD5 | 8933259964d26db45d777614bc5ddf16 |
|
BLAKE2b-256 | 4a1206fabf9fa688c9aa7b5057b44c6c9d3e0742b8251b5d5bf6544ae17d97a5 |
File details
Details for the file basecfg-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: basecfg-2.0.0-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61cce0ddcc90eed96161b669ba05b731b60ed9e4d81c2ee0d14575950b9d8e26 |
|
MD5 | f3acf90644fd5c5dbecd1f2ade817693 |
|
BLAKE2b-256 | 93591d2ad63cc7e04d76d45a3813d68d27655021f6c4886f6b36b763767300eb |