Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

A package to easily convert between Python objects and JSON-compatible dictionaries, with built-in type conversion.

Project description

py-jobject

A package to easily convert between Python objects and JSON-compatible dictionaries, with built-in type conversion.

Usage

  • Declare a class with type-annotated attributes:
class MyObject:

    foo: int
    bar: str
  • Convert to a dict object:
from py_jobject import to_dict

obj = MyObject()
obj.foo = 123
obj.bar = 'abc'

my_dict = to_dict(obj)

assert my_dict == {
   'foo': 123,
   'bar': 'abc'
}
  • Convert from a dict object:
from py_jobject import from_dict

my_dict = {
    'foo': 123,
    'bar': 'abc'
}

obj = from_dict(obj, MyObject)

assert obj.foo == 123
assert obj.bar == 'abc'

Features

  • Supports type conversion:
from py_jobject import from_dict

my_dict = {
    'foo': '123',
}

obj = from_dict(obj, MyObject)

assert obj.foo == 123

Project details


Release history Release notifications

This version

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for py-jobject, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size py_jobject-0.1.0-py3-none-any.whl (16.7 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size py-jobject-0.1.0.tar.gz (5.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page