Metadata-Version: 2.1
Name: yaml2pyclass
Version: 0.1.2
Summary: Code generator that produces a Python class from a YAML input file. Can be used to facilitate code completion for config objects. 
Home-page: https://github.com/a-nau/yaml2pyclass
Author: Alexander Naumann, Felix Hertlein
Author-email: alex.code@mail.com, hertlein@fzi.de
License: BSD-3
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.7.0
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyyaml
Provides-Extra: all
Requires-Dist: pyyaml ; extra == 'all'
Requires-Dist: black >=20.1.0 ; extra == 'all'
Requires-Dist: isort ==5.9.3 ; extra == 'all'
Requires-Dist: mypy >=0.761 ; extra == 'all'
Requires-Dist: pre-commit >=2.9.2 ; extra == 'all'
Requires-Dist: pytest >=4.5.0 ; extra == 'all'
Requires-Dist: pytest-cov >=2.6.1 ; extra == 'all'
Requires-Dist: pyupgrade >=3.2.0 ; extra == 'all'
Requires-Dist: types-PyYAML ; extra == 'all'
Requires-Dist: flask >=2.0.2 ; extra == 'all'
Requires-Dist: ipykernel >=6.9.0 ; extra == 'all'
Requires-Dist: mike >=0.5.3 ; extra == 'all'
Requires-Dist: mkdocs >=1.2.3 ; extra == 'all'
Requires-Dist: mkdocs-awesome-pages-plugin >=2.7.0 ; extra == 'all'
Requires-Dist: mkdocs-gen-files >=0.3.5 ; extra == 'all'
Requires-Dist: mkdocs-literate-nav >=0.4.1 ; extra == 'all'
Requires-Dist: mkdocs-material >=8.1.11 ; extra == 'all'
Requires-Dist: mkdocstrings[python] >=0.19.0 ; extra == 'all'
Requires-Dist: pytkdocs[numpy-style] >=0.5.0 ; extra == 'all'
Requires-Dist: ipython-genutils >=0.1.0 ; extra == 'all'
Requires-Dist: mkdocs-jupyter >=0.20.0 ; extra == 'all'
Requires-Dist: mkdocs-bibtex ==2.8.1 ; extra == 'all'
Requires-Dist: nbconvert ==6.4.2 ; extra == 'all'
Requires-Dist: numpydoc ==1.2 ; extra == 'all'
Requires-Dist: spacy ==3.2.2 ; extra == 'all'
Requires-Dist: jinja2 ==3.0.3 ; extra == 'all'
Provides-Extra: dev
Requires-Dist: pyyaml ; extra == 'dev'
Requires-Dist: black >=20.1.0 ; extra == 'dev'
Requires-Dist: isort ==5.9.3 ; extra == 'dev'
Requires-Dist: mypy >=0.761 ; extra == 'dev'
Requires-Dist: pre-commit >=2.9.2 ; extra == 'dev'
Requires-Dist: pytest >=4.5.0 ; extra == 'dev'
Requires-Dist: pytest-cov >=2.6.1 ; extra == 'dev'
Requires-Dist: pyupgrade >=3.2.0 ; extra == 'dev'
Requires-Dist: types-PyYAML ; extra == 'dev'
Provides-Extra: docs
Requires-Dist: flask >=2.0.2 ; extra == 'docs'
Requires-Dist: ipykernel >=6.9.0 ; extra == 'docs'
Requires-Dist: mike >=0.5.3 ; extra == 'docs'
Requires-Dist: mkdocs >=1.2.3 ; extra == 'docs'
Requires-Dist: mkdocs-awesome-pages-plugin >=2.7.0 ; extra == 'docs'
Requires-Dist: mkdocs-gen-files >=0.3.5 ; extra == 'docs'
Requires-Dist: mkdocs-literate-nav >=0.4.1 ; extra == 'docs'
Requires-Dist: mkdocs-material >=8.1.11 ; extra == 'docs'
Requires-Dist: mkdocstrings[python] >=0.19.0 ; extra == 'docs'
Requires-Dist: pytkdocs[numpy-style] >=0.5.0 ; extra == 'docs'
Requires-Dist: ipython-genutils >=0.1.0 ; extra == 'docs'
Requires-Dist: mkdocs-jupyter >=0.20.0 ; extra == 'docs'
Requires-Dist: mkdocs-bibtex ==2.8.1 ; extra == 'docs'
Requires-Dist: nbconvert ==6.4.2 ; extra == 'docs'
Requires-Dist: numpydoc ==1.2 ; extra == 'docs'
Requires-Dist: spacy ==3.2.2 ; extra == 'docs'
Requires-Dist: jinja2 ==3.0.3 ; extra == 'docs'
Provides-Extra: test
Requires-Dist: pyyaml ; extra == 'test'
Requires-Dist: black >=20.1.0 ; extra == 'test'
Requires-Dist: isort ==5.9.3 ; extra == 'test'
Requires-Dist: mypy >=0.761 ; extra == 'test'
Requires-Dist: pre-commit >=2.9.2 ; extra == 'test'
Requires-Dist: pytest >=4.5.0 ; extra == 'test'
Requires-Dist: pytest-cov >=2.6.1 ; extra == 'test'
Requires-Dist: pyupgrade >=3.2.0 ; extra == 'test'
Requires-Dist: types-PyYAML ; extra == 'test'


