Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Minimal, pythonic JSON to class serializer with zero dependencies.

License

NotificationsYou must be signed in to change notification settings

adhaamehab/jsonabc

Repository files navigation

Json Abstract Base Class

JSONABC is a minimal, pythonic JSON to class serializer. It haszero dependencies which makes it very lightweight. It provide a very minimal API with few options and play nicely with python type checking.

Install

pip install jsonabc

Examples

example 1 (simple)

fromjsonabcimportJSONABC# All you need to do is define JSONABC as your metaclassclassResponse(metaclass=JSONABC):args:dictheaders:dictorigin:strurl:strresp=requests.get("https://httpbin.org/get")json_data=resp.json()# Your class can now take a single dict and automatically validate and parse it.obj=Response(response)# obj attributes now have their correspondent values from our json data.# you can also convert your class back to its json form.# JSONABC will preserve the same names for the original json keys.print(obj.json())

example 2 (composite)

fromjsonabcimportJSONABC# You can also define composite values instead of using dictsclassHeaders(metaclass=JSONABC):accept:straccept_encoding:strclassResponse(metaclass=JSONABC):args:dictheaders:Headersorigin:strurl:strresp=requests.get("https://httpbin.org/get")json_data=resp.json()obj=Response(response)# headers attr is now an instance of Headers with the same behavior as Responseobj.headers

About

Minimal, pythonic JSON to class serializer with zero dependencies.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp