Utilities for generating dictionary based parameter sets
Project description
config-forge
Utilities for generating dictionary based configuration sets. A configuration set is iterable and yields (name, config_dict) pairs. You can patch existing sets and combine them while the library manages name composition.
Installation
pip install config-forge
Quick example
import config_forge as cforge
# optionally change the separator used for generated names
cforge.set_name_separator("__") # or use `name_separator("__")` as a context manager
base = cforge.Single("foo", {"a": 10, "b": {"c": 20, "d": 30}, "c": "qux"})
cfgs = (
base.patch(**{f"b_c_{i}": {"b": {"c": i}} for i in range(0, 10)}).patch(
**{f"c_{s}": {"c": s} for s in ["x", "y", "z"]}
)
| base.patch(**{f"c_{s}": {"c": s} for s in ["bar", "baz"]})
| base.patch(aaa={"b": cforge.Replace({"x": 30})})
)
for name, cfg in cfgs:
print(name, cfg)
The above script prints names composed from each patch along with the resulting dictionaries. The output begins like this:
foo__b_c_0__c_x {'a': 10, 'b': {'c': 0, 'd': 30}, 'c': 'x'}
foo__b_c_0__c_y {'a': 10, 'b': {'c': 0, 'd': 30}, 'c': 'y'}
foo__b_c_0__c_z {'a': 10, 'b': {'c': 0, 'd': 30}, 'c': 'z'}
foo__b_c_1__c_x {'a': 10, 'b': {'c': 1, 'd': 30}, 'c': 'x'}
foo__b_c_1__c_y {'a': 10, 'b': {'c': 1, 'd': 30}, 'c': 'y'}
...
foo__c_baz {'a': 10, 'b': {'c': 20, 'd': 30}, 'c': 'baz'}
foo__aaa {'a': 10, 'b': {'x': 30}, 'c': 'qux'}
See examples/example.py for a full demonstration.
Concepts
Building configuration sets
- Single – wrap a single base configuration.
- Patch – apply dictionary patches to each configuration in a set.
- Union – combine multiple configuration sets into one.
Merge helpers
- Replace – fully replace a sub-dictionary when merging.
- Remove – remove a key entirely during merging.
Transformations
- map – transform each
(name, config)pair in a set. - filter – drop pairs that don't satisfy a predicate.
License
This project is licensed under the MIT License.
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 config_forge-0.1.0.tar.gz.
File metadata
- Download URL: config_forge-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b885a4383e316950724b3461bc743094bda09abc65615bf09ff3a1d2da095505
|
|
| MD5 |
20385e9f385d1efc7b0ae9534df36ab3
|
|
| BLAKE2b-256 |
5e6f64c4725f05eb0bb047ec510d7768f90abe00cd5857425ba56cf582a478db
|
File details
Details for the file config_forge-0.1.0-py3-none-any.whl.
File metadata
- Download URL: config_forge-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fc678186a9de08b9c9ec3c22bdabe025903557ec22c0ff7caef960593522a45
|
|
| MD5 |
bb515a74287dac222e052e14a0a9e114
|
|
| BLAKE2b-256 |
1d8b1c941f674aa15fc685389c6523574daff511c969cd4b426e9878b590605e
|