Skip to main content

Utilities for working with Python dataclasses: serialize and deserialize to list with nested support.

Project description

dataclass_toolkit

Minimalistic utilities for working with Python dataclass — serialize, deserialize, and compactly store dataclass instances.

PyPI - Python Version PyPI - Version


Installation

pip install dataclass_toolkit

What is dataclass_toolkit?

dataclass_toolkit provides lightweight tools to work with Python dataclasses:

  • Convert dataclass instances into compact lists.
  • Restore dataclasses from lists.
  • Handle nested dataclasses and lists of dataclasses automatically.
  • Save and transmit dataclass data in the most compact way.

Example Usage

from dataclasses import dataclass
from dataclass_toolkit.as_list import serialize_dataclass_to_list, deserialize_list_to_dataclass

@dataclass
class Child:
    x: int
    y: str

@dataclass
class Parent:
    a: int
    b: Child
    c: list[Child]

# Create an object
p = Parent(
    a=1,
    b=Child(x=10, y="hello"),
    c=[Child(x=20, y="world")]
)

# Serialize to list
data = serialize_dataclass_to_list(p)
print(data)
# Output: [1, [10, 'hello'], [[20, 'world']]]

# Deserialize back
restored = deserialize_list_to_dataclass(Parent, data)
print(restored)
# Output: Parent(a=1, b=Child(x=10, y='hello'), c=[Child(x=20, y='world')])

🔥 Features

  • ✅ Supports nested dataclasses
  • ✅ Supports lists of dataclasses
  • ✅ Compatible with __slots__
  • ✅ Minimal and efficient serialization
  • ✅ Clean and extensible codebase

📜 License

This project is licensed under the MIT License — feel free to use it in your projects!


🤝 Contributing

Pull requests are welcome!
If you have ideas for improvements or new utilities, feel free to open an issue.

Project details


Download files

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

Source Distribution

dataclass_toolkit-0.1.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

dataclass_toolkit-0.1.1-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file dataclass_toolkit-0.1.1.tar.gz.

File metadata

  • Download URL: dataclass_toolkit-0.1.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for dataclass_toolkit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d2ab791301475244b54954524e03cd44c8e1f964a2bd8bfffa9ed0307a096c93
MD5 b588c2178c2dc28a50eb734a412c976f
BLAKE2b-256 d2bc96d8784fb9710501c02906825318990aa2fea39d33fe0bd28a16adb0cc11

See more details on using hashes here.

File details

Details for the file dataclass_toolkit-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dataclass_toolkit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7043d1c9f3603004af5ba9c4594c07080f4154ed9bd454306ff1c6b1e31ecbd7
MD5 252857b707dbf8a4dc8a3eb51c1c5f71
BLAKE2b-256 c1a94a29ba47e04f2797727c319a2750e2e29add9fa5be909527a271cc1ad9ca

See more details on using hashes here.

Supported by

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