Skip to main content

A simple deserialization library, based on dataclasses and type-hints

Project description

dataclass-deser PyPI - Version

A simple deserialization library for python based on dataclasses and type hints.

I've written this code repeatedly across several of my scripts, so I've decided to publish it to PyPi for reuse.

Basic Example

@dataclass
class Nested:
    foo: int

@dataclass
class Foo:
    bar: int
    baz: list[int]
    nested: Nested

raw_json = """{
    "bar": 3,
    "baz": [1, 2, 8],
    "nested": {"foo": 42}
}"""
expected = Foo(
    bar=3,
    baz=[1, 2, 8],
    nested=Nested(foo=42)
)

ctx = dataclass_deser.DeserContext()
assert expected == ctx.deser(Foo, json.loads(raw_json))

Status

WARNING: This library is ALPHA qUaLitY

  • Basic primitive deserialization
    • Support lossless numeric conversions (int -> float)
    • Support lossy numeric conversion
  • Support for optional types
  • Support for union types (int | str | bytes)
  • Configuration options
    • Allow unused keys
  • Extensibility
    • Field options via dataclass field.metadata
    • Newtype wrappers
  • Support more collections
    • Dictionaries
    • Tuples
    • Sets
  • Support enumerations

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

dataclass-deser-0.1.0a2.tar.gz (7.7 kB view hashes)

Uploaded Source

Built Distribution

dataclass_deser-0.1.0a2-py3-none-any.whl (5.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