Yet Another Configuration and Registration System
Project description
YACRS: Yet Another Configuration and Registration System
YACRS is a lightweight Python configuration system that maps configuration values directly to class or function arguments. It is inspired by YACS but adds a decorator-based registration and binding mechanism so you can wire configs to existing code without writing boilerplate mapping logic.
Philosophy
Get rid of the configuration value mapping in code blocks.
Features
- Hierarchical config nodes —
Nodeextendsdictand supports dotted-key access (e.g.cfg.model.lr). - Auto-vivification — Nested paths are created on demand.
- Immutable snapshots — Freeze a config tree to prevent accidental changes.
- Decorator-based binding —
@registermaps config values to function/class__init__arguments. - Scope binding — Bind the same class/function to different config scopes.
- CLI support — Load JSON/YAML/TOML configs and override values from the command line.
Installation
pip install yacrs
Or install from source:
git clone https://github.com/Cowhisper/yacrs.git
cd yacrs
pip install -e .
Quick Start
from yacrs import _C, register
# 1. Register a class with a config scope
@register('model')
class Model:
def __init__(self, input_channels, output_channels):
self.input_channels = input_channels
self.output_channels = output_channels
# 2. Create config entries
_C.register('model')
_C.model.input_channels = 3
_C.model.output_channels = 32
# 3. Instantiate from config
model = Model()
print(model.input_channels) # 3
print(model.output_channels) # 32
See tutorial.md for a complete walkthrough.
Core Concepts
Node
A Node is a dictionary that supports attribute-style and dotted-key access:
from yacrs import Node
cfg = Node()
cfg.model = Node()
cfg.model.lr = 0.01
cfg.set('model.optimizer', 'Adam')
print(cfg.get('model.lr')) # 0.01
print(cfg.model.optimizer) # Adam
_C — Global Config
_C is the package-wide root Node. It is where @configurable looks up values by default.
@configurable
The configurable decorator registers a class or function and binds its parameters to config values at call time.
from yacrs import _C, register
@register('train')
def train(epoch, lr, model):
print(f'Training {model} for {epoch} epochs at lr={lr}')
_C.register('train')
_C.train.epoch = 10
_C.train.lr = 0.001
_C.train.model = 'resnet50'
train() # Training resnet50 for 10 epochs at lr=0.001
CLI
Use cli(...) to load config files and override values from the command line:
python train.py -c config.yaml train.epoch=20 train.lr=0.01
See tutorial.md for details on CLI usage and config file formats.
License
MIT
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 yacrs-0.1.0.tar.gz.
File metadata
- Download URL: yacrs-0.1.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb85846aeccbab8bc1e559fbdc19a5afe85102c961b7759c5537946fb9ffe139
|
|
| MD5 |
cf522fba49393a0cfc20724f3efc6ea3
|
|
| BLAKE2b-256 |
75acaed0684048fb79f96e2b55559065a62dabf5369dfe5db8982bc3f7b7e9d0
|
File details
Details for the file yacrs-0.1.0-py3-none-any.whl.
File metadata
- Download URL: yacrs-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dd58b6dc7bc8bab0a1d0ef7444f1b5a2a629edfbb6749bed05511d75ee1eb80
|
|
| MD5 |
968217f2e0753d2180f97df236623658
|
|
| BLAKE2b-256 |
10ab94fa09d8be33114159b70c29ffdeebc3766710b4b2dc1f97f955ea195dec
|