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

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"]))

{'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.


  • Serialization and unserialization of dataclasses
  • Validation of input/output data
  • Very fast
  • Extensible through custom encoders


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


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

serpyco-1.3.9.tar.gz (39.9 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page