Skip to main content

Python-todict

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.

Metadata

Release files for todict 0.2.4

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

Source distribution (sdist)

Source distribution for todict 0.2.4
File Size Uploaded
todict-0.2.4.tar.gz 2.3 kB Details

Built distribution (wheel)

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

Total release size: 5.8 kB

Release files / todict-0.2.4.tar.gz

Download URL todict-0.2.4.tar.gz
Size 2.3 kB
Tags Source
SHA-256 checksum
How to use checksums
82976c9f91f0884319107f27f5749116302f6e6e8a4a5f9edf9d9ff1b838535f
BLAKE2b-256 checksum
How to use checksums
4054fa1b2bb35b70746dc69cde99fcf645169a046e7f9d4ef0f4a9b53b923b73
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / todict-0.2.4-py3-none-any.whl

Download URL todict-0.2.4-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eba76958dde393d9cc3caccb613564cd9e81f8db79c3f67f8b43d168d4ad6603
BLAKE2b-256 checksum
How to use checksums
976ff7616c2569a71551fa01bbdf2de791be1b6370b49d7ddf7131069e79d6c9
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

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