Simple config package for Python
  • Python 99.4%
  • Makefile 0.6%
Find a file
Renovate 4753063771
All checks were successful
ci/woodpecker/push/release-prepare Pipeline was successful
ci(deps): update code.bjoernpetersen.net/bjoernpetersen/plugin-release docker tag to v1.3.16
2026-10-30 21:35:57 +00:00
.mise chore(deps): update dependency prek to v0.5.9 2026-10-30 21:24:02 +00:00
.woodpecker ci(deps): update code.bjoernpetersen.net/bjoernpetersen/plugin-release docker tag to v1.3.16 2026-10-30 21:35:57 +00:00
src/bs_config feat: allow passing directory of tomls 2026-09-25 09:41:16 +02:00
tests feat: allow passing directory of tomls 2026-09-25 09:41:16 +02:00
.editorconfig Empty project 2023-09-24 20:53:37 +02:00
.gitignore fix: Ignore all cache folders 2024-06-22 22:16:28 +02:00
.miserc.toml chore: add prek to mise 2026-10-10 17:07:57 +02:00
.pre-commit-config.yaml ci(deps): update pre-commit hook commitizen-tools/commitizen to v4.19.3 2026-10-30 21:35:46 +00:00
CHANGELOG.md bump: release version 5.3.0 2026-10-10 13:46:03 +00:00
Makefile chore: fix typing errors 2025-10-23 19:19:36 +02:00
pyproject.toml chore(deps): update dev dependencies 2026-10-30 21:35:27 +00:00
README.md docs: update readme 2026-01-16 20:20:20 +01:00
renovate.json chore: enable patch python updates 2026-10-10 17:11:11 +02:00
uv.lock chore(deps): update dev dependencies 2026-10-30 21:35:27 +00:00

bs-config

Usage

This package provides an Env class for easy access and validation of configuration values from the environment or TOML files.

Example:

from bs_config import Env

env = Env.load()

# a: int | None (missing or blank values lead to the default None)
a = env.get_int("my-int")

# b: int (you specified a default, so it can't be None)
b = env.get_int("my-iny", default=42)

# c: int (if the value is missing, a ValueError is raised)
c = env.get_int("my-int", required=True)

Nested Values

You can access nested values by either separating keys with a dot, or using a scoped Env instance:

from bs_config import Env

env = Env.load()
a = env.get_int("nested.my-int")

nested_env = env / "nested"
b = nested_env.get_int("my-int")

assert a == b

Key Translation

For environment variables and Dotenv values, keys are translated to SCREAMING_SNAKE_CASE. Nested scopes are translated to a double underscore, so the key nested-section.my-value becomes NESTED_SECTION__MY_VALUE.

Dotenv Support

If you install the package with the dotenv extra (pip install bs-config[dotenv]), you can load the contents of .env files in addition to the environment variables from os.environ:

from bs_config import Env

# Includes values from the .env file (if present)
env = Env.load(include_default_dotenv=True)

# Includes values from the test.env and dev.env files (if present)
env = Env.load(additional_dotenvs=["test", "dev"])

TOML Support

You can also load TOML config files into an Env instance. Note that given paths are allowed to not exist, and dotenv/env values take precedence.

from bs_config import Env
from pathlib import Path

env = Env.load(toml_configs=[Path("/etc/myapp/config.toml")])