config-forge


Nameconfig-forge JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryUtilities for generating dictionary based parameter sets
upload_time2025-07-21 02:09:01
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```bash
pip install config-forge
```

## Quick example

```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "config-forge",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/5e/6f/64c4725f05eb0bb047ec510d7768f90abe00cd5857425ba56cf582a478db/config_forge-0.1.0.tar.gz",
    "platform": null,
    "description": "# config-forge\r\n\r\nUtilities 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.\r\n\r\n## Installation\r\n\r\n```bash\r\npip install config-forge\r\n```\r\n\r\n## Quick example\r\n\r\n```python\r\nimport config_forge as cforge\r\n\r\n# optionally change the separator used for generated names\r\ncforge.set_name_separator(\"__\")  # or use `name_separator(\"__\")` as a context manager\r\n\r\nbase = cforge.Single(\"foo\", {\"a\": 10, \"b\": {\"c\": 20, \"d\": 30}, \"c\": \"qux\"})\r\n\r\ncfgs = (\r\n    base.patch(**{f\"b_c_{i}\": {\"b\": {\"c\": i}} for i in range(0, 10)}).patch(\r\n        **{f\"c_{s}\": {\"c\": s} for s in [\"x\", \"y\", \"z\"]}\r\n    )\r\n    | base.patch(**{f\"c_{s}\": {\"c\": s} for s in [\"bar\", \"baz\"]})\r\n    | base.patch(aaa={\"b\": cforge.Replace({\"x\": 30})})\r\n)\r\n\r\n\r\nfor name, cfg in cfgs:\r\n    print(name, cfg)\r\n```\r\n\r\nThe above script prints names composed from each patch along with the resulting dictionaries. The output begins like this:\r\n\r\n```\r\nfoo__b_c_0__c_x {'a': 10, 'b': {'c': 0, 'd': 30}, 'c': 'x'}\r\nfoo__b_c_0__c_y {'a': 10, 'b': {'c': 0, 'd': 30}, 'c': 'y'}\r\nfoo__b_c_0__c_z {'a': 10, 'b': {'c': 0, 'd': 30}, 'c': 'z'}\r\nfoo__b_c_1__c_x {'a': 10, 'b': {'c': 1, 'd': 30}, 'c': 'x'}\r\nfoo__b_c_1__c_y {'a': 10, 'b': {'c': 1, 'd': 30}, 'c': 'y'}\r\n...\r\nfoo__c_baz {'a': 10, 'b': {'c': 20, 'd': 30}, 'c': 'baz'}\r\nfoo__aaa {'a': 10, 'b': {'x': 30}, 'c': 'qux'}\r\n```\r\n\r\nSee `examples/example.py` for a full demonstration.\r\n\r\n## Concepts\r\n\r\n### Building configuration sets\r\n\r\n- **Single** \u2013 wrap a single base configuration.\r\n- **Patch** \u2013 apply dictionary patches to each configuration in a set.\r\n- **Union** \u2013 combine multiple configuration sets into one.\r\n\r\n### Merge helpers\r\n\r\n- **Replace** \u2013 fully replace a sub-dictionary when merging.\r\n- **Remove** \u2013 remove a key entirely during merging.\r\n\r\n### Transformations\r\n\r\n- **map** \u2013 transform each `(name, config)` pair in a set.\r\n- **filter** \u2013 drop pairs that don't satisfy a predicate.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License.\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Utilities for generating dictionary based parameter sets",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/5hun/config-forge"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1d8b1c941f674aa15fc685389c6523574daff511c969cd4b426e9878b590605e",
                "md5": "bb515a74287dac222e052e14a0a9e114",
                "sha256": "9fc678186a9de08b9c9ec3c22bdabe025903557ec22c0ff7caef960593522a45"
            },
            "downloads": -1,
            "filename": "config_forge-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bb515a74287dac222e052e14a0a9e114",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 4804,
            "upload_time": "2025-07-21T02:08:59",
            "upload_time_iso_8601": "2025-07-21T02:08:59.777864Z",
            "url": "https://files.pythonhosted.org/packages/1d/8b/1c941f674aa15fc685389c6523574daff511c969cd4b426e9878b590605e/config_forge-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5e6f64c4725f05eb0bb047ec510d7768f90abe00cd5857425ba56cf582a478db",
                "md5": "20385e9f385d1efc7b0ae9534df36ab3",
                "sha256": "b885a4383e316950724b3461bc743094bda09abc65615bf09ff3a1d2da095505"
            },
            "downloads": -1,
            "filename": "config_forge-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "20385e9f385d1efc7b0ae9534df36ab3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 5338,
            "upload_time": "2025-07-21T02:09:01",
            "upload_time_iso_8601": "2025-07-21T02:09:01.242135Z",
            "url": "https://files.pythonhosted.org/packages/5e/6f/64c4725f05eb0bb047ec510d7768f90abe00cd5857425ba56cf582a478db/config_forge-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-21 02:09:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "5hun",
    "github_project": "config-forge",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "config-forge"
}
        
Elapsed time: 0.58229s