Skip to main content

Package for serializing python object & dataclasses

Project description

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.

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

py-serializer-0.9.6.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

py_serializer-0.9.6-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file py-serializer-0.9.6.tar.gz.

File metadata

  • Download URL: py-serializer-0.9.6.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for py-serializer-0.9.6.tar.gz
Algorithm Hash digest
SHA256 9315d10697a6901226e1dda13289e0b57fc9fab3a260162a1ef4ac214afddd19
MD5 58b3346bd503a5d03c8af05651fbf372
BLAKE2b-256 6ddc3fe8679b1d015c0afd3304bcd51685de4854482a33a2e80fd8ecc89d791c

See more details on using hashes here.

File details

Details for the file py_serializer-0.9.6-py3-none-any.whl.

File metadata

  • Download URL: py_serializer-0.9.6-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for py_serializer-0.9.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e751f43f882cfcffe50ae0209fe684c2a059c6e9e1771825342cb49796d04f38
MD5 278bff25dab3d0bc98dea11006b4ff26
BLAKE2b-256 6a7f0e2f677a90eeec36d538d6eaee5f766b83905a624a78c7f1e119213a6ad1

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