dataconfigs


Namedataconfigs JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/mantasu/dataconfigs
SummaryTurn your dataclasses into configs seamlessly.
upload_time2024-10-28 02:44:52
maintainerNone
docs_urlNone
authorMantas Birškus
requires_python>=3.12
licenseApache
keywords python config configuration configurable
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Dataconfigs

## About

Dataconfigs provides a seamless integration between dataclasses as configs and any configurable classes that use these configs. The most powerful feature is that config attributes become part of configurable, i.e., no need for _explicit_ `.config` attribute (unless specified otherwise). This keep class definitions very siple yet decouples configurable parameters from class attributes. In terms of configs, it is a simplified hydra alternative, yet supporting more features.

## Features

Last 3 features are in development:
* Embedded config params in configurables (no need for separate `.config` attribute, unless specified otherwise)
* Easy type annotations (visible annotations, even though configs are never inherited from)
* Support for multiple, nested, hierarchical, and union configs, as well as non-atomic types
* Various file support (`json`, `yaml`, `pickle`)
* CLI support
* Decorator-based (inspired by Hydra)

## Quick Start

Install the library:

```bash
pip install dataconfigs
```

Check the [demo](https://github.com/mantasu/dataconfigs/blob/main/notebooks/01-demo.ipynb).

### Simple Script Example

1. Simply define your config (must be a datacalss and contain the word Config in name!)
2. Extend the config with your configurable (it won't turn into a dataclass unless specified!)
3. Instantiate your configurable by optionally overwriting default config parameters

```python
from datacalsses import dataclass, is_dataclass
from dataconfigs import configurable, show_config_params

@datacalss
class MyConfig:
    """My config class
    Args:
        param1 (int): The first parameter.
        param2 (str): The second parameter.
    """
    param1: int = 0
    param2: str = "param2"

@configurable
class MyConfigurable(MyConfig):
    def __init__(self, attr1=1, attr2=2):
        print(self.param1, self.param2) # Already available!

assert not is_dataclass(MyConfigurable) # Only attributes were copied!
obj = MyConfigurable("attr1", param1=1) # Can overwrite config params! 
# 1, 'param2'
```

### Simple CLI Example (only ideas for now)

Assume you have `config.json` file as follows:
```json
{
    "param1": 111,
    "param2": "222"
}
```

One possibility is to directly make the configurable. Example `main.py`:
```python
@configurable.main("path/to/config.json", MyConfigurable, attr1="attr1")
def main(my_configurable):
    pass

if __name__ == "__main__":
    main()
```

We can still overwrite config params or the whole config file when calling:
```bash
dataconfigs main.py --param2 'custom' # 111, 'custom'
dataconfigs main.py --config path/to/config2.yaml
```

If we call `dataconfigs main.py -h`, descriptions will be extracted from docstrings:
```bash
Options:
--param1 : (int) The first parameter. Defaults to 111.
--param2 : (str) The second parameter. Defaults to '222'.
```

## Tutorials (TODO)

1. **Config classes**: there are many ways to define configs. The only restriction is that they must be dataclasses and contain an "Config" word in their class name (see basics):
    * **Basics**
    * **Unions & non-atomic types**
    * **Multiple, nested and hierarchical configs**
    * **Config files (json, yaml, pkl, etc.)**
2. **Configurables**: any class (configurable) that extends the config(-s) will only obtain its attributes and won't alter its class definition. The configurable class can inherit from any other parents in the usual manner.
    * **Config vs non-config attributes**
    * **Various ways to instantiate**
3. Compatibility with Third Party CLI
    * Pytorch Lightning
    * Tensorflow
    * Optuna
    * Ray


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mantasu/dataconfigs",
    "name": "dataconfigs",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "python, config, configuration, configurable",
    "author": "Mantas Bir\u0161kus",
    "author_email": "mantix7@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/03/1c/a3a550e314a7f0ee90dd42535643dc6adafd60f9efd11724cc460ce88881/dataconfigs-0.1.0.tar.gz",
    "platform": null,
    "description": "# Dataconfigs\n\n## About\n\nDataconfigs provides a seamless integration between dataclasses as configs and any configurable classes that use these configs. The most powerful feature is that config attributes become part of configurable, i.e., no need for _explicit_ `.config` attribute (unless specified otherwise). This keep class definitions very siple yet decouples configurable parameters from class attributes. In terms of configs, it is a simplified hydra alternative, yet supporting more features.\n\n## Features\n\nLast 3 features are in development:\n* Embedded config params in configurables (no need for separate `.config` attribute, unless specified otherwise)\n* Easy type annotations (visible annotations, even though configs are never inherited from)\n* Support for multiple, nested, hierarchical, and union configs, as well as non-atomic types\n* Various file support (`json`, `yaml`, `pickle`)\n* CLI support\n* Decorator-based (inspired by Hydra)\n\n## Quick Start\n\nInstall the library:\n\n```bash\npip install dataconfigs\n```\n\nCheck the [demo](https://github.com/mantasu/dataconfigs/blob/main/notebooks/01-demo.ipynb).\n\n### Simple Script Example\n\n1. Simply define your config (must be a datacalss and contain the word Config in name!)\n2. Extend the config with your configurable (it won't turn into a dataclass unless specified!)\n3. Instantiate your configurable by optionally overwriting default config parameters\n\n```python\nfrom datacalsses import dataclass, is_dataclass\nfrom dataconfigs import configurable, show_config_params\n\n@datacalss\nclass MyConfig:\n    \"\"\"My config class\n    Args:\n        param1 (int): The first parameter.\n        param2 (str): The second parameter.\n    \"\"\"\n    param1: int = 0\n    param2: str = \"param2\"\n\n@configurable\nclass MyConfigurable(MyConfig):\n    def __init__(self, attr1=1, attr2=2):\n        print(self.param1, self.param2) # Already available!\n\nassert not is_dataclass(MyConfigurable) # Only attributes were copied!\nobj = MyConfigurable(\"attr1\", param1=1) # Can overwrite config params! \n# 1, 'param2'\n```\n\n### Simple CLI Example (only ideas for now)\n\nAssume you have `config.json` file as follows:\n```json\n{\n    \"param1\": 111,\n    \"param2\": \"222\"\n}\n```\n\nOne possibility is to directly make the configurable. Example `main.py`:\n```python\n@configurable.main(\"path/to/config.json\", MyConfigurable, attr1=\"attr1\")\ndef main(my_configurable):\n    pass\n\nif __name__ == \"__main__\":\n    main()\n```\n\nWe can still overwrite config params or the whole config file when calling:\n```bash\ndataconfigs main.py --param2 'custom' # 111, 'custom'\ndataconfigs main.py --config path/to/config2.yaml\n```\n\nIf we call `dataconfigs main.py -h`, descriptions will be extracted from docstrings:\n```bash\nOptions:\n--param1 : (int) The first parameter. Defaults to 111.\n--param2 : (str) The second parameter. Defaults to '222'.\n```\n\n## Tutorials (TODO)\n\n1. **Config classes**: there are many ways to define configs. The only restriction is that they must be dataclasses and contain an \"Config\" word in their class name (see basics):\n    * **Basics**\n    * **Unions & non-atomic types**\n    * **Multiple, nested and hierarchical configs**\n    * **Config files (json, yaml, pkl, etc.)**\n2. **Configurables**: any class (configurable) that extends the config(-s) will only obtain its attributes and won't alter its class definition. The configurable class can inherit from any other parents in the usual manner.\n    * **Config vs non-config attributes**\n    * **Various ways to instantiate**\n3. Compatibility with Third Party CLI\n    * Pytorch Lightning\n    * Tensorflow\n    * Optuna\n    * Ray\n\n",
    "bugtrack_url": null,
    "license": "Apache",
    "summary": "Turn your dataclasses into configs seamlessly.",
    "version": "0.1.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/mantasu/dataconfigs/issues",
        "Documentation": "https://mantasu.github.io/dataconfigs",
        "Homepage": "https://github.com/mantasu/dataconfigs"
    },
    "split_keywords": [
        "python",
        " config",
        " configuration",
        " configurable"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "51ba83c5e928c50d97cbaf5ab50ccac889e2d2d9d0ceae7fde0175dbd992f48c",
                "md5": "e4eae7fc433148f3d158a617bfd7e0f6",
                "sha256": "ac494a18b6e2b31aae23f60c56676f9b218007883386eaf74cc7352e65b53331"
            },
            "downloads": -1,
            "filename": "dataconfigs-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e4eae7fc433148f3d158a617bfd7e0f6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 18360,
            "upload_time": "2024-10-28T02:44:51",
            "upload_time_iso_8601": "2024-10-28T02:44:51.528813Z",
            "url": "https://files.pythonhosted.org/packages/51/ba/83c5e928c50d97cbaf5ab50ccac889e2d2d9d0ceae7fde0175dbd992f48c/dataconfigs-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "031ca3a550e314a7f0ee90dd42535643dc6adafd60f9efd11724cc460ce88881",
                "md5": "99909df91a0cf9d730dfc2dfffe9d55c",
                "sha256": "3c56f0be32762dd1be33dec439e883b87e2d5e8088f4e23a910b1a0f5c545355"
            },
            "downloads": -1,
            "filename": "dataconfigs-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "99909df91a0cf9d730dfc2dfffe9d55c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 18347,
            "upload_time": "2024-10-28T02:44:52",
            "upload_time_iso_8601": "2024-10-28T02:44:52.721559Z",
            "url": "https://files.pythonhosted.org/packages/03/1c/a3a550e314a7f0ee90dd42535643dc6adafd60f9efd11724cc460ce88881/dataconfigs-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-28 02:44:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mantasu",
    "github_project": "dataconfigs",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "dataconfigs"
}
        
Elapsed time: 0.43199s