Skip to main content

Serialization library on top of dataclasses.

Project description

pyserde

image Build Status Build status Coverage Status

Serialization library on top of dataclasses.

Installation

$ pip install pyserde

QuickStart

You can serialize/deserialize your class to/from various message formant (e.g. Json, MsgPack) quite easily!

# main.py
# /usr/bin/env python

from dataclasses import dataclass
from serde import deserialize, serialize
from serde.json import from_json, to_json

# Mark the class serializable/deserializable.
@deserialize
@serialize
@dataclass
class Hoge:
    i: int
    s: str
    f: float
    b: bool

h = Hoge(i=10, s='hoge', f=100.0, b=True)

print(f"Into Json: {to_json(h)}")

s = '{"i": 10, "s": "hoge", "f": 100.0, "b": true}'

print(f"From Json: {from_json(Hoge, s)}")
$ python main.py
Into Json: {"i": 10, "s": "hoge", "f": 100.0, "b": true}
From Json: Hoge(i=10, s='hoge', f=100.0, b=True)

Features

  • Data format
  • Class attributes
    • Case conversion e.g. camelCase, kebab-case

Documentation

https://yukinarit.github.io/pyserde/

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyserde-0.0.7.tar.gz (12.8 kB view hashes)

Uploaded Source

Built Distribution

pyserde-0.0.7-py3-none-any.whl (16.9 kB view hashes)

Uploaded Python 3

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