A base class to get well-formatted serialized representations of child classes
Project description
serialclass
A base class to get serialized representations of any Python class
Install
pip install serialclass
Usage
from serialclass import SerialClass
class InnerClass(SerialClass):
def __init__(self, id_key):
self.id_key = id_key
class Outerclass(SerialClass):
def __init__(self):
self._attribute = 'attribute'
self._list = ['a', 'list']
self._dict = {1: InnerClass('a'), 2: InnerClass('b')}
outclass = Outerclass()
outclass.serialize() # dict
>>>> {'Outerclass': {'_attribute': 'attribute', '_dict': {1: {'InnerClass': {'id_key': 'a'}}, 2: {'InnerClass': {'id_key': 'b'}}}, '_list': ['a', 'list']}}'
outclass.serialize(depth=1) # do not recurse
>>>> {'Outerclass': {'_attribute': 'attribute', '_dict': {1: <__main__.InnerClass object at 0x000001DC95C800C8>, 2: <__main__.InnerClass object at 0x000001DC95C801C8>}, '_list': ['a', 'list']}}
outclass.stringify() # json string
>>>> {"Outerclass": {"_attribute": "attribute", "_dict": {"1": {"InnerClass": {"id_key": "a"}}, "2": {"InnerClass": {"id_key": "b"}}}, "_list": ["a", "list"]}}
outclass.pstringify(indent=2) # json string with indent (default=4)
>>>> {
"Outerclass": {
"_attribute": "attribute",
"_dict": {
"1": {
"InnerClass": {
"id_key": "a"
}
},
"2": {
"InnerClass": {
"id_key": "b"
}
}
},
"_list": [
"a",
"list"
]
}
}
outclass.pstringify(indent=2, ignore_protected=True)) # ignore _ - prefaced attributes
>>>> {
"Outerclass": {}
}
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
serialclass-0.0.2.121.tar.gz
(3.0 kB
view details)
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 serialclass-0.0.2.121.tar.gz.
File metadata
- Download URL: serialclass-0.0.2.121.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bba19eac5a270c4cfbe48c0087ad6b985cb153927223d7de3f95b94797be47d
|
|
| MD5 |
4c85c543317bff220fd1f48bd4e0583b
|
|
| BLAKE2b-256 |
11ee5b96f36f50ecb6c6d968fad5e55004849fe565e36b86493ab25793227f59
|
File details
Details for the file serialclass-0.0.2.121-py3-none-any.whl.
File metadata
- Download URL: serialclass-0.0.2.121-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d73aff45b01a382cdce4da338f65a809f49b8775f214446ddcd2da87eeded31d
|
|
| MD5 |
68962b04009655702f6c4be98708e3f9
|
|
| BLAKE2b-256 |
0f1c4fc7e47a5df54548cf009768334eee184ced986c1995e1c9380ae85cbbb7
|