Skip to main content

Dictipy

Dictipy creates the right dict also for nested objects using recursion, whenever the standard Python __dict__() cannot.

Python 2.7, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11 PyPI version Build Status codecov

Table of contents

  1. Motivation
  2. Usage

1. Motivation

Using get_dict makes you able to recursively get dict of nested objects without explicitly overriding __repr__() function, making it usable for other purposes. It could be useful when you have very complex nested object and you want not to override each sub-object __repr__() function. Imagine for example an operation which produces a complex object which has to be serialized and sent through a REST protocol as a json. The json.dumps() cannot execute the task if the argument object is not a dict. Again, using simply the standard Python __dict__() function does not solve the problem if a nested object has to be considered.

2. Usage

Simply import get_dict function from dictipy and use it on any potentially serializable object.


Example 1: Nested objects.

from dictipy import dictipy


class Parent:

    def __init__(self, parent_field):
        self.parent_field = parent_field
        self.child = Child(1)


class Child:

    def __init__(self, child_field):
        self.child_field = child_field


if __name__ == "__main__":
    p = Parent(0)
    print("Standard Python dict:  ", p.__dict__)
    print("Python vars:  ", vars(p))
    print("Dictipy get_dict:      ", dictipy(p))

Result:

Standard Python dict:   {'parent_field': 0, 'child': <__main__.Child object at 0x0000021C530BFEB8>}
Python vars:   {'parent_field': 0, 'child': <__main__.Child object at 0x0000021C530BFEB8>}
Dictipy get_dict:       {'parent_field': 0, 'child': {'child_field': 1}}

Example 2: Json serialization.

from dictipy import dictipy
import json


class Parent:

    def __init__(self, parent_field):
        self.parent_field = parent_field
        self.child = Child(1)


class Child:

    def __init__(self, child_field):
        self.child_field = child_field


if __name__ == "__main__":
    p = Parent(0)
    j1 = json.dumps(p) # throws -> TypeError: Object of type Parent is not JSON serializable
    j2 = json.dumps(p.__dict__) # throws -> TypeError: Object of type Child is not JSON serializable
    j3 = json.dumps(vars(p)) # throws -> TypeError: Object of type Child is not JSON serializable
    j4 = json.dumps(dictipy(p)) # returns -> '{"parent_field": 0, "child": {"child_field": 1}}'

Metadata

Release files for dictipy 0.0.4

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

Built distributions (wheels)

Table of built distributions (wheels) for dictipy 0.0.4
File Interpreter ABI Platform
dictipy-0.0.4-py3.8.egg Legacy Egg format - - Details
dictipy-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 7.7 kB

Release files / dictipy-0.0.4-py3.8.egg

Download URL dictipy-0.0.4-py3.8.egg
Size 3.9 kB
Tags Egg
SHA-256 checksum
How to use checksums
f0600741ea74a2eec92e88f818bbc1841d289b1e0b794f59a486fbd438a7361e
BLAKE2b-256 checksum
How to use checksums
74d8086240997f2cb9d00da6c7a3951a5b75c4af3baeb009dc8aab6beaaa515a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.0

Release files / dictipy-0.0.4-py3-none-any.whl

Download URL dictipy-0.0.4-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01c35443d1f57df9484e0935598790e8c958c763eed8f006c2ddd65356227ceb
BLAKE2b-256 checksum
How to use checksums
dcee10d065b2788a69185f6ddc4a58a4d53b7de789669f9abbc5e81491a0bc8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.0

Security for dictipy 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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