Export python objects as dictionnaries so they can then be easily serializable.
Project description
Python-todict allows you to easily turn any python object into a dictionary. It can then be easily serialized, to json for example. The class of the object you want to convert needs to inherit from two mixin classes and hold an attribute listing the attributes to export. List, dict, tuple and set attributes are supported and any attribute object that implements the mixins are recursively converted.
Usage
>>> from todict.mixins import ToDictMixin, FromDictMixin
>>> class MyClass(ToDictMixin, FromDictMixin):
... TO_SERIALIZE = ["my_attr"]
... def __init__(self):
... self.my_attr = "data"
...
>>> MyClass().to_dict()
{'my_attr': 'data'}
>>> restored_obj = MyClass.from_dict({'my_attr': 'test'})
>>> getattr(restored_obj, "my_attr")
'test'
Installation
Python-todict can be installed with pip:
$ pip install todict
Launch tests
>>> pip install -r requirements-dev.txt >>> tox
Python: 2.7, 3.6.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file todict-0.2.4.tar.gz.
File metadata
- Download URL: todict-0.2.4.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82976c9f91f0884319107f27f5749116302f6e6e8a4a5f9edf9d9ff1b838535f
|
|
| MD5 |
eb61a8889ed3ff4feb412bd09e7752c0
|
|
| BLAKE2b-256 |
4054fa1b2bb35b70746dc69cde99fcf645169a046e7f9d4ef0f4a9b53b923b73
|
File details
Details for the file todict-0.2.4-py3-none-any.whl.
File metadata
- Download URL: todict-0.2.4-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eba76958dde393d9cc3caccb613564cd9e81f8db79c3f67f8b43d168d4ad6603
|
|
| MD5 |
708c74f6d2ba65d94030dc5f84e64fd5
|
|
| BLAKE2b-256 |
976ff7616c2569a71551fa01bbdf2de791be1b6370b49d7ddf7131069e79d6c9
|