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

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fancy_dataclass-0.11.1.tar.gz (327.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fancy_dataclass-0.11.1-py3-none-any.whl (84.3 kB view details)

Uploaded Python 3

File details

Details for the file fancy_dataclass-0.11.1.tar.gz.

File metadata

  • Download URL: fancy_dataclass-0.11.1.tar.gz
  • Upload date:
  • Size: 327.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.13.11 HTTPX/0.28.1

File hashes

Hashes for fancy_dataclass-0.11.1.tar.gz
Algorithm Hash digest
SHA256 40b01ef82f88c7bb9911b26944dcc0be268310a023c6835b173083236cc51c4f
MD5 ee7c4197a8de081445732726cf5245df
BLAKE2b-256 07d918823d9e2a33d1ab59899b520197222b98093001bc4f327e20c215b786cd

See more details on using hashes here.

File details

Details for the file fancy_dataclass-0.11.1-py3-none-any.whl.

File metadata

  • Download URL: fancy_dataclass-0.11.1-py3-none-any.whl
  • Upload date:
  • Size: 84.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.13.11 HTTPX/0.28.1

File hashes

Hashes for fancy_dataclass-0.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 63952f7bd4104d54cf9d55d1d05c7008a3e3419f2048b8eb17363a987f19af69
MD5 4909517cd77f5d7aa68b0dd8bc0ec0e6
BLAKE2b-256 8efd3be91ba2a7b1b33d7eed8a2953cb7c6c300f256a26d3db73cabd6023f482

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.11.1 This release

2 files

0.11.0

2 files

0.10.2

2 files

0.10.1

2 files

0.10.0

2 files

0.9.0

2 files

0.8.3

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page