Skip to main content

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 ConfigError with 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.

  1. Create a JSON file config.json (example):
{
  "host": "json.local",
  "port": 8080,
  "retries": 3,
  "mode": "safe"
}
  1. 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.

  1. Export an environment variable that will override the JSON value (prefix uses the dataclass name):
export PORT=9090
export RETRIES=5
  1. 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 of safe.
  • debug: left at the dataclass default False (not set in JSON/env/CLI).

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

bubbleconf-0.1.3.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bubbleconf-0.1.3-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file bubbleconf-0.1.3.tar.gz.

File metadata

  • Download URL: bubbleconf-0.1.3.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

Hashes for bubbleconf-0.1.3.tar.gz
Algorithm Hash digest
SHA256 abbafe4b8c891c18f0a19e47dbbd9142f75161250062da3320daa58c36a8d904
MD5 cd6a53e8e1e9c54222a169f9fd63579b
BLAKE2b-256 71a8c285ee4f4c7bd9e41b87a3b0aa55966971444f6ff3bc03ced01cc62daed5

See more details on using hashes here.

Provenance

The following attestation bundles were made for bubbleconf-0.1.3.tar.gz:

Publisher: publish.yml on bubbleconf/bubbleconf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bubbleconf-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: bubbleconf-0.1.3-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

Hashes for bubbleconf-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 48a2757e249bafb2e02345a9c700710c650082db6837dd4c0965bc76e98ebd92
MD5 cc163ae66d187654ff0e51dba7beb83f
BLAKE2b-256 48a69b31bd26c85a4608a667bf603690b602c0d86849b0a6e2f0b9e1262405f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for bubbleconf-0.1.3-py3-none-any.whl:

Publisher: publish.yml on bubbleconf/bubbleconf

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