Skip to main content

Lightweight configuration management with layered sources for Python microservices

This project has been quarantined.

PyPI Admins need to review this project before it can be restored. While in quarantine, the project is not installable by clients, and cannot be being modified by its maintainers.

Read more in the project in quarantine help article.

Project description

confighub

Lightweight configuration management with layered sources for Python microservices. Load from JSON, YAML, TOML, INI, .env files with deep merging, interpolation, and change watchers.

Installation

pip install confighub

Usage

from confighub import ConfigManager, load_env, merge_deep, interpolate

# Layer multiple configuration sources
config = ConfigManager({'app': {'name': 'myservice', 'debug': False}})
config.load('config/defaults.json')
config.load('config/local.yaml')
config.from_env({'APP_PORT': 'app.port', 'DB_URL': 'database.url'})

# Access nested values with dot notation
port = config.get('app.port', 8080)
db_url = config.get('database.url')

# Watch for changes
config.watch(lambda data: print('Config updated!'))
config.set('app.debug', True)

# Load .env files
env_vars = load_env('.env', override=False)

# Deep merge configs
merged = merge_deep(base_config, override_config)

# Variable interpolation
template = {'url': 'https://${HOST:-localhost}:${PORT}'}
resolved = interpolate(template, {'HOST': 'prod.example.com', 'PORT': '443'})

Features

  • Layered loading — JSON, YAML, TOML, INI, .env with priority ordering
  • Deep merge — nested dict merging with override semantics
  • Dot notation — access config.get('database.pool.size')
  • Interpolation — ${VAR} and ${VAR:-default} with env fallback
  • Change watchers — callback on config mutations
  • Env mapping — map environment variables to config paths
  • Config diffing — detect changes between versions
  • Thread-safe — all operations are lock-protected

API

ConfigManager

  • ConfigManager(defaults=None) — create manager with optional defaults
  • .load(source, priority=0) — load dict, file path, or env mapping
  • .get(key, default=None) — get value by dot-notation key
  • .set(key, value) — set value
  • .has(key) — check existence
  • .delete(key) — remove key
  • .all() — get full config dict
  • .keys(prefix=None) — list keys
  • .from_env(mapping) — load from environment variables
  • .watch(callback) / .unwatch(callback)

Loaders

  • load_json(path) / save_json(path, data)
  • load_env(path='.env', override=False) / save_env(path, data)
  • load_ini(path) / load_yaml(path) / load_toml(path)

Utilities

  • interpolate(value, context) — variable interpolation
  • merge_deep(base, override) — recursive dict merge
  • freeze(obj) — make hashable (for caching)
  • diff(old, new) — compute config changes

License

MIT

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

confighub-7.0.1.tar.gz (6.2 kB view details)

Uploaded Source

File details

Details for the file confighub-7.0.1.tar.gz.

File metadata

  • Download URL: confighub-7.0.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for confighub-7.0.1.tar.gz
Algorithm Hash digest
SHA256 fc778a667607085889636244626a6b73a062943c061ccd7c2fb1cbfce85f0531
MD5 06aad35c6882ec75783442cd79d574f3
BLAKE2b-256 160d81045952ba87a948114d0a571e7dc4ab5c3806edfbb99dd3dde8c92216f4

See more details on using hashes here.

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