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.
Field Types
Configuration fields may use the following types:
type Primitive = bool | int | float | str | _enum.Enum
type FieldValue = (
Primitive
| set[Primitive]
| list[Primitive]
| tuple[Primitive, ...]
)
class Mode(Enum):
DEV = "dev"
PROD = "prod"
class Config:
NAME: str
PORT: int
MODE: Mode
WORDS: list[str]
NUMBERS: tuple[int, ...] # variable-lenght, fixed type
VECTOR: tuple[float, float, float] # fixed-lenght
MIX: tuple[str, int, bool] # fixed-length, mixed types
Note: Type unions or optional fields are not supported
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,FalseorNone.
Note: A validator fails only if it returns
Falseor 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
tuplewith one value per fieldseries=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.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bean_config-0.2.2.tar.gz | 12.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bean_config-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.2 kB
Release files / bean_config-0.2.2.tar.gz
| Download URL | bean_config-0.2.2.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e5348315bcaf06e732d3a1aac4434a3299c17208a6273ed7ec15465be2cce70a
|
|
BLAKE2b-256 checksum How to use checksums |
6d3a33fcda3d70930f344ddeabb910a604411d2698257f479dd6383dbd310e1b
|
| 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 logRelease files / bean_config-0.2.2-py3-none-any.whl
| Download URL | bean_config-0.2.2-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b18261935f8289bccec67b41dd8f4ad7782f446c8702dac365ed6a48a5c1b459
|
|
BLAKE2b-256 checksum How to use checksums |
5cb2050015d824bb3f7da7ed8feb4a8baa282eb2ebefb4470436a28eb4685732
|
| 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