Serialize and deserialize using type hints
Project description
serializepy: typed deserialization
File issues here: Issues tracker
Motivation
serializepy inspects the type-hints of self-assignments in class-constructors, and constructs the type from a given dictionary. The goal is to support this work recursively for large and complex (typed) hierarchies.
Installation
Install serializepy with pip:
$ python3 -m pip install serializepy
Usage
# Example class hierarchy
class B():
def __init__(self, b: int) -> None:
self.b: int = b
class A():
def __init__(self, a: int, b: B) -> None:
self.a: int = a
self.b: B = b
# Data that we want to fit the above hierarchy, possibly from json.load(..)
d = {
'a': 1,
'b': {
'b': 2
}
}
# Deserialization and assertion
obj: A = deserialize(A, d)
assert isinstance(obj, A)
assert obj.a == 1
assert isinstance(obj.b, B)
assert obj.b.b == 2
License
serializepy is licensed under the terms of the MIT License (see the LICENSE file).
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
serializepy-0.0.1.tar.gz
(4.9 kB
view hashes)
Built Distribution
Close
Hashes for serializepy-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8e76cd0f4c153bea76d08c9a205e16d456e678adc88f4e676e0e8bbb18f26c1 |
|
MD5 | 810808da34a9668bb187631cf03901a0 |
|
BLAKE2b-256 | d02fdc51daa4f045313eeb1489db3bfb55df1af0a7e52559f5ab4a279edd8f52 |