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 details)

Uploaded Source

Built Distribution

dataclass_deser-0.1.0a2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file dataclass-deser-0.1.0a2.tar.gz.

File metadata

  • Download URL: dataclass-deser-0.1.0a2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for dataclass-deser-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 d1be3ccfeb6e91130dec95e5e7f8723c7babc9fd81489c3d0018f2eb0f9ea8c7
MD5 27460740fe3e2bdfd5c5ab40056f9bf8
BLAKE2b-256 a903a3550109a92619434981ac5c98d22169fa1b9d50fa882d5854aa7abc30ef

See more details on using hashes here.

File details

Details for the file dataclass_deser-0.1.0a2-py3-none-any.whl.

File metadata

File hashes

Hashes for dataclass_deser-0.1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 71f2315109a73272faba07ac8d5441102758962f92e5bbcd24e1faedd185345b
MD5 3d09f66ab588ebb9543ce73ba7ccd61b
BLAKE2b-256 044c5fae873faaddeade82f2b72e6b9b930b40ac233b5bbd04bacbc5569a2922

See more details on using hashes here.

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