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.3.tar.gz (5.1 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.3-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dataclass_toolkit-0.1.3.tar.gz
  • Upload date:
  • Size: 5.1 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.3.tar.gz
Algorithm Hash digest
SHA256 1c58bfe625ffa038dc11aba91805f70f7452c577a02ecd18cff2b1fb95ee3d2e
MD5 2ebea32f71e67ec619eba34a4290dbf9
BLAKE2b-256 9520dd8c33202c0da250ba29be4591585d59d9cd462bbb84c1a5c370e9bcb552

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dataclass_toolkit-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d6b31af8e0f9de960e582dfd59992591433632e7caf57ea0a518579d7c59a9a5
MD5 62e6be843553068e34af88749b4f5951
BLAKE2b-256 25020c7179872aec6afb12d0019968050c55482fab877ce7b7c5089b00a449ef

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