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.0.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.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dataclass_toolkit-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 2b1317935601cdc4fd0c3b4596d82a9b70f5a0f4d496478a35712156504ef232
MD5 3cde72322185d18ef8ac023031667e64
BLAKE2b-256 d82eb0f4976a57ae43e231c8b8daa9a4b6c0d451ec4c2bdb33b9d43c22d71dbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dataclass_toolkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dbf71c86edfcc18434c0abb59b7aa9e200dd7c200beed2fa0046928278105c81
MD5 474ff5c6ac6193609e95efb67934c689
BLAKE2b-256 7e0af31db63ccaa97a811f65e0e0b9c69f9365bf0d78b77d329040bca68c39e2

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