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.2.tar.gz (5.0 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.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dataclass_toolkit-0.1.2.tar.gz
  • Upload date:
  • Size: 5.0 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.2.tar.gz
Algorithm Hash digest
SHA256 88f7655dabd187a576809ed8bf3f0e12c45cd5ea1bb8719d635d504b3f60594d
MD5 c8343d0cc838fa0bf1bbe75edf190317
BLAKE2b-256 ca9790c8a38841c4ad00d1835099646bfc762414af2d6bdc23ad352400b98a62

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dataclass_toolkit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c566c61424196fc07b88b6299807039f6d543a9d2caf9482fd68dae401e3c36
MD5 db2b4b73341fc1bd62440eaafd6b096e
BLAKE2b-256 cd9bd3b8d2ed50ca527cfeeab45ef6e9d6a2ade7ebfc596786617cbc61ee58b7

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