# ⚔️ Heracless ⚔️
A simple and minimalistic Config Manager using YAML.
[![GitHub](https://img.shields.io/badge/GitHub-Repository-blue?logo=github)](https://github.com/felixscode/heracless)
[![PyPi](https://img.shields.io/badge/PyPi-Package-blue?logo=pypi)](https://pypi.org/project/heracless/)
[![Documentation](https://img.shields.io/badge/Documentation-Read-green?logo=readthedocs)](https://heracless.io/docs)
## Table of Contents
- [Description](#description)
- [Installation](#installation)
- [Setup](#setup)
- [CLI Tool](#cli-tool)
- [Helper Functions in Heracless](#helper-functions-in-heracless)
- [mutate_config](#mutate_config)
- [as_dict](#as_dict)
- [from_dict](#from_dict)
- [Version](#version)
- [Future](#future)
- [Author](#author)
## 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 stub file (.pyi) which can be used for type hints. Generated types also make autocompletion dreamy!
## Installation
Heracless is available as a pip package:
```bash
pip install heracless
```
If you want to build from source, run:
```bash
git clone https://github.com/felixscode/heracless.git
cd heracless
pip install -e .
```
## Setup
First, create a `config.yaml` file in a desired location and add desired configs. Make a new Python file called `load_config.py` and put it somewhere into your project.
Here is an example project structure:
```
├── src
│ └── your_module
│ ├── main.py
│ └──utils
│ └── load_config.py
├── data
│ └── config.yaml
├── README.md
├── pyproject.toml
└── .gitignore
```
Paste the following code into your `load_config.py`:
```python
from pathlib import Path
from typing import Type, TypeVar
from heracless import load_config as _load_config
# CONFIG_YAML_PATH is a global variable that sets the path of your YAML config file
# Edit this to your config file path
CONFIG_YAML_PATH = None
Config = TypeVar("Config")
def load_config(frozen: bool = True) -> Config:
"""
Load the configuration from the specified directory and return a Config object.
Args:
frozen (bool, optional): Whether the configuration should be frozen. Defaults to True.
Returns:
Config: The loaded configuration object.
Raises:
FileNotFoundError: If the configuration file does not exist.
yaml.YAMLError: If there is an error parsing the YAML configuration file.
Note:
CONFIG_YAML_PATH is a global variable that sets the path of your YAML config file.
"""
file_path = Path(__file__).resolve()
yaml_config_path = CONFIG_YAML_PATH
return _load_config(yaml_config_path,file_path, frozen=frozen)
```
After creating the `load_config.py` file, set the `CONFIG_YAML_PATH` variable to the path of your `config.yaml` file. For example:
```python
CONFIG_YAML_PATH = "/path/to/your/config.yaml"
```
## 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 your_project import load_config
from heracless.utils.helper import mutate_config
config = load_config()
new_config = mutate_config(config, "name", "new_value")
```
### `as_dict`
This function converts a `Config` object to a dictionary.
```python
from your_project import load_config
from heracless.utils.helper import as_dict
config = load_config()
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)
```
## Version
Heracless 0.4 <br>
Written in Python 3.11
## Future
- [ ] Add config variants
- [ ] Add None type support
- [x] Web app
## Author
Felix Schelling<br>
GitHub: [felixscode](https://github.com/felixscode)<br>
Website: [heracless.io](https://heracless.io)<br>
Personal website: [felixschelling.de](https://felixschelling.de)<br>
Written with ❤️ in Mexico
Raw data
{
"_id": null,
"home_page": null,
"name": "heracless",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "YAML, Dataclass, Config, config, config management",
"author": null,
"author_email": "Felix Schelling <felix.schelling@protonmail.com>",
"download_url": "https://files.pythonhosted.org/packages/4c/b0/59de3633a7a604195b2872fad659bed7d674af1c2f16e24b6eaaef1f9c76/heracless-0.3.2.tar.gz",
"platform": null,
"description": "# \u2694\ufe0f Heracless \u2694\ufe0f\n\nA simple and minimalistic Config Manager using YAML. \n[![GitHub](https://img.shields.io/badge/GitHub-Repository-blue?logo=github)](https://github.com/felixscode/heracless)\n[![PyPi](https://img.shields.io/badge/PyPi-Package-blue?logo=pypi)](https://pypi.org/project/heracless/)\n[![Documentation](https://img.shields.io/badge/Documentation-Read-green?logo=readthedocs)](https://heracless.io/docs)\n \n\n## Table of Contents\n- [Description](#description)\n- [Installation](#installation)\n- [Setup](#setup)\n- [CLI Tool](#cli-tool)\n- [Helper Functions in Heracless](#helper-functions-in-heracless)\n - [mutate_config](#mutate_config)\n - [as_dict](#as_dict)\n - [from_dict](#from_dict)\n- [Version](#version)\n- [Future](#future)\n- [Author](#author)\n\n## Description\n\nHeracless aims to make working with config files in Python easy. It parses a config file into a dataclass and creates types as a Python stub file (.pyi) which can be used for type hints. Generated types also make autocompletion dreamy!\n\n## Installation\n\nHeracless is available as a pip package:\n\n```bash\npip install heracless\n```\n\nIf you want to build from source, run:\n\n```bash\ngit clone https://github.com/felixscode/heracless.git\ncd heracless\npip install -e .\n```\n\n## Setup\n\nFirst, create a `config.yaml` file in a desired location and add desired configs. Make a new Python file called `load_config.py` and put it somewhere into your project.\nHere is an example project structure:\n```\n\u251c\u2500\u2500 src\n\u2502 \u2514\u2500\u2500 your_module\n\u2502 \u251c\u2500\u2500 main.py\n\u2502 \u2514\u2500\u2500utils\n\u2502 \u2514\u2500\u2500 load_config.py\n\u251c\u2500\u2500 data\n\u2502 \u2514\u2500\u2500 config.yaml\n\u251c\u2500\u2500 README.md\n\u251c\u2500\u2500 pyproject.toml\n\u2514\u2500\u2500 .gitignore\n\n```\n\n\nPaste the following code into your `load_config.py`:\n\n```python\nfrom pathlib import Path\nfrom typing import Type, TypeVar\n\nfrom heracless import load_config as _load_config\n\n# CONFIG_YAML_PATH is a global variable that sets the path of your YAML config file \n# Edit this to your config file path\nCONFIG_YAML_PATH = None\n\nConfig = TypeVar(\"Config\")\n\ndef load_config(frozen: bool = True) -> Config:\n \"\"\"\n Load the configuration from the specified directory and return a Config object.\n\n Args:\n frozen (bool, optional): Whether the configuration should be frozen. Defaults to True.\n\n Returns:\n Config: The loaded configuration object.\n\n Raises:\n FileNotFoundError: If the configuration file does not exist.\n yaml.YAMLError: If there is an error parsing the YAML configuration file.\n\n Note:\n CONFIG_YAML_PATH is a global variable that sets the path of your YAML config file.\n \"\"\"\n\n file_path = Path(__file__).resolve()\n yaml_config_path = CONFIG_YAML_PATH\n return _load_config(yaml_config_path,file_path, frozen=frozen)\n```\n\nAfter creating the `load_config.py` file, set the `CONFIG_YAML_PATH` variable to the path of your `config.yaml` file. For example:\n\n```python\nCONFIG_YAML_PATH = \"/path/to/your/config.yaml\"\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 your_project import load_config\n\nfrom heracless.utils.helper import mutate_config\n\nconfig = load_config()\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 your_project import load_config\n\nfrom heracless.utils.helper import as_dict\n\nconfig = load_config()\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## Version\n\nHeracless 0.4 <br>\nWritten in Python 3.11\n\n## Future\n\n- [ ] Add config variants\n- [ ] Add None type support\n- [x] Web app\n\n## Author\n\nFelix Schelling<br>\nGitHub: [felixscode](https://github.com/felixscode)<br>\nWebsite: [heracless.io](https://heracless.io)<br>\nPersonal website: [felixschelling.de](https://felixschelling.de)<br>\nWritten with \u2764\ufe0f in Mexico\n\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Yaml to Dataclass parser for Config files",
"version": "0.3.2",
"project_urls": {
"Homepage": "https://heracless.io",
"Repository": "https://github.com/felixscode/heracless.git"
},
"split_keywords": [
"yaml",
" dataclass",
" config",
" config",
" config management"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "98a909790ae0146fa7d1e203645cf06ec00199893b68de3a407515ed3c388d46",
"md5": "0b64270588187f22ce3d514c9f22f5fb",
"sha256": "ae4d2d840fd7dbbfb16f26ac5fa644df5d316c402967f9cf8b4f69bd0911da7f"
},
"downloads": -1,
"filename": "heracless-0.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0b64270588187f22ce3d514c9f22f5fb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 20809,
"upload_time": "2024-12-19T16:23:45",
"upload_time_iso_8601": "2024-12-19T16:23:45.320080Z",
"url": "https://files.pythonhosted.org/packages/98/a9/09790ae0146fa7d1e203645cf06ec00199893b68de3a407515ed3c388d46/heracless-0.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4cb059de3633a7a604195b2872fad659bed7d674af1c2f16e24b6eaaef1f9c76",
"md5": "a9602660d4ea015b68910caf1d5dd3c5",
"sha256": "f1db08722ef1550e00059664e36590ffe56752b9604ab71d6e3e475dff3e6876"
},
"downloads": -1,
"filename": "heracless-0.3.2.tar.gz",
"has_sig": false,
"md5_digest": "a9602660d4ea015b68910caf1d5dd3c5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 15866,
"upload_time": "2024-12-19T16:23:47",
"upload_time_iso_8601": "2024-12-19T16:23:47.881797Z",
"url": "https://files.pythonhosted.org/packages/4c/b0/59de3633a7a604195b2872fad659bed7d674af1c2f16e24b6eaaef1f9c76/heracless-0.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-19 16:23:47",
"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"
}