Skip to main content

Simple, fast, and space-efficient (de)serialization for simple Python classes

Project description

Miniserial

Miniserial is a Python package for dead-simple, space-efficient serialization and deserialization of simple dataclasses. There are many great packages for general purpose serialization in the standard library and on PyPI (e.g. json, marshal, pickle, ujson, bson, etc.), but most use serialization formats that can come with significant byte overhead. Sometimes, project constraints—like the 256-byte-max-packet radio devices that inspired this package—encourage the use of a much more compact format, something akin to protobuf or the layout of C structs. But libraries in this space typically come with the overhead of implementing manual serializers, modifying class fields with various wrappers, or using non python data specifications (e.g. .proto files).

Miniserial makes compact serialization easy. Simply have your dataclass inherit from the Serialization mixin, and serialize and deserialize methods will be automatically generated for the class. For example:

from dataclasses import dataclass
from miniserial import Serializable

@dataclass
class Person(Serializable):
    name   : str
    age    : int
    titles : list[str]
    balance: float
    
p = Person("Bob", 34, ["Mr.", "Dr.", "Professor"], 239847.25)
assert Person.deserialize(p.serialize()) == p

Classes that inherit the Serializable mixin must be dataclasses composed of fields annotated with simple types.

Documentation of supported types and the serialization format is on the way. For now, bool, int, float, str, and list are supported. int and float are taken to be 32 bit values. Support for more types, including int64, float64, etc. from numpy are on the horizon.

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

miniserial-0.1.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

miniserial-0.1.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: miniserial-0.1.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for miniserial-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9bbee9f5b0c0e35ec56ba7d5b5f98fd3d14687d4477ca53edccddff819f0dbf2
MD5 05c103a67eca706a5ea6629df7dee1ab
BLAKE2b-256 4b76f828390ff08b75305171bac9b8f7c8ddb38c0052e77d125b8fef50a09005

See more details on using hashes here.

File details

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

File metadata

  • Download URL: miniserial-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for miniserial-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 500edda7bf623d657ede74ac94538904d6219f3bf8669ae4a343f2df322907e5
MD5 0e99ee7b38a5a57ee77cd3af49b4034d
BLAKE2b-256 60431618614de5b40ae38c9032200fcda0f35456df65c2fed0bbc8ea8377dc43

See more details on using hashes here.

Supported by

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