A Python configuration library that turns YAML, JSON, and TOML files into Python objects
Project description
ReausoConfig
A Python configuration library that turns YAML, JSON, and TOML files into Python objects with minimal runtime coupling.
ReausoConfig loads configuration files and instantiates fully-connected object graphs by calling actual class constructors. Your application code doesn't need to know about ReausoConfig — only the startup/registration code does. After instantiation, you get pure Python objects with no framework dependency.
Key Features
- Minimal coupling — Your application code never imports rconfig; only startup code does
- Object-oriented instantiation — Config files describe object graphs, not just data
- Multiple formats — YAML, JSON, and TOML with automatic format detection
- Config composition — Split configs across files with
_ref_references and deep merge - Type-driven resolution — Automatic target inference from type hints
- Interpolation —
${...}expressions with environment variables, math, and conditionals - Lazy instantiation — Defer object creation until first access
- Provenance tracking — Know where every config value came from
- Config diffing — Compare configurations programmatically
- CLI overrides — Override any config value from the command line
- Multirun support — Generate config combinations for parameter sweeps
- Lifecycle hooks — React to config loading, instantiation, and errors
Installation
pip install git+https://github.com/reauso/ReausoConfig.git
Development Setup
pixi install
pixi run test
Quick Start
1. Define your classes
Your classes have no dependency on ReausoConfig — use dataclasses, regular classes, or any callable:
from dataclasses import dataclass
@dataclass
class Database:
host: str
port: int
@dataclass
class Service:
name: str
db: Database # Nested object
2. Create a config file
The _target_ key maps a config block to a registered class name. Nested blocks with _target_ become nested object instances:
# service.yaml
_target_: service
name: "api"
db:
_target_: database
host: "localhost"
port: 5432
3. Register and instantiate
import rconfig as rc
rc.register(name="database", target=Database)
rc.register(name="service", target=Service)
# One call creates the entire object graph
service = rc.instantiate(path="service.yaml")
assert isinstance(service, Service)
assert isinstance(service.db, Database)
assert service.db.host == "localhost"
The result is Service(name="api", db=Database(host="localhost", port=5432)) — pure Python objects with no framework dependency.
Config Composition
Split configuration across files and compose them with _ref_:
# models/resnet.yaml
_target_: model
hidden_size: 256
dropout: 0.1
# trainer.yaml
_target_: trainer
model:
_ref_: models/resnet # Load from file (format auto-detected)
dropout: 0.2 # Override: merged on top
epochs: 10
Overrides are deep-merged — dict values merge recursively, scalars and lists are replaced.
Supported Formats
ReausoConfig works with YAML, JSON, and TOML. The loader is selected automatically from the file extension:
model = rc.instantiate(path="config.yaml")
model = rc.instantiate(path="config.json")
model = rc.instantiate(path="config.toml")
You can mix formats with _ref_ — a YAML config can reference a JSON or TOML file and vice versa.
Interpolation
Use ${...} expressions for dynamic values:
_target_: training
data_dir: ${env:DATA_DIR, ./data} # Environment variable with default
batch_size: 32
total_samples: ${= 1000 * 32} # Math expressions
output: ${data_dir}/results # Reference other fields
gpu: ${if:${env:USE_GPU, false}, cuda:0, cpu} # Conditionals
CLI Overrides
Override any config value from the command line without modifying files:
service = rc.instantiate(path="service.yaml", cli_args=["db.port=3306", "name=prod"])
Type-Driven Polymorphism
Type hints enable runtime substitution of implementations:
from abc import ABC, abstractmethod
class Optimizer(ABC):
@abstractmethod
def step(self): pass
class Adam(Optimizer):
def __init__(self, lr: float):
self.lr = lr
def step(self): pass
@dataclass
class Trainer:
optimizer: Optimizer # Accepts any registered Optimizer subclass
rc.register(name="adam", target=Adam)
rc.register(name="trainer", target=Trainer)
_target_: trainer
optimizer:
_target_: adam # Switch implementations by changing this value
lr: 0.001
Documentation
Full documentation is available at reauso.github.io/ReausoConfig, including:
- Getting Started — Full installation and walkthrough
- Core Concepts — ConfigStore, validation, resolution pipeline
- Config Composition —
_ref_,_instance_, deep merge, CLI overrides - API Reference — Complete function and type reference
License
MIT License — see LICENSE for details.
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 reausoconfig-0.1.0.tar.gz.
File metadata
- Download URL: reausoconfig-0.1.0.tar.gz
- Upload date:
- Size: 448.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b48f369aa7f69802fd5b5efeae7ad86b84c33ca8f9ba88e63a0f597c5f57f5fe
|
|
| MD5 |
6572a7cc76318ef8ed51e1745edb04d4
|
|
| BLAKE2b-256 |
82a10a9f7c506eb4bb9bc51a487f9602ce0ecec7c70bf5bdc002e78477d19ebb
|
Provenance
The following attestation bundles were made for reausoconfig-0.1.0.tar.gz:
Publisher:
publish.yml on reauso/ReausoConfig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
reausoconfig-0.1.0.tar.gz -
Subject digest:
b48f369aa7f69802fd5b5efeae7ad86b84c33ca8f9ba88e63a0f597c5f57f5fe - Sigstore transparency entry: 849655902
- Sigstore integration time:
-
Permalink:
reauso/ReausoConfig@16c52e3b28aa48d3beb4bc3bc194bf7e99df14de -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/reauso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@16c52e3b28aa48d3beb4bc3bc194bf7e99df14de -
Trigger Event:
release
-
Statement type:
File details
Details for the file reausoconfig-0.1.0-py3-none-any.whl.
File metadata
- Download URL: reausoconfig-0.1.0-py3-none-any.whl
- Upload date:
- Size: 203.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b90164b3ab79a0afed340993cfafffc10d53d19da1f4c93c3fb696d70059bd2a
|
|
| MD5 |
8ac0c5a521ccf2bda9f32d4231126bb7
|
|
| BLAKE2b-256 |
e02f508ddb13c6afad0c9b3d7b11e8e2e6104c6157c2abff33444ebc60be51bd
|
Provenance
The following attestation bundles were made for reausoconfig-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on reauso/ReausoConfig
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
reausoconfig-0.1.0-py3-none-any.whl -
Subject digest:
b90164b3ab79a0afed340993cfafffc10d53d19da1f4c93c3fb696d70059bd2a - Sigstore transparency entry: 849655904
- Sigstore integration time:
-
Permalink:
reauso/ReausoConfig@16c52e3b28aa48d3beb4bc3bc194bf7e99df14de -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/reauso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@16c52e3b28aa48d3beb4bc3bc194bf7e99df14de -
Trigger Event:
release
-
Statement type: