Readable serializable and deserializable Python nested models
Project description
jstruct
An eloquent and opinionated python library for nested object models definition offering simple serialization and deserialization into python dictionaries.
Why
The deserialization of JSON or yaml into python data types is a common practice useful in many ways.
- Configuration file reading and writing
- REST API message response generation and request processing
- Object-Document Mapping for a document store
- Data import parsing or export generation
How
JStruct
leverage attrs the great Classes without boilerplate
library to define structs without boilerplate.
What
The result is a simple and intuitive syntax familiar to a pythonista that brings Validation
, Deserialization
and Serialization
.
Requirements
- Python 3.6 and +
Installation
Install using pip
pip install jstruct
Usage
import attr
from typing import List
from jstruct import struct, JList
@struct
class Person:
first_name: str
last_name: str
@struct
class RoleModels:
scientists: List[Person] = JList[Person]
payload = {
"scientists": [{"first_name": "John", "last_name": "Doe"}]
}
role_models = RoleModels(**payload)
print(role_models)
# RoleModels(scientists=[Person(first_name='John', last_name='Doe')])
print(attr.asdict(role_models))
# {'scientists': [{'first_name': 'John', 'last_name': 'Doe'}]}
Authors
- Daniel K. - @DanHK91 | https://danielk.xyz
Contribute
Contributors are welcomed.
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for jstruct-2020.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86257c1332e1ba6983d78e3199fb3dcadaf742e96c3c1a97f3ba322fa241f89c |
|
MD5 | 9477940ffa414007829d381de459c2d5 |
|
BLAKE2b-256 | 90f36df005850585542fe15cab1df2c1c4a39c8cbfa727ad90837e43a3eca0f7 |