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)``
    # (don't forget to import ``configatron.manager.get_active_cfg``)
    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.23.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.23.0-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: configatron-2026.4.23.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.23.0.tar.gz
Algorithm Hash digest
SHA256 391baa94c4b5010434617a407d6398082c87e7cb2159be1a95c28096371f83d7
MD5 9a2cb577aa1c7d9b561dd10b2f3fd38c
BLAKE2b-256 6e4017276798b1bbfd4f5f9cd5428ebb4a88b6a7987ca2f3270e3bf0f845e5a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for configatron-2026.4.23.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.23.0-py3-none-any.whl.

File metadata

File hashes

Hashes for configatron-2026.4.23.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e1c6f5bf059480f2f2ac52ff24e4911b1f941cdabc12f381a66cfd391666b699
MD5 e941b52e6d4c0187d19ed2fba45e8ab2
BLAKE2b-256 56995998c978176c94cbee1706703e24cd360e28db35792ed463d876ddf3de79

See more details on using hashes here.

Provenance

The following attestation bundles were made for configatron-2026.4.23.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