https://github.com/karthikrangasai/anton
`anton` is a Python library for auto instantiating yaml definitions to user defined dataclasses with runtime type checking.
https://github.com/karthikrangasai/anton
configuration-management json python toml yaml
Last synced: about 2 months ago
JSON representation
`anton` is a Python library for auto instantiating yaml definitions to user defined dataclasses with runtime type checking.
- Host: GitHub
- URL: https://github.com/karthikrangasai/anton
- Owner: karthikrangasai
- License: mit
- Created: 2023-01-01T12:39:16.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-22T10:46:20.000Z (about 3 years ago)
- Last Synced: 2025-12-22T06:20:08.065Z (6 months ago)
- Topics: configuration-management, json, python, toml, yaml
- Language: Python
- Homepage: https://karthikrangasai.github.io/anton/
- Size: 2.93 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# anton
[](https://github.com/karthikrangasai/anton/actions/workflows/ci-testing.yml)
[](https://github.com/pre-commit/pre-commit)
`anton` is a Python library for auto instantiating yaml definitions to user defined dataclasses.
Avoid boilerplate and get runtime type checking before the objects are created.
## Usage
Given a `yaml` file definition in a file `index.yaml` as follows:
```yaml
# index.yaml
integer: 23
string: "Hello world"
point:
x: 0
y: 0
line_segment:
first_point:
x: 10
y: 10
second_point:
x: 10
y: 10
```
`yaml_conf` lets you avoid writing the biolerplate code for loading the `yaml` file and parsing the python dictionary to instantiate the Dataclass object as follows:
```py
>>> from dataclasses import dataclass
>>> from anton import yaml_conf
>>>
>>> @dataclass
... class Point:
... x: int
... y: int
...
>>> @dataclass
... class LineSegment:
... first_point: Point
... second_point: Point
...
>>> @yaml_conf()
... class ExampleClass:
... integer: int
... string: str
... point: Point
... line_segment: LineSegment
...
>>> example_obj = ExampleClass(conf_path="index.yaml")
>>> example_obj
ExampleClass(integer=23, string='Hello world', point=Point(x=0, y=0), line_segment=LineSegment(first_point=Point(x=10, y=10), second_point=Point(x=10, y=10)))
```
## Roadmap
Currently the project only supports Python3.8
Runtime type checking is supported for the following types:
- int
- float
- str
- bool
- typing.List
- typing.Dict
- typing.Union
- Any user defined dataclass
The ultimate aim is to support all python versions Python3.8+ and all possible type combinations.
## Contributing
Pull requests are welcome !!! Please make sure to update tests as appropriate.
For major changes, please open an issue first to discuss what you would like to change.
Please do go through the [Contributing Guide](https://github.com/karthikrangasai/anton/blob/master/CONTRIBUTING.md) if some help is required.
Note: `anton` currently in active development. Please [open an issue](https://github.com/karthikrangasai/anton/issues/new/choose) if you find anything that isn't working as expected.