Skip to main content

No project description provided

Project description

serpyco-rs: a serializer for python dataclasses

PyPI version Python versions CI status

What is serpyco-rs ?

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

import dataclasses
import serpyco_rs

@dataclasses.dataclass
class Example:
    name: str
    num: int
    tags: list[str]


serializer = serpyco_rs.Serializer(Example)

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

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

serpyco-rs works by analysing the dataclass fields and can recognize many types : list, tuple, Optional... You can also embed other dataclasses in a definition.

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

Installation

Use pip to install:

$ pip install serpyco-rs

Features

  • Serialization and unserialization of dataclasses
  • Validation of input/output data
  • Very fast
  • Support recursive schemas

Supported field types

There is support for generic types from the standard typing module:

  • Decimal
  • UUID
  • Time
  • Date
  • DateTime
  • Enum
  • List
  • Dict
  • Mapping
  • Sequence
  • Tuple (fixed size)

Benchmark

macOS Monterey / Apple M1 Pro / 16GB RAM / Python 3.11.0

dump

Library Median latency (milliseconds) Operations per second Relative (latency)
serpyco_rs 0.05 22188.2 1
serpyco 0.05 20878.5 1.06
mashumaro 0.06 15602.7 1.42
pydantic 2.66 375.6 59
marshmallow 1.05 951.7 23.33

load with validate

Library Median latency (milliseconds) Operations per second Relative (latency)
serpyco_rs 0.23 4400.1 1
serpyco 0.28 3546.4 1.24
mashumaro 0.23 4377.7 1.01
pydantic 2.01 497.3 8.86
marshmallow 4.55 219.9 20.03

load (only serpyco and serpyco_rs supported load without validate)

Library Median latency (milliseconds) Operations per second Relative (latency)
serpyco_rs 0.07 13882.9 1
serpyco 0.08 12424.5 1.12
mashumaro 0.23 4382.9 3.17
pydantic 2.02 494.4 28.09
marshmallow 4.59 217.5 63.8

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_rs-0.2.2.tar.gz (32.1 kB view hashes)

Uploaded Source

Built Distributions

serpyco_rs-0.2.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

serpyco_rs-0.2.2-cp311-none-win_amd64.whl (182.2 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

serpyco_rs-0.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

serpyco_rs-0.2.2-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (594.7 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

serpyco_rs-0.2.2-cp310-none-win_amd64.whl (182.2 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

serpyco_rs-0.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

serpyco_rs-0.2.2-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (594.7 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

serpyco_rs-0.2.2-cp39-none-win_amd64.whl (182.5 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

serpyco_rs-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

serpyco_rs-0.2.2-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (595.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

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