A simple deserialization library, based on dataclasses and type-hints
Project description
dataclass-deser
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
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
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1be3ccfeb6e91130dec95e5e7f8723c7babc9fd81489c3d0018f2eb0f9ea8c7 |
|
MD5 | 27460740fe3e2bdfd5c5ab40056f9bf8 |
|
BLAKE2b-256 | a903a3550109a92619434981ac5c98d22169fa1b9d50fa882d5854aa7abc30ef |
File details
Details for the file dataclass_deser-0.1.0a2-py3-none-any.whl
.
File metadata
- Download URL: dataclass_deser-0.1.0a2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71f2315109a73272faba07ac8d5441102758962f92e5bbcd24e1faedd185345b |
|
MD5 | 3d09f66ab588ebb9543ce73ba7ccd61b |
|
BLAKE2b-256 | 044c5fae873faaddeade82f2b72e6b9b930b40ac233b5bbd04bacbc5569a2922 |