[![PyPI - Version](https://img.shields.io/pypi/v/fancy-dataclass)](https://pypi.org/project/fancy-dataclass/)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/jeremander/fancy-dataclass/workflow.yml)
![Coverage Status](https://github.com/jeremander/fancy-dataclass/raw/coverage-badge/coverage-badge.svg)
[![Read the Docs](https://img.shields.io/readthedocs/fancy-dataclass)](https://fancy-dataclass.readthedocs.io)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/jeremander/fancy-dataclass/raw/main/docs/LICENSE.txt)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
# Basics
🤵🏻♂️ ***Fancy Dataclass***: A library to spiff up your dataclasses with extra features.
## Introduction
Python 3.7 introduced the `dataclasses` module which lets you write "statically typed" classes using the type hinting mechanism.
By inspecting dataclasses' type annotations, it is possible to endow them with special powers that help cut down on boilerplate code in a wide variety of domains, such as:
- *JSON/TOML conversion*: convert dataclasses to JSON/TOML files and vice versa
- *Configuration management*: store global configurations and use them anywhere in your program
- *SQL persistence*: define SQL tables, and save/load objects from a database
- *CLI parsing*: parse command-line arguments and store their values in a dataclass, then use them to execute your main program logic
- *Subprocess calls*: generate command-line arguments to be passed to another program
`fancy_dataclass` borrows ideas from other excellent libraries such as [`marshmallow`](https://marshmallow.readthedocs.io/en/stable/), [`pydantic`](https://docs.pydantic.dev/latest), and [`argparse_dataclass`](https://github.com/mivade/argparse_dataclass), while aiming to be as lightweight as possible in terms of its dependencies and learning curve.
## How to install
```pip install fancy-dataclass```
Requires Python 3.8 or higher.
## Example
**Regular dataclass**
```python
@dataclass
class Person:
name: str
age: int
height: float
hobbies: list[str]
```
**Fancy dataclass**
```python
@dataclass
class Person(JSONDataclass):
name: str
age: int
height: float
hobbies: list[str]
```
Usage:
```python
>>> person = Person(
name='John Doe',
age=47,
height=71.5,
hobbies=['reading', 'juggling', 'cycling']
)
>>> print(person.to_json_string(indent=2))
{
"name": "John Doe",
"age": 47,
"height": 71.5,
"hobbies": [
"reading",
"juggling",
"cycling"
]
}
```
## Documentation
Read the official documentation [here](https://fancy-dataclass.readthedocs.io).
The documentation is made with [Material for MkDocs](https://squidfunk.github.io/mkdocs-material) and is hosted by [Read the Docs](https://readthedocs.com).
View the Changelog [here](CHANGELOG.md).
## License
This library is distributed under the terms of the [MIT](LICENSE.txt) license.
Raw data
{
"_id": null,
"home_page": null,
"name": "fancy-dataclass",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "cli, config, dataclass, json, orm, serialize, toml",
"author": null,
"author_email": "Jeremy Silver <jeremys@nessiness.com>",
"download_url": "https://files.pythonhosted.org/packages/06/b2/a292b77fa22ce7e2a470d500cafd7fffea92d12f721b3f2c1f6c823ae066/fancy_dataclass-0.7.3.tar.gz",
"platform": null,
"description": "[![PyPI - Version](https://img.shields.io/pypi/v/fancy-dataclass)](https://pypi.org/project/fancy-dataclass/)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/jeremander/fancy-dataclass/workflow.yml)\n![Coverage Status](https://github.com/jeremander/fancy-dataclass/raw/coverage-badge/coverage-badge.svg)\n[![Read the Docs](https://img.shields.io/readthedocs/fancy-dataclass)](https://fancy-dataclass.readthedocs.io)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/jeremander/fancy-dataclass/raw/main/docs/LICENSE.txt)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)\n\n# Basics\n\n\ud83e\udd35\ud83c\udffb\u200d\u2642\ufe0f ***Fancy Dataclass***: A library to spiff up your dataclasses with extra features.\n\n## Introduction\n\nPython 3.7 introduced the `dataclasses` module which lets you write \"statically typed\" classes using the type hinting mechanism.\n\nBy inspecting dataclasses' type annotations, it is possible to endow them with special powers that help cut down on boilerplate code in a wide variety of domains, such as:\n\n- *JSON/TOML conversion*: convert dataclasses to JSON/TOML files and vice versa\n- *Configuration management*: store global configurations and use them anywhere in your program\n- *SQL persistence*: define SQL tables, and save/load objects from a database\n- *CLI parsing*: parse command-line arguments and store their values in a dataclass, then use them to execute your main program logic\n- *Subprocess calls*: generate command-line arguments to be passed to another program\n\n`fancy_dataclass` borrows ideas from other excellent libraries such as [`marshmallow`](https://marshmallow.readthedocs.io/en/stable/), [`pydantic`](https://docs.pydantic.dev/latest), and [`argparse_dataclass`](https://github.com/mivade/argparse_dataclass), while aiming to be as lightweight as possible in terms of its dependencies and learning curve.\n\n## How to install\n\n```pip install fancy-dataclass```\n\nRequires Python 3.8 or higher.\n\n## Example\n\n**Regular dataclass**\n\n```python\n@dataclass\nclass Person:\n name: str\n age: int\n height: float\n hobbies: list[str]\n```\n\n**Fancy dataclass**\n\n```python\n@dataclass\nclass Person(JSONDataclass):\n name: str\n age: int\n height: float\n hobbies: list[str]\n```\n\nUsage:\n\n```python\n>>> person = Person(\n name='John Doe',\n age=47,\n height=71.5,\n hobbies=['reading', 'juggling', 'cycling']\n)\n\n>>> print(person.to_json_string(indent=2))\n\n{\n \"name\": \"John Doe\",\n \"age\": 47,\n \"height\": 71.5,\n \"hobbies\": [\n \"reading\",\n \"juggling\",\n \"cycling\"\n ]\n}\n```\n\n## Documentation\n\nRead the official documentation [here](https://fancy-dataclass.readthedocs.io).\n\nThe documentation is made with [Material for MkDocs](https://squidfunk.github.io/mkdocs-material) and is hosted by [Read the Docs](https://readthedocs.com).\n\nView the Changelog [here](CHANGELOG.md).\n\n## License\n\nThis library is distributed under the terms of the [MIT](LICENSE.txt) license.\n",
"bugtrack_url": null,
"license": null,
"summary": "Spiff up your dataclasses with extra features.",
"version": "0.7.3",
"project_urls": {
"Changelog": "https://fancy-dataclass.readthedocs.io/en/stable/CHANGELOG",
"Documentation": "https://fancy-dataclass.readthedocs.io",
"Issues": "https://github.com/jeremander/fancy-dataclass/issues",
"Source": "https://github.com/jeremander/fancy-dataclass"
},
"split_keywords": [
"cli",
" config",
" dataclass",
" json",
" orm",
" serialize",
" toml"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "01c3c0434dcc3717ba95e09c4418b16ed99c5cb22daef06591b24b401ce2cfad",
"md5": "0f3f311aeaa8fb99fc4767488e05220d",
"sha256": "4e5569addb7ba686a077760a5880e790068708a364fafd6677a4b9b0d3f9fbd1"
},
"downloads": -1,
"filename": "fancy_dataclass-0.7.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0f3f311aeaa8fb99fc4767488e05220d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 354832,
"upload_time": "2024-11-01T15:04:28",
"upload_time_iso_8601": "2024-11-01T15:04:28.772397Z",
"url": "https://files.pythonhosted.org/packages/01/c3/c0434dcc3717ba95e09c4418b16ed99c5cb22daef06591b24b401ce2cfad/fancy_dataclass-0.7.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "06b2a292b77fa22ce7e2a470d500cafd7fffea92d12f721b3f2c1f6c823ae066",
"md5": "9ebc9df27a4298e3b9c4165fce34be50",
"sha256": "7ef5a46724b45e54e08842251454e7ffad271ea9914851436455fe0b66c70f87"
},
"downloads": -1,
"filename": "fancy_dataclass-0.7.3.tar.gz",
"has_sig": false,
"md5_digest": "9ebc9df27a4298e3b9c4165fce34be50",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 545090,
"upload_time": "2024-11-01T15:04:26",
"upload_time_iso_8601": "2024-11-01T15:04:26.672080Z",
"url": "https://files.pythonhosted.org/packages/06/b2/a292b77fa22ce7e2a470d500cafd7fffea92d12f721b3f2c1f6c823ae066/fancy_dataclass-0.7.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-01 15:04:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jeremander",
"github_project": "fancy-dataclass",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "fancy-dataclass"
}