heracless


Nameheracless JSON
Version 0.2.2 PyPI version JSON
download
home_page
SummaryYaml to Dataclass parser for Config files
upload_time2024-03-18 10:14:07
maintainer
docs_urlNone
author
requires_python>=3.10
license
keywords ymal dataclass config
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # heracless

Config Manager using yaml.

# Description

heracless aims to make working with config files in python easy. It parses a config file into a dataclass
and creates types as a python file
with can be used for type hints. Generated types also make autocompletion a dreamy!

# Usage

first create a config file in yaml format and put in your desired fields.
to access the config information do like in following sample code.

```
from heracless import heracless
from config.types import Config

@heracless()
def main(cfg:Config) -> Any: 
"""
simply add a cfg parameter to any function at the first place
and access config attributes like you do any with any other object
"""
    some_sample_config_value = config.sample.some_value

```

its as simple as that!

or simply use the load_config function to load the config file into a dataclass
```
from heracless import load_config
from config.types import Config

@heracless()
def main(*args,**kwargs) -> Any: 
    config = load_config()
    print(config.sample.some_value)

```

arguments:

- **cfg_path**:Path yaml config file path -> Default ./config/config.yaml
- **dump_dir**:Path Path where types are going to be written to -> Default ./config/types.py
- **dump_func**:Callable control's the dumping behavior -> options: heracless.dump_in_file|heracless.dump_in_console| heracless.dump_dummy -> Default dump_in_file
- **frozen**:bool whether dataclass config objects are mutable or not -> Default True
- **make_dir**:bool make given paths or not if not existing -> Default True

# Cli-Tool

heracless also comes with a cli tool to generate the types file from a config file
simply run the following command in your terminal

```bash

heracless path/to/config.yaml -p path/to/types.py # generates types file
heracless path/to/config.yaml -d # dumps types to console
heracless path/to/config.yaml -h # for help
```
Sure, here's a markdown document that describes the functions in `helper.py` and provides example usage:

---

# Helper Functions in Heracless

This document describes the helper functions in the `helper.py` module of the Heracless project.

## `mutate_config`

This function takes a `Config` object, a name, and a value, and returns a new `Config` object with the value at the name updated.

```python
from heracless.utils.helper import mutate_config
from heracless.utils.c_types import Config

config = Config(...)  # Initialize a Config object
new_config = mutate_config(config, "name", "new_value")
```

## `as_dict`

This function converts a `Config` object to a dictionary.

```python
from heracless.utils.helper import as_dict
from heracless.utils.c_types import Config

config = Config(...)  # Initialize a Config object
config_dict = as_dict(config)
```

## `from_dict`

This function creates a `Config` object from a dictionary. You can specify whether the `Config` object should be frozen.

```python
from heracless.utils.helper import from_dict

config_dict = {...}  # A dictionary representing the configuration
config = from_dict(config_dict, frozen=True)
```

---

Remember to replace `Config(...)` and `{...}` with actual `Config` objects and dictionaries.

## installation

```bash
pip install heracless
```

## Version

heracless 0.2 <br>
written in python 3.11

## Future

add config variants <br>


## Author

