🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

confighub

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Malware was recently detected in this package.

Affected versions:

7.0.17.0.2

confighub

Lightweight configuration management with layered sources for Python microservices

pipPyPI
Version
7.0.2
Weekly downloads
0
Maintainers
1
Weekly downloads
 

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

Keywords

config configuration management env yaml json toml dotenv layered microservice

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts