Skip to main content

bean.config

bean.config is a minimal configuration framework for Python.

Define your configuration as a class and populate it from command-line arguments, environment variables, defaults, overrides, or custom sources.

Just enough to arrange some beans.


Overview

With bean.config you get:

  • Type-safe configuration classes.
  • Automatic loading from multiple built-in or user-defined sources.
  • Configurable source priority.
  • Custom validators and normalizers.
from enum import Enum
from bean import config

class Mode(Enum):
    DEV = "dev"
    PROD = "prod"

@config
class AppConfig:
    DEBUG: bool = False
    MODE: Mode = Mode.DEV
    HOST: str
    PORT: int = 8080

# `AppConfig` is now the loaded configuration instance.
print(config.dump_str(AppConfig))

Note:

To quickly inspect the public API:

python -c "
    import bean.config as bean
    for v in sorted(dir(bean)):
        print(f'- {v}')
"

Installation

Requirements:

  • Python 3.14+

Using pip:

pip install --upgrade bean-config

Using curl (direct download):

curl -Ls \
    https://raw.githubusercontent.com/numen-0/bean/refs/heads/main/bean-config/src/bean/config.py

API

This is a quick reference for the main API.

For full details, see the source code.

Loading

cfg = config.load(
    Config,
    argv=["--host", "localhost"],
)

config.load(
    Config,
    env_prefix="APP",
    overrides={
        "HOST": "localhost",
    },
)

config.load(
    Config,
    priorities=("extra", "defaults"), # only load from extra and then defaults
    extra_sources={
        "extra": foo,                 # foo(field) -> value
    },
)

Built-in sources:

source description
args Command-line arguments (argparse).
envs Environment variables.
defaults Default class attributes.
overrides Explicit values passed via the overrides parameter.

Validators

Validators can raise exceptions or return a boolean signaling success:

class Config:
    NAME: str
    PORT: int

    @config.validator("PORT")
    def port_is_valid(self, port: int) -> bool:
        return 0 < port <= 65535

    @config.validator("NAME")
    def name_is_valid(self, name: str):
      if name == "":
          raise ValueError("Empty NAME")

Note: Validators may return True, False or None.

Note: A validator fails only if it returns False or raises an exception.

Normalizers

Normalizers can be used to finalize the configuration load.

class Config:
    NAME: str
    HOST: str

    @config.normalizer("NAME", "HOST")
    def lowercase(self, name: str, host: str) -> tuple[str, str]:
        return name.lower(), host.lower()

    @config.normalizer("NAME", "HOST", series=True)
    def strip(self, value: str) -> str:
        return value.strip()

    @config.normalizer()
    def normalize(self) -> None:
      ...

Note:

The return value must match the declared fields

  • No fields -> return None
  • One field -> return the normalized value
  • Multiple fields -> return a tuple with one value per field
  • series=True -> the function receives and returns one field at a time

Notes

Validators and normalizers follow the same definition rules:

  • The number of declared fields must match the function parameters.
  • They work with instance methods, @staticmethod, and @classmethod.
  • Execution order is determined by priority, then by function name.

License

All the repo falls under the MIT License.

Metadata

Release files for bean-config 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bean-config 0.2.1
File Size Uploaded
bean_config-0.2.1.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bean-config 0.2.1
File Interpreter ABI Platform
bean_config-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.3 kB

Release files / bean_config-0.2.1.tar.gz

Download URL bean_config-0.2.1.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
49336a44ef4985ad81e3d78d813b44095545a7025c8accfe5cf4f25e92ccc414
BLAKE2b-256 checksum
How to use checksums
259d16b3e68f9d98f4a90e1b5f85ac2642ccb03600ea85450b324b1309d16529
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 12, 2026.

Transparency log

Release files / bean_config-0.2.1-py3-none-any.whl

Download URL bean_config-0.2.1-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
82adfe7aa80b49d8586e038b64d54f63bf97a017b27427c031c65f174ba002f4
BLAKE2b-256 checksum
How to use checksums
51eaa947e0d0b2478bde44bdc27569ebe577ce46ebd965b589d1b42a59b75805
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 12, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.2

2 release files

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release 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