Skip to main content

PyPI - Version GitHub Actions Workflow Status Coverage Status Read the Docs License: MIT 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
  • 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)

Source distribution for fancy-dataclass 0.12.0
File Size Uploaded
fancy_dataclass-0.12.0.tar.gz 327.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fancy-dataclass 0.12.0
File Interpreter ABI Platform
fancy_dataclass-0.12.0-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.12.0 This release

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.2

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page