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
- Version management: assign numbers to different versions of the same data type
fancy_dataclass borrows ideas from other excellent libraries such as marshmallow, pydantic, and 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.9 or higher.
Example
Regular dataclass
@dataclass
class Person:
name: str
age: int
height: float
hobbies: list[str]
Fancy dataclass
from fancy_dataclass import JSONDataclass
@dataclass
class Person(JSONDataclass):
name: str
age: int
height: float
hobbies: list[str]
Usage:
>>> 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.
The documentation is made with Material for MkDocs and is hosted by Read the Docs.
View the Changelog here.
License
This library is distributed under the terms of the MIT license.
Metadata
Release files for fancy-dataclass 0.12.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fancy_dataclass-0.12.0.tar.gz | 327.4 kB | Without provenance | Details for fancy_dataclass-0.12.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fancy_dataclass-0.12.0-py3-none-any.whl | Python 3 | none | any | Details for fancy_dataclass-0.12.0-py3-none-any.whl |
Total release size: 412.4 kB
Release files / fancy_dataclass-0.12.0.tar.gz
| Download URL | fancy_dataclass-0.12.0.tar.gz |
|---|---|
| Size | 327.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
54dfc14a1e858a855b2c8e9ad094b820197af2baf2f31acfd1ad8562b53de011
|
|
BLAKE2b-256 checksum How to use checksums |
5121364635e19827341600381c54e4dfc6786af8449a4b1a5f353647873685d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.5 cpython/3.13.11 HTTPX/0.28.1
|
Release files / fancy_dataclass-0.12.0-py3-none-any.whl
| Download URL | fancy_dataclass-0.12.0-py3-none-any.whl |
|---|---|
| Size | 85.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
86d64b34a85a12b21840a81477f81c3aface949a0c87a0dc2a5b04f8f89c4012
|
|
BLAKE2b-256 checksum How to use checksums |
e2dfffc555acdcfcfe4bb83086580e48b2c836a41ba28211e42d1a72c6079e95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.5 cpython/3.13.11 HTTPX/0.28.1
|
Security for fancy-dataclass 0.12.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.