Skip to main content

Application configuration tool from the BAT project

Project description

Logo

BatConf

Configuration Management for Python projects, modules, applications, and microservices.

Stable Version Downloads Build Status Documentation Status

Python 3.9 Python 3.10 Python 3.11 Python 3.12 Python 3.13

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.

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).

Professional Support

Tidelift Logo Professionally supported BatConf is now available.

Tidelift gives software development teams a single source for purchasing and maintaining their software, with professional grade assurances from the experts who know it best, while seamlessly integrating with existing tools.

Get supported BatConf with the Tidelift subscription

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


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
        ),
    ]

    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

Install the core package:

pip install .

Install with Yaml support:

pip install .[yaml]

Install with Toml support, for python<=3.11:

pip install .[toml]

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 --group=dev -e .

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

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

batconf-0.2.0.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

batconf-0.2.0-py3-none-any.whl (36.6 kB view details)

Uploaded Python 3

File details

Details for the file batconf-0.2.0.tar.gz.

File metadata

  • Download URL: batconf-0.2.0.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.8.0-62-generic

File hashes

Hashes for batconf-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1c5625641c0ebf180ca1504356d2898112bd279664a6c3acd7f921520bcaa7c4
MD5 d2504ee04222e9747da468d77c0fe325
BLAKE2b-256 1495ad7cc1c6139166f0cf9e64646e2f4a413745673a6d29afa85e605c429a0a

See more details on using hashes here.

File details

Details for the file batconf-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: batconf-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 36.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.8.0-62-generic

File hashes

Hashes for batconf-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc1a09937292275233f74681e7fdd5db2f2e89a38e90c459bc68125ba0c44fcb
MD5 4620ceb46c3eef1b4c1d4cd7b8ceedcd
BLAKE2b-256 b03c767b40ff316d769a87989771edd0b430e029f95348996c7ba79f947f26c3

See more details on using hashes here.

Supported by

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