Application configuration tool from the BAT project
Project description
BatConf
Configuration Management for Python projects, modules, applications, and microservices.
Compose structured hierarchical configurations from multiple sources. Enable your code to adapt seemlessly to the current context. Allow users in different contexts to use the config source that works best for them.
- Hierarchical priority: CLI > Environment > config file > module defaults
- Provides builtin support for common config sources:
- CLI args
- Environment Variables
- Config File (yaml)
- Config classes with default values
- Easily extendable, add new sources to serve your needs.
- Set reasonable defaults, and override them as needed.
- Designed for 12-factor applications (config via Environment Variables)
Users can create their own config sources
by creating classes that satisfy batconf.source.SourceInterfaceProto
(or subclass batconf.source.SourceInterface
)
The config lookup order is determined by the SourceList
instance,
which can be adjusted to suit your needs.
Example Configuration
- REF: template project example
- tests/example/ contains an example project and tests with documentation.
Most projects can copy this example with minimal modification.
from bat import GlobalConfig
from batconf.manager import Configuration, ConfigProtocol
from batconf.source import SourceList
from batconf.sources.args import CliArgsConfig, Namespace
from batconf.sources.env import EnvConfig
from batconf.sources.file import FileConfig
from batconf.sources.dataclass import DataclassConfig
def get_config(
# Known issue: https://github.com/python/mypy/issues/4536
config_class: ConfigProtocol = GlobalConfig, # type: ignore
cli_args: Namespace = None,
config_file: FileConfig = None,
config_file_name: str = None,
config_env: str = None,
) -> Configuration:
# Build a prioritized config source list
config_sources = [
CliArgsConfig(cli_args) if cli_args else None,
EnvConfig(),
config_file if config_file else FileConfig(
config_file_name, config_env=config_env
),
DataclassConfig(config_class),
]
source_list = SourceList(config_sources)
return Configuration(source_list, config_class)
GlobalConfig and Config classes
the GlobalConfig
class is a python dataclass
, used for namespacing,
and providing a structured configuration tree.
Its attributes should be other Config dataclasses for sub-modules.
from dataclasses import dataclass
from .example import Config
@dataclass
class GlobalConfig:
# example module with configuration dataclass
example: Config
Install Instructions
pip install .
Install with Poetry
install poetry >= 1.1.13
poetry install
Manual install
install the dev dependencies listed in pyproject.toml
Dev Guide
Install dev dependencies (pytest, mypy, etc)
pip install -e .[dev]
macos/zsh:
pip install -e ".[dev]"
Design Principles
- Non-Intrusive Integration: BatConf can be seamlessly incorporated
into existing projects with minimal code modifications.
- imports from batconf can be isolated to a single source file
- Config classes utilize stdlib dataclasses
- Portability and Modularity: Modules (sub-modules or entire projects) that use batconf configuration
should be easy to compose and refactor.
- modules can be easily plugged in to other modules.
- modules can be easily factored out (into new projects).
Security contact information
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
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 batconf-0.1.8.tar.gz
.
File metadata
- Download URL: batconf-0.1.8.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-44-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eac591d4fd8da52862e3ffa952bb81e993969c64d999e8391ed99817234b8906 |
|
MD5 | b4bafed26e0bc2b8fc422722ff67cd84 |
|
BLAKE2b-256 | b2ef8fef1c78b4d86179807c6a3c16559b56a9957fac6ba7d7edd0af789a16fb |
File details
Details for the file batconf-0.1.8-py3-none-any.whl
.
File metadata
- Download URL: batconf-0.1.8-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-44-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1544292faf6e75d57518d1756f058ba38cd99aa515b7bcf3733cf06e4ea837c |
|
MD5 | 75aab76c17bc6fe47d15c9f2c5552fad |
|
BLAKE2b-256 | 11bacb760a9d726efe97d3b15da56eaf3b5eb451a8d577997f06fa1b9b06dda8 |