Felix Schelling<br>
github: felixscode <br>
Witten with <3 in Mexico

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "heracless",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "YMAL,Dataclass,Config",
    "author": "",
    "author_email": "Felix Schelling <felix.schelling@protonmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/dd/4b/cc107c6773d32d35ecda28c11023d8abc1e9219b9bc12aa88fe0e2e9aed6/heracless-0.2.2.tar.gz",
    "platform": null,
    "description": "# heracless\n\nConfig Manager using yaml.\n\n# Description\n\nheracless aims to make working with config files in python easy. It parses a config file into a dataclass\nand creates types as a python file\nwith can be used for type hints. Generated types also make autocompletion a dreamy!\n\n# Usage\n\nfirst create a config file in yaml format and put in your desired fields.\nto access the config information do like in following sample code.\n\n```\nfrom heracless import heracless\nfrom config.types import Config\n\n@heracless()\ndef main(cfg:Config) -> Any: \n\"\"\"\nsimply add a cfg parameter to any function at the first place\nand access config attributes like you do any with any other object\n\"\"\"\n    some_sample_config_value = config.sample.some_value\n\n```\n\nits as simple as that!\n\nor simply use the load_config function to load the config file into a dataclass\n```\nfrom heracless import load_config\nfrom config.types import Config\n\n@heracless()\ndef main(*args,**kwargs) -> Any: \n    config = load_config()\n    print(config.sample.some_value)\n\n```\n\narguments:\n\n- **cfg_path**:Path yaml config file path -> Default ./config/config.yaml\n- **dump_dir**:Path Path where types are going to be written to -> Default ./config/types.py\n- **dump_func**:Callable control's the dumping behavior -> options: heracless.dump_in_file|heracless.dump_in_console| heracless.dump_dummy -> Default dump_in_file\n- **frozen**:bool whether dataclass config objects are mutable or not -> Default True\n- **make_dir**:bool make given paths or not if not existing -> Default True\n\n# Cli-Tool\n\nheracless also comes with a cli tool to generate the types file from a config file\nsimply run the following command in your terminal\n\n```bash\n\nheracless path/to/config.yaml -p path/to/types.py # generates types file\nheracless path/to/config.yaml -d # dumps types to console\nheracless path/to/config.yaml -h # for help\n```\nSure, here's a markdown document that describes the functions in `helper.py` and provides example usage:\n\n---\n\n# Helper Functions in Heracless\n\nThis document describes the helper functions in the `helper.py` module of the Heracless project.\n\n## `mutate_config`\n\nThis function takes a `Config` object, a name, and a value, and returns a new `Config` object with the value at the name updated.\n\n```python\nfrom heracless.utils.helper import mutate_config\nfrom heracless.utils.c_types import Config\n\nconfig = Config(...)  # Initialize a Config object\nnew_config = mutate_config(config, \"name\", \"new_value\")\n```\n\n## `as_dict`\n\nThis function converts a `Config` object to a dictionary.\n\n```python\nfrom heracless.utils.helper import as_dict\nfrom heracless.utils.c_types import Config\n\nconfig = Config(...)  # Initialize a Config object\nconfig_dict = as_dict(config)\n```\n\n## `from_dict`\n\nThis function creates a `Config` object from a dictionary. You can specify whether the `Config` object should be frozen.\n\n```python\nfrom heracless.utils.helper import from_dict\n\nconfig_dict = {...}  # A dictionary representing the configuration\nconfig = from_dict(config_dict, frozen=True)\n```\n\n---\n\nRemember to replace `Config(...)` and `{...}` with actual `Config` objects and dictionaries.\n\n## installation\n\n```bash\npip install heracless\n```\n\n## Version\n\nheracless 0.2 <br>\nwritten in python 3.11\n\n## Future\n\nadd config variants <br>\n\n\n## Author\n\nFelix Schelling<br>\ngithub: felixscode <br>\nWitten with <3 in Mexico\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Yaml to Dataclass parser for Config files",
    "version": "0.2.2",
    "project_urls": {
        "Homepage": "https://github.com/felixscode/heracless"
    },
    "split_keywords": [
        "ymal",
        "dataclass",
        "config"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "14e98ef61a7f5dc059203b2c2e173f6ba556d6c044a1fbbc1e8edaa18d4b8cda",
                "md5": "63225ac76f65381de219e15be34e9ac2",
                "sha256": "7195f459af502de597e9fe26b68bb7562f71079b8e51f41fb0e96e9c3467a023"
            },
            "downloads": -1,
            "filename": "heracless-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "63225ac76f65381de219e15be34e9ac2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 13876,
            "upload_time": "2024-03-18T10:14:05",
            "upload_time_iso_8601": "2024-03-18T10:14:05.578224Z",
            "url": "https://files.pythonhosted.org/packages/14/e9/8ef61a7f5dc059203b2c2e173f6ba556d6c044a1fbbc1e8edaa18d4b8cda/heracless-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dd4bcc107c6773d32d35ecda28c11023d8abc1e9219b9bc12aa88fe0e2e9aed6",
                "md5": "d39b5167f5a346b769eeb56f2a7802e9",
                "sha256": "0d43ce654d820511eff57c02c2dc0c0adcc89e52a3853c3df3f803f9ebad78e3"
            },
            "downloads": -1,
            "filename": "heracless-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "d39b5167f5a346b769eeb56f2a7802e9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 11664,
            "upload_time": "2024-03-18T10:14:07",
            "upload_time_iso_8601": "2024-03-18T10:14:07.688695Z",
            "url": "https://files.pythonhosted.org/packages/dd/4b/cc107c6773d32d35ecda28c11023d8abc1e9219b9bc12aa88fe0e2e9aed6/heracless-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-18 10:14:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "felixscode",
    "github_project": "heracless",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "heracless"
}
        
Elapsed time: 0.22318s