A python package for reading configurations from different sources
Project description
bubbleconf
A tiny, battery-included configuration helper for Python projects. Use a dataclass to declare your configuration, then populate it from command-line arguments, environment variables, and sensible defaults with predictable priority.
Installation
pip install bubbleconf
Or, for development from this repository:
# from the repo root
python -m pip install --upgrade pip
python -m pip install --upgrade uv
uv sync
Hello example (programmatic)
@config
@dataclass
class MyConfig:
version: str
is_cool: bool = False
number_of_things: int = 0
ratio: float = 1.0
def main():
cfg = parse_config(MyConfig)
print(cfg)
if __name__ == '__main__':
main()
You can set values by environment variables (MYCONFIG_VERSION, MYCONFIG_IS_COOL, ...), by CLI flags, or by defaults in the dataclass. The parser chooses values in a predictable priority order.
CLI example (using the included example/ project)
From the repository root you can run:
uv run example/main.py --is_cool=1 --version=0.1.1 --number_of_things=42 --ratio=0.1337
This will print a populated MyConfig instance.
Advanced usage
- Boolean flags accept
0/1,true/false, and common truthy/falsy strings. - Unknown or invalid values raise a
ConfigErrorwith an easy-to-read message (TTY-aware when printed in terminals).
Contributing
PRs are welcome. The project uses uv to manage the local environment. Run tests with:
uv run pytest -q
If you change packaging metadata, the CI workflow .github/workflows/publish.yml will build and either publish a dev build to TestPyPI or (for tagged commits) publish to PyPI.
License
This project is MIT-licensed. See the LICENSE file for details.
If you'd like the README adjusted (add badges, expand examples, or include API docs), tell me what to include and I'll update it.
Combined sources example (JSON + env + CLI)
This example shows how bubbleconf composes multiple sources. The priority is: CLI flags override environment variables, which override values loaded from a JSON file. Defaults in the dataclass apply if a value is not provided from any source.
- Create a JSON file
config.json(example):
{
"host": "json.local",
"port": 8080,
"retries": 3,
"mode": "safe"
}
- Dataclass declaration (in your script):
from dataclasses import dataclass
from bubbleconf import config, parse_config
@config
@dataclass
class ServiceConfig:
host: str
port: int = 80
retries: int = 1
debug: bool = False
mode: str = "default"
def main():
cfg = parse_config(ServiceConfig, json_file="config.json")
print(cfg)
if __name__ == '__main__':
main()
Note: pass json_file="config.json" (or whatever API your project exposes for loading JSON) — replace with the exact helper call if your project provides a convenience loader.
- Export an environment variable that will override the JSON value (prefix uses the dataclass name):
export PORT=9090
export RETRIES=5
- Run the program with a CLI flag that overrides env and JSON:
uv run example/main.py --host=cli.local --mode=fast
Expected result printed by the program (values annotated):
ServiceConfig(host='cli.local', port=9090, retries=5, debug=False, mode='fast')
Explanation:
host: came from the CLI (cli.local).port: came from the environment (PORT=9090).retries: came from the environment (RETRIES=5) and overrides the JSON value of 3.mode: came from the CLI (fast), overriding the JSON value ofsafe.debug: left at the dataclass defaultFalse(not set in JSON/env/CLI).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bubbleconf-0.1.2.tar.gz.
File metadata
- Download URL: bubbleconf-0.1.2.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26de4a33ed85c14e30a6bf4e87dd274408a5cb28ff401049246b874ea74bd64f
|
|
| MD5 |
2f60f0475f3a39b82656f1e69577bf7e
|
|
| BLAKE2b-256 |
5d190775e0a557cb0eeebf4f0472e02dd73df65baeec2246dd824819ac2d531e
|
Provenance
The following attestation bundles were made for bubbleconf-0.1.2.tar.gz:
Publisher:
publish.yml on bubbleconf/bubbleconf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bubbleconf-0.1.2.tar.gz -
Subject digest:
26de4a33ed85c14e30a6bf4e87dd274408a5cb28ff401049246b874ea74bd64f - Sigstore transparency entry: 425243362
- Sigstore integration time:
-
Permalink:
bubbleconf/bubbleconf@aaa6b3edff37e3fed25dd7d633c074ed981353c2 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/bubbleconf
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@aaa6b3edff37e3fed25dd7d633c074ed981353c2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bubbleconf-0.1.2-py3-none-any.whl.
File metadata
- Download URL: bubbleconf-0.1.2-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04368f3fc0a42289698ed1d136990529d8cf95525a4eaa9fad1027d16011760f
|
|
| MD5 |
27ad1a7ea5c326d36501ff6e00401f56
|
|
| BLAKE2b-256 |
32dfce271761c7128be317a9d7f9ff414a38aec6255406104e7a05db16e3528e
|
Provenance
The following attestation bundles were made for bubbleconf-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on bubbleconf/bubbleconf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bubbleconf-0.1.2-py3-none-any.whl -
Subject digest:
04368f3fc0a42289698ed1d136990529d8cf95525a4eaa9fad1027d16011760f - Sigstore transparency entry: 425243380
- Sigstore integration time:
-
Permalink:
bubbleconf/bubbleconf@aaa6b3edff37e3fed25dd7d633c074ed981353c2 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/bubbleconf
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@aaa6b3edff37e3fed25dd7d633c074ed981353c2 -
Trigger Event:
push
-
Statement type: