Skip to main content

Serializer

A serialization module for python objects

Test Upload Python Package PyPI version

Quickstart

pip install py-serializer

from typing import List
from serializer import serializable

@serializable
class Role:
    role_type: str
    attributes: List[str]

@serializable
class Person:
    name: str
    age: int
    height: float
    weight: float
    address: str
    role: List[Role]


p = Person(
    name="Paul", age=25, height=1.70, weight=83.5, address="earth",
    role=[Role(role_type='human', attributes=['speak', 'eat', 'sleep'])]
)

print(p.to_dict())
{
    'name': 'Paul', 
    'age': 25, 
    'height': 1.7,
    'weight': 83.5, 
    'address': 'earth', 
    'role': [
          {
            'role_type': 'human',
            'attributes': ['speak', 'eat', 'sleep']
          }
    ]
}

Serializable wrapper extends dataclass so you can treat it like a normal dataclass.

Mixin

It is possible to have a class extend abstract class SerializableMixin

from serializer import SerializableMixin, serializer

class Test(SerializableMixin):

    def __init__(self, name: str):
        self.name = name

    def __serialize__(self):
        return dict(name=serializer(self.name))

>> Test(name='Paul').to_dict()

{ 'name': 'Paul' }

For object to be seriazable they only need to implement a __serialize__ method.

Metadata

Release files for py-serializer 0.9.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-serializer 0.9.6
File Size Uploaded
py-serializer-0.9.6.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-serializer 0.9.6
File Interpreter ABI Platform
py_serializer-0.9.6-py3-none-any.whl Python 3 none any Details

Total release size: 11.5 kB

Release files / py-serializer-0.9.6.tar.gz

Download URL py-serializer-0.9.6.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9315d10697a6901226e1dda13289e0b57fc9fab3a260162a1ef4ac214afddd19
BLAKE2b-256 checksum
How to use checksums
6ddc3fe8679b1d015c0afd3304bcd51685de4854482a33a2e80fd8ecc89d791c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

Release files / py_serializer-0.9.6-py3-none-any.whl

Download URL py_serializer-0.9.6-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e751f43f882cfcffe50ae0209fe684c2a059c6e9e1771825342cb49796d04f38
BLAKE2b-256 checksum
How to use checksums
6a7f0e2f677a90eeec36d538d6eaee5f766b83905a624a78c7f1e119213a6ad1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

Release history Release notifications | RSS feed

This release

0.9.6 This release

2 release files

0.9.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page