Skip to main content

Logo

BatConf

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

Stable Version Downloads Build Status Documentation Status Python Tidelift OpenSSF Scorecard

Compose structured hierarchical configurations from multiple sources. Enable your code to adapt seamlessly 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)
  • ConfigSingleton: share a single Configuration instance across your application
  • insert_source: dynamically add configuration sources at runtime
  • Subscript access: cfg['key'] as an alternative to cfg.key, enabling dynamic lookups like cfg.clients[client_id]

Users can create their own config sources by creating classes that satisfy batconf.source.SourceInterfaceP (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).

How BatConf Compares

Tool Layered sources Config object access Validation CLI integration
BatConf CLI / env / files / dataclass defaults dot-path + subscript bring your own (by design) explicit — your app owns its argparse parser
pydantic-settings env / files / secrets / CLI typed model attributes built-in (pydantic) generated parser
environs env vars only none (per-value reads) built-in (marshmallow) none
python-decouple env / .ini / .env none (per-value reads) cast callable only none
Dynaconf many formats + env profiles dot-path + subscript built-in validators management CLI
python-dotenv .env loader only plain dict none none
Hydra / OmegaConf YAML composition + CLI overrides dot-path + subscript opt-in structured configs framework owns argv
configparser (stdlib) INI files subscript (strings) none none

See the full comparison guide for details, access-interface ergonomics, and guidance on choosing a tool.

Professional Support

Tidelift Logo BatConf participates in the Tidelift open source sustainability program. Organizations can support the ongoing maintenance of BatConf while receiving professional assurances through a Tidelift subscription.

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

Check out our Quick Start Guide

and the example project in tests/example/ which includes tests and documentation.

Quick Example

from dataclasses import dataclass
from batconf import (
    ConfigSingleton,
    insert_source,
    Configuration,
    SourceList,
    EnvSource,
    IniSource,
    NamespaceSource,
    Namespace,
)

@dataclass
class AppConfig:
    host: str = 'localhost'
    port: str = '8080'

def get_config() -> Configuration:
    sources = SourceList([EnvSource(), IniSource('config.ini')])
    return Configuration(sources, AppConfig, path='app')

# A shared singleton — import CFG anywhere in your application
CFG = ConfigSingleton(get_config)

# Attribute access
host = CFG.host

# Subscript access — useful for dynamic keys
key = 'host'
host = CFG[key]

# Add a source at runtime (e.g. after CLI args are parsed)
args = Namespace()
setattr(args, 'app.host', 'example.com')
insert_source(cfg=CFG, source=NamespaceSource(args))

Install Instructions

Install the core package:

pip install .

Install with Yaml support:

pip install .[yaml]

Install with Toml support, for python<=3.10:

pip install .[toml]

Adding BatConf to your project requirements

[project]
dependencies = [
    'batconf',
]

Including optional extras, like Yaml:

[project]
dependencies = [
    'batconf[yaml]',
]

Migrating to v0.4.0

Breaking Changes

  • batconf.sources.file.FileConfig has been removed. See the migration guide for details.

Architecture Decision Records

Significant design decisions are documented in docs/decisions/. Start with the foundational ADRs to understand the core philosophy, then read the per-feature groups for decisions made during specific refactors.

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.

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.4.0.tar.gz (254.3 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.4.0-py3-none-any.whl (47.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: batconf-0.4.0.tar.gz
  • Upload date:
  • Size: 254.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.4

File hashes

Hashes for batconf-0.4.0.tar.gz
Algorithm Hash digest
SHA256 32e115817d47c08367f8b95a8910dfa098ab363bfaf9094ba798fc216e526727
MD5 62602a0670642ad092e2ef7a95cfdff1
BLAKE2b-256 e736c39e8779a37988d99d75489443b02fd3ab0222e7e844431449a879b3bde7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: batconf-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 47.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.4

File hashes

Hashes for batconf-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2dd38a0a8bb4742620897b71d0b03506b333a375726856641bd165efe0c4bee6
MD5 53caaaedf0c3242f6e02235f44dc177c
BLAKE2b-256 55ce98da5012f154494a27c053ea6e9a25163abb04585eb4659b8a422bb76a16

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

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