fancy-dataclass


Namefancy-dataclass JSON
Version 0.4.2 PyPI version JSON
download
home_pageNone
SummarySpiff up your dataclasses with extra features.
upload_time2024-04-29 22:01:48
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords cli config dataclass json orm serialize toml
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![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)

# 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), but it aims 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/8c/c4/965b0e31c2ea3f0d2cd358615d55512f98a9f2e2f80576f91712cc0a0eaa/fancy_dataclass-0.4.2.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\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), but it aims 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.4.2",
    "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": "66961dda2af4184dba8e8b2b31d244055f117921f573673b19c23ddc53394854",
                "md5": "dbaa4b64a0c93df84519a53358e6c41e",
                "sha256": "0fe590ccd05ed4658980b0b00f00196596a4815745aa2ea654ec1fbf62063714"
            },
            "downloads": -1,
            "filename": "fancy_dataclass-0.4.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dbaa4b64a0c93df84519a53358e6c41e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 286894,
            "upload_time": "2024-04-29T22:01:44",
            "upload_time_iso_8601": "2024-04-29T22:01:44.988859Z",
            "url": "https://files.pythonhosted.org/packages/66/96/1dda2af4184dba8e8b2b31d244055f117921f573673b19c23ddc53394854/fancy_dataclass-0.4.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8cc4965b0e31c2ea3f0d2cd358615d55512f98a9f2e2f80576f91712cc0a0eaa",
                "md5": "e7eecf71f62154887c37bdcb246a65fd",
                "sha256": "53bd17f5f7525640d4e242fa144f08a75f4deb82ce27990418865c0f10e1beb9"
            },
            "downloads": -1,
            "filename": "fancy_dataclass-0.4.2.tar.gz",
            "has_sig": false,
            "md5_digest": "e7eecf71f62154887c37bdcb246a65fd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 277585,
            "upload_time": "2024-04-29T22:01:48",
            "upload_time_iso_8601": "2024-04-29T22:01:48.740837Z",
            "url": "https://files.pythonhosted.org/packages/8c/c4/965b0e31c2ea3f0d2cd358615d55512f98a9f2e2f80576f91712cc0a0eaa/fancy_dataclass-0.4.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-29 22:01:48",
    "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"
}
        
Elapsed time: 0.26269s