Skip to main content

Extensible, secure configuration based on runtime type annotations.

Project description

Configatron

Configatron is a configuration management framework suitable for both application and library code. It separates the abstract configuration definition from the concrete implementation that loads config values, making it easy for configuration consumers (or library developers) to focus on business logic, while nevertheless giving devops (or library users) fine-grained control over config value storage and retrieval, including the ability to annotate fields as Secret.

Getting started

Configatron is available as configatron on pypi, ex via pip install configatron or uv add configatron.

Async support requires anyio, which will be included automatically if you specify the async extra, (ex pip install configatron[async] or uv add configatron[async]).

For more information, check out the documentation!

At a glance

A simple example of library usage of an abstract config class:

from typing import Protocol

from configatron import CfgMeta
from configatron import Secret


class MyLibraryConfig(Protocol, metaclass=CfgMeta):
    host: str
    port: int
    app_secret: Secret[str]


async def my_library_code(server):
    # Alternate spelling: ``config = get_active_cfg(MyLibraryConfig)``
    config = ~MyLibraryConfig

    async with server.bind([f'{config.host}:{config.port}']):
        # Concise inline references are supported
        await server.set_secret((~MyLibraryConfig).app_secret)

And its concrete counterpart in application code:

import anyio
from configatron import CfgField
from configatron import CfgManager
from configatron import CfgSource
from configatron import Configatron
from configatron.prebaked.backends.env_vars import EnvVarBackend
from configatron.prebaked.backends.tomlfile import TomlFileBackend
from dcei import ext_dataclass
from dcei import ext_field
from my_library import MyLibraryConfig
from my_library import my_library_code


@ext_dataclass(Configatron(namespace='my.app'))
class MyConfigImpl(MyLibraryConfig):
    # By default, we'll search all backends for the field name, ex
    # ``host`` and ``port``, respectively
    host: str
    port: int
    # Specifying the source backend is optional; only if you want to limit to
    # a specific (prioritized) list of backends, or have aliases for the field
    # names. By default we'll check all of them, and apply them in
    # precedence order from your CfgManager
    app_secret: str = ext_field(CfgField(
        CfgSource(
            backend='env_vars',
            # The env var backend interprets this as ``MY_APP_COOKIE_SECRET``,
            # using the config class' namespace
            lookup_keys=['COOKIE_SECRET'])))


class MyServerObject:

    # During startup
    def on_app_start(self):
        cfg_manager = CfgManager(
            MyConfigImpl,
            backends={
                'config_file': TomlFileBackend('my_config.toml'),
                'env_vars': EnvVarBackend()})
        cfg_manager.load_once_sync()

        # The loaded config is now available to the application code that
        # requires it
        anyio.run(my_library_code, self)

Note that the same class can be both an abstract config class and its own concrete implementation. For example:

@ext_dataclass(Configatron(namespace='my.app'))
class MyApplicationConfig(metaclass=CfgMeta):
    ...

Runtime type support

Configatron CfgManager objects support a type_coercer parameter to allow for easy integration with runtime type libraries like pydantic.

Custom backends

Defining custom backends is easy:

from typing import Any

from configatron.backends import CfgBackend
from configatron.backends import KeyspaceSummary
from configatron.types import CfgFieldDesc


class SecretsManagerBackend(CfgBackend):
    """A custom config backend that contacts a cloud provider's secrets
    manager.
    """
    ALLOW_SECRET = True
    ALLOW_PLAINTEXT = False

    def load_sync(
            self,
            request: KeyspaceSummary,
            full_keyspace: KeyspaceSummary
            ) -> dict[CfgFieldDesc, Any]:
        """Required to support sync loading, optional for async-only.
        """
        raise NotImplementedError('Your implementation goes here!')

    async def load_async(
            self,
            request: KeyspaceSummary,
            full_keyspace: KeyspaceSummary
            ) -> dict[CfgFieldDesc, Any]:
        """Required to support async loading, optional for sync-only.
        """
        raise NotImplementedError('Your implementation goes here!')

Full documentation

Full docs are available on the corresponding project page on Taev Codespace.

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

configatron-2026.4.7.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

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

configatron-2026.4.7.0-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file configatron-2026.4.7.0.tar.gz.

File metadata

  • Download URL: configatron-2026.4.7.0.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for configatron-2026.4.7.0.tar.gz
Algorithm Hash digest
SHA256 29f01590685a3a49b8ded386a6be0cdb07e151cf2b318fb2312250648c5248f1
MD5 319dfaa3971db98bb6cd52646223ba37
BLAKE2b-256 73c88d56f318f1d0124287bfa03a8010ecc58371b139ec066656e9a1552b5d5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for configatron-2026.4.7.0.tar.gz:

Publisher: on_release-publish_pypi.yaml on taev-tech/configatron

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file configatron-2026.4.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for configatron-2026.4.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22178e30880f2994a32fb022639d86e3a79c8d0ec0c60753766126727a5ef790
MD5 9161ffd8941367aad67a8ff398b3743d
BLAKE2b-256 494616a100d971dbea18c77b57a81f74759e0fb5dd836708336e0d5bdd29adf8

See more details on using hashes here.

Provenance

The following attestation bundles were made for configatron-2026.4.7.0-py3-none-any.whl:

Publisher: on_release-publish_pypi.yaml on taev-tech/configatron

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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