ConfWire
ConfWire is a lightweight Python configuration library that makes application configuration simple, flexible, and Pythonic.
It supports native Python, YAML, and JSON configuration files while providing powerful configuration composition without the heavy dependencies of MMCV.
Installation • Quick Start • Why ConfWire? • Features • Comparison • Examples • API • Docs
Installation
Using pip:
pip install confwire
Using uv:
uv add confwire
ConfWire requires Python 3.10+.
Quick Start
from confwire import Config
cfg = Config.fromfile("config.py")
print(cfg.server.port) # attribute-style access
print(cfg["server"]["port"]) # dict-style access
Why ConfWire?
Most Python projects eventually need more than a single flat config file: different environments, experiment variants, or shared defaults that get overridden in specific cases. Reimplementing this composition and inheritance logic by hand is tedious and error-prone.
ConfWire solves this by providing a small, self-contained Config object that:
- Loads Python, YAML, or JSON files interchangeably
- Merges configs together through
_base_inheritance - Preserves dict-like and attribute-like access (
cfg.server.portandcfg["server"]["port"]both work) - Lets you build actual Python objects straight from configuration data
It is designed to be dropped into any project, not tied to a specific framework or domain.
Features
- Native Python configuration files — write configs as plain
.pyfiles with regular variables and dicts - YAML configuration support — load and dump
.yaml/.ymlfiles - JSON configuration support — load and dump
.jsonfiles - Configuration inheritance — extend one or more base configs with
_base_ - Configuration composition — merge multiple config files into a single, unified config
- Importing configurations from other files — reference and combine configs across your project
- Native Python imports inside configuration files — use real Python code, functions, and imports in
.pyconfigs - Object construction from config — build nested Python objects directly from
"type"-tagged dictionaries, with a built-in blocklist for dangerous types - Simple API — a single
Configclass covers loading, merging, and dumping - Zero unnecessary dependencies — no deep learning frameworks or unrelated tooling required
- Lightweight installation — install in seconds, use in any Python project
- Easy integration — drop it into an existing project without restructuring anything
Comparison with MMCV Config
ConfWire's Config system is heavily inspired by MMCV's configuration module, which is well designed but only available as part of the full MMCV package.
| MMCV Config | ConfWire | |
|---|---|---|
| Config inheritance & composition | ✅ | ✅ |
| Python / YAML / JSON configs | ✅ | ✅ |
| Dict + attribute-style access | ✅ | ✅ |
| Standalone install | ❌ (requires the MMCV ecosystem) | ✅ |
| Dependencies | Large (CUDA/vision-oriented stack) | Minimal, pure-Python |
| Usable outside computer vision projects | Limited | Yes, general purpose |
ConfWire extracts the parts of MMCV's config system that are broadly useful and repackages them as a small, independent library — without requiring MMCV itself.
Configuration Examples
Loading Configurations
Config.fromfile() automatically infers the file format from its extension. Supported formats: .py, .yaml / .yml, and .json.
from confwire import Config
cfg = Config.fromfile("configs/app.py")
cfg = Config.fromfile("configs/app.yaml")
cfg = Config.fromfile("configs/app.json")
You can also inspect and export a loaded config:
cfg.filename # absolute path to the source file
cfg.text # raw text of the config file(s)
cfg.pretty_text # formatted Python-style representation
cfg.dump("out.yaml") # write the config back out, format inferred from extension
Python Configuration Example
config.py:
server = dict(
host="0.0.0.0",
port=8080,
)
database = dict(
driver="postgresql",
pool_size=10,
)
from confwire import Config
cfg = Config.fromfile("config.py")
print(cfg.server.port) # 8080
print(cfg.database.driver) # postgresql
Since these are plain Python files, you can use native Python imports and logic directly inside a config:
import os
log_level = os.environ.get("LOG_LEVEL", "INFO")
logging = dict(
level=log_level,
format="%(asctime)s %(levelname)s %(message)s",
)
YAML Example
config.yaml:
server:
host: 0.0.0.0
port: 8080
database:
driver: postgresql
pool_size: 10
from confwire import Config
cfg = Config.fromfile("config.yaml")
print(cfg.server.port) # 8080
JSON Example
config.json:
{
"server": {
"host": "0.0.0.0",
"port": 8080
},
"database": {
"driver": "postgresql",
"pool_size": 10
}
}
from confwire import Config
cfg = Config.fromfile("config.json")
print(cfg.server.port) # 8080
Configuration Inheritance Example
A config can extend one or more base configs using the reserved _base_ key. Values defined in the child config override matching values from the base config(s).
base.py:
server = dict(
host="0.0.0.0",
port=8080,
)
database = dict(
driver="postgresql",
pool_size=10,
)
production.py:
_base_ = "./base.py"
database = dict(pool_size=50) # overrides only database.pool_size
from confwire import Config
cfg = Config.fromfile("production.py")
print(cfg.server.port) # 8080 (inherited from base.py)
print(cfg.database.pool_size) # 50 (overridden)
_base_ also accepts a list of files, letting you compose a config out of several base files at once:
_base_ = ["./server.py", "./database.yaml", "./logging.json"]
To fully replace a base value instead of merging into it, set _delete_=True on the overriding dict:
database = dict(_delete_=True, driver="sqlite")
API Reference
Config
| Member | Description |
|---|---|
Config.fromfile(filename) |
Load a config from a .py, .yaml/.yml, or .json file, resolving _base_ inheritance. |
Config.fromstring(cfg_str, file_format) |
Build a config from an in-memory string, given its intended file format. |
cfg.filename |
Absolute path of the loaded file. |
cfg.text |
Raw source text of the config (including merged base files). |
cfg.pretty_text |
Formatted, Python-style string representation of the config. |
cfg.dump(file=None) |
Write the config to a file, or return it as a string if no file is given. |
cfg.merge_from_dict(options) |
Merge a flat, dot-separated key/value dict into the config. |
Configs support both attribute access (cfg.server.port) and item access (cfg["server"]["port"]).
confwire.build
| Member | Description |
|---|---|
build_from_config(config_dict, base_package=None, blocked_types=None) |
Build a Python object from a "type"-tagged dict, recursively building any nested dicts that also contain a "type" key. |
build_value(value, base_package=None, blocked_types=None) |
Recursively resolve buildable objects nested inside a value (dict, list, etc.). |
from confwire.build import build_from_config
instance = build_from_config({
"type": "botocore.config.Config",
"region_name": "us-east-1",
})
A default blocklist prevents "type" values that would allow arbitrary code or command execution (e.g. os.system, subprocess.run, eval) from being built.
Documentation
Full documentation, including guides and the complete API reference, is available at confwire.readthedocs.io.
Contributing
Contributions are welcome. To get started:
git clone https://github.com/sri-dhurkesh/confwire.git
cd confwire
uv sync --all-groups
pre-commit install
pytest
Please open an issue to discuss significant changes before submitting a pull request.
License
ConfWire is released under the Apache License 2.0.
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 confwire-1.0.0.tar.gz.
File metadata
- Download URL: confwire-1.0.0.tar.gz
- Upload date:
- Size: 31.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ebc8c1b23f196f7a99bfa3f75b8d63c431d22da9a6d23f19399b816851b8489
|
|
| MD5 |
23f2f53e9e28ef97bfed28d93311b06f
|
|
| BLAKE2b-256 |
17a14fcc917041125655e8c3620697ad2614c1d3f28b4478737a4c158b97435d
|
File details
Details for the file confwire-1.0.0-py3-none-any.whl.
File metadata
- Download URL: confwire-1.0.0-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b48d31dc9963e4227b8b4c20111c6947a636e11c8ec3eea1305e3a355cd4ca68
|
|
| MD5 |
c9c7c44847eccfcb7d88ff03b22436bc
|
|
| BLAKE2b-256 |
c6a37145cbdd86099d61ee4ac887586c003e171be8bab37c3a1bf72e1a5abade
|