Metadata-Version: 2.1
Name: to-dict
Version: 0.0.5
Summary: to_dict
Home-page: https://github.com/kkristof200/py_todict
Author: Kristof
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.5
Description-Content-Type: text/markdown

# py_todict

## Install
~~~~shell
pip install to_dict
# or
pip3 install to_dict
~~~~

## Usage
~~~~python
from enum import Enum
import json

from to_dict import Dictable

class E(Enum):
    test = 'test_val'

class D:
    def __init__(self):
        self.val = 'str_val'

class C:
    def __init__(self):
        self.d1 = D()
        self.d2 = D()

class B(Dictable):
    def __init__(self, vals: list):
        self.vals = vals

class A(Dictable):
    def __init__(self):
        self.a = 5
        self.b = 'b'
        self.c = E.test
        self.d = C()
        self.e = [B([996, 997]), B([998, 999])]
        self.f = {'key_1': B([996, 997]), 'key_2': B([998, 999])}

print(A().dict)
# Outputs: {'a': 5, 'b': 'b', 'c': <E.test: 'test_val'>, 'd': <__main__.C object at 0x102afa1d0>, 'e': [{'vals': [996, 997]}, {'vals': [998, 999]}], 'f': {'key_1': {'vals': [996, 997]}, 'key_2': {'vals': [998, 999]}}}

print(json.dumps(A().json, indent=4))
# Outputs: 
# {
#     "a": 5,
#     "b": "b",
#     "c": "test_val",
#     "d": {
#         "d1": {
#             "val": "str_val"
#         },
#         "d2": {
#             "val": "str_val"
#         }
#     },
#     "e": [
#         {
#             "vals": [
#                 996,
#                 997
#             ]
#         },
#         {
#             "vals": [
#                 998,
#                 999
#             ]
#         }
#     ],
#     "f": {
#         "key_1": {
#             "vals": [
#                 996,
#                 997
#             ]
#         },
#         "key_2": {
#             "vals": [
#                 998,
#                 999
#             ]
#         }
#     }
# }
~~~~


