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). msgpack comes close, but does not work out of the box with classes.
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 supported types, which include any other class which
inherits Serializable. This means that even recursive structures,
like trees, can be serialized and deserialized.
from __future__ import annotations
from dataclasses import dataclass
from miniserial import Serializable
@dataclass
class Node(Serializable):
value : int
children: list[Node]
# 1
# / \
# 2 3
# / \
# 4 5
tree = Node(1, [Node(2, [Node(4, []), Node(5, [])]), Node(3, [])])
assert Node.deserialize(tree.serialize()) == tree
Documentation of supported types and the serialization format is on the way. For
now, bool, int, float, str, and subclasses of collections.abc.Collection
(e.g. list, set, tuple) are supported, along with any other user-defined
class that inherits Serializable. int and float are taken to be 32 bit
values. Support for more types, including int64, float64, etc. from numpy
are on the horizon.
Metadata
Release files for miniserial 0.2.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| miniserial-0.2.6.tar.gz | 5.9 kB | Without provenance | Details for miniserial-0.2.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| miniserial-0.2.6-py3-none-any.whl | Python 3 | none | any | Details for miniserial-0.2.6-py3-none-any.whl |
Total release size: 11.0 kB
Release files / miniserial-0.2.6.tar.gz
| Download URL | miniserial-0.2.6.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e43d907fc2df8b3baf2eb38c74db4a76133ac973efb41276716d66acad16ca14
|
|
BLAKE2b-256 checksum How to use checksums |
09d37f785c4498922afa752ef434fc8f4090dbfd16e7276636f6547d6b7702fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|
Release files / miniserial-0.2.6-py3-none-any.whl
| Download URL | miniserial-0.2.6-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aeb9c00b14f1c3ecae9717b50ad306210267a2f00a99bdc374c8784c4a68fcd2
|
|
BLAKE2b-256 checksum How to use checksums |
a5b4d6c731b1144897cb5141c1f640e510537e551eb8808f4b2ddf2de613f61c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|
Security for miniserial 0.2.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.