Skip to main content

Fast serialization of dataclasses using Cython

Project description

What is Serpyco ?

Serpyco is a serialization library for Python 3.6+ dataclasses that works just by defining your dataclasses:

import dataclasses
import typing

import serpyco

@dataclasses.dataclass
class Example(object):
    name: str
    num: int
    tags: typing.List[str]


serializer = serpyco.Serializer(Example)

result = serializer.dump(Example(name="foo", num=2, tags=["hello", "world"]))
print(result)

{'name': 'foo', 'num': 2, 'tags': ['hello', 'world']}

Serpyco works by analysing the dataclass fields and can recognize many types : List, Set, Tuple, Optional, Union… You can also embed other dataclasses in a definition.

The main use-case for Serpyco is to serialize objects for an API, but it can be helpful whenever you need to transform objects to/from builtin Python types.

Features

  • Serialization and unserialization of dataclasses

  • Validation of input/output data

  • Very fast

  • Extensible through custom encoders

Installing

Serpyco is best installed via pip:

pip install serpyco

It has only 3 (4 with python 3.6 dataclasses backport) dependencies:

  • rapid-json: used for data validation and fast JSON dump/load

  • python-dateutil: used for serializing datetime objects

  • typing_inspect: used to inspect types as needed to create serializers

Documentation

Contributing

Serpyco is written using Python and Cython for parts needing speed.

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

serpycow-1.2.23.tar.gz (39.7 kB view details)

Uploaded Source

File details

Details for the file serpycow-1.2.23.tar.gz.

File metadata

  • Download URL: serpycow-1.2.23.tar.gz
  • Upload date:
  • Size: 39.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.16

File hashes

Hashes for serpycow-1.2.23.tar.gz
Algorithm Hash digest
SHA256 7a68a6644e88f9e9e7c6ee21f86bae617c9c633122d0adb24e147b7d4587f8d7
MD5 6174a9bc647ee29e3514c74fbd6acb1e
BLAKE2b-256 3a71e0d488c96eba53e80708cf33a9dccd9f0b947c40cefd68b66474fec66eee

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