Skip to main content

jstruct

An eloquent and opinionated python library for nested object models definition offering simple serialization and deserialization into python dictionaries.

JStruct Codacy Badge Code style: black License: MIT

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

Contribute

Contributors are welcomed.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Metadata

Release files for jstruct 2021.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for jstruct 2021.11
File Interpreter ABI Platform
jstruct-2021.11-py3-none-any.whl Python 3 none any Details

Release files / jstruct-2021.11-py3-none-any.whl

Download URL jstruct-2021.11-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b1a7f3f88e34051b372953e0e6f88c465ddd84cdd7e15e5de10a8eeb6863485
BLAKE2b-256 checksum
How to use checksums
b523f99cc3785451817849451e0f9fb0f1cc3045ed8f5d2e49292fdced474579
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.6

Release history Release notifications | RSS feed

This release

2021.11 This release

1 release file

2021.7

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page