[![PyPI](https://github.com/a-nau/yaml2pyclass/actions/workflows/pypi_publish.yml/badge.svg)](https://github.com/a-nau/yaml2pyclass/actions/workflows/pypi_publish.yml)
[![test](https://github.com/a-nau/yaml2pyclass/workflows/test/badge.svg)](https://github.com/a-nau/yaml2pyclass/actions)

# yaml2pyclass Code Generator

This package enables you to easily generate and instantiate dataclasses from an input `YAML` file. For example
this `YAML` file

```yaml
image_size: [ 1280, 960 ]
cluster_config:
  eps: 0.02
  min_num_samples: 10
path_output: "./output"
```

automatically converts to a Python `class`

```python
import dataclasses
import yaml2pyclass

class Config(yaml2pyclass.CodeGenerator):
    @dataclasses.dataclass
    class ClusterConfigClass:
        eps: float
        min_num_samples: int

    image_size: list
    cluster_config: ClusterConfigClass
    path_output: str
```

In addition to code creation, an instance of the generated class that is initialized with the `YAML`s values can be
created automatically.

The use case it was primarily developed for is facilitating code completion for arbitrary `YAML` config files.
Using `YAML` files as input config allows flexible and general information passing, however, when
using [`pyyaml`](https://pypi.org/project/PyYAML/) the
information is saved as a `dict` which does not support any automatic code completion. This means, that you need to know
the exact variable names for access.

Using this package you can enjoy `YAML`s flexibility and generality, while additionally providing the benefit of code
completion and type specific suggestions from your IDE. Thus, no need to memorize exact variable names or types.

## Installation

You can install the package using `pip`

```shell
pip install yaml2pyclass
```

## Usage

### File Update

To update an existing file, as e.g. in the case of a config file, you need to create a base file. The base file (e.g.
at `path/to/config.py`) should simply contain a class, that inherits from the `yaml2pyclass` base class `CodeGenerator`:

```python
import yaml2pyclass


class Config(yaml2pyclass.CodeGenerator):
    # content is updated automatically from the specified YAML file
    pass
```

Then, in the function where you want to use this class based on the `YAML` input, import the created class and call
the `from_yaml` function

```python
from path.to.config import Config  # import the class Config from the path/to/config.py file

config = Config.from_yaml("config.yaml")
```

This will update the file of the `Config` class with dataclass that matches the input `YAML`.

## Contributors

This project is a collaboration with [Felix Hertlein](https://github.com/FelixHertlein).

## License

This code is distributed under the 3-Clause BSD License, see [LICENSE](LICENSE).


