Skip to main content

Fast and flexible serialization library.

Project description

perde: python-wrapped serde

Heavily under construction towards 0.1.0 🎅

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. License PyPi Supported python versions Actions Status codecov

Python wrapper around the powerful Rust serialization framework.

  • Serialization & deserialization of python data structures.
  • Supports various types including dataclasses, generic types, enum and common built-in types.
  • Supports various serialization formats. By design, perde can support as many format as serde can.
  • Provides string case conversion of field names, skipping serialization/deserialization options, structure flattening.
  • Precise type checking based on type hints.
  • Very fast.

Install

pip install perde

Usage

>>> import perde

Assume you have a dataclass,

>>> @dataclass
... class A:
...     a: int
...     b: str

To serialize class A to JSON,

>>> perde.json.dumps(A(a=10, b='x'))
'{"a":10,"b":"x"}'

To deserialize JSON to class A,

>>> perde.json.loads_as(A, '{"a":10,"b":"x"}')
A(a=10, b='x')

To deserialize JSON to a dictionary,

>>> perde.json.loads('{"a":10,"b":"x"}')
{'a': 10, 'b': 'x'}

More formats are supported.

>>> perde.yaml.dumps(A(10, "x"))
'---\na: 10\nb: x'
>>> perde.yaml.loads_as(A, '---\na: 10\nb: x')
A(a=10, b='x')
>>> perde.msgpack.dumps(A(10, "x"))
b'\x82\xa1a\n\xa1b\xa1x'
>>> perde.msgpack.loads_as(A, b'\x82\xa1a\n\xa1b\xa1x')
A(a=10, b='x')

Supported formats

  • JSON (perde.json)
  • YAML (perde.yaml)
  • MessagePack (perde.msgpack)
  • TOML (perde.toml)
  • CBOR
  • Pickle
  • RON
  • BSON
  • Avro
  • JSON5
  • Postcard
  • URL
  • Environment variables
  • AWS Parameter Store
  • S-expressions
  • D-Bus
  • FlexBuffer
  • XML

Supported types

  • dataclass
  • Primitive types
    • int
    • str
    • float
    • bool
    • bytes
    • bytearray
  • Generic types
    • dict /typing.Dict
    • list / typing.List
    • set / typing.Set
    • frozenset / typing.FrozenSet
    • tuple / typing.Tuple
    • typing.Optional
    • typing.Union
    • typing.Any
  • Enum types
    • Enum
    • IntEnum
    • Flag
    • IntFlag
  • More built-in types
    • datetime.datetime
    • datetime.date
    • datetime.time
    • decimal.Decimal
    • uuid.UUID

Attributes

Attributes allow to modify the way of serialization/deserialization.

For example, to serialize/deserialize the field names as camelCase,

>>> @perde.attr(rename_all="camelCase")
... @dataclass
... class A:
...     foo_bar: int
...     bar_bar: int

>>> perde.json.dumps(A(foo_bar=1, bar_bar=2))
'{"fooBar":1,"barBar":2}'
>>> perde.json.loads_as(A, '{"fooBar":1,"barBar":2}')
A(foo_bar=1, bar_bar=2)

See the book for more details.

Benchmark

JSON

YAML

TOML

MessagePack

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

perde-0.0.2.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distributions

perde-0.0.2-cp39-none-win_amd64.whl (550.7 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

perde-0.0.2-cp39-cp39-manylinux2010_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

perde-0.0.2-cp39-cp39-macosx_10_7_x86_64.whl (660.6 kB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

perde-0.0.2-cp38-none-win_amd64.whl (550.7 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

perde-0.0.2-cp38-cp38-manylinux2010_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

perde-0.0.2-cp38-cp38-macosx_10_7_x86_64.whl (660.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.7+ x86-64

perde-0.0.2-cp37-none-win_amd64.whl (550.7 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

perde-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

perde-0.0.2-cp37-cp37m-macosx_10_7_x86_64.whl (660.6 kB view hashes)

Uploaded CPython 3.7m macOS 10.7+ x86-64

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