DSerial
0. Introduction
DSerial is dictionary serializer with type checking methodology by declared type hinting
1. Requirements
python 3.7 +
2. Quick start
2.0. Installation
pip3 install dserial
2.1. Default type
{
"int_variable": 1234,
"string_variable": "string_value"
}
For serialize above dictionary, data class can be below code
class DefaultData(TypeCheckingDictSerializer):
int_variable: int
string_variable: str
and usage:
>>> dictionary = {
'int_variable': 1234,
'string_variable': 'string_value'
}
>>> data = DefaultData(dictionary)
>>> data.int_variable
1234
>>> data.string_variable
string_value
2.2. Nested type
{
"int_variable": 1234,
"string_variable": "string_value",
"nested": {
"int_variable": 4321
}
}
For serialize above dictionary, data class can be below code
class NestedData(TypeCheckingDictSerializer):
int_variable: int
class DefaultData(TypeCheckingDictSerializer):
int_variable: int
string_variable: str
nested: NestedData
and usage:
>>> dictionary = {
'int_variable': 1234,
'string_variable': 'string_value',
'nested': {
'int_variable': 4321
}
}
>>> data = DefaultData(dictionary)
>>> data.int_variable
1234
>>> data.string_variable
string_value
>>> data.nested.int_variable
4321
2.3. Repeated type
{
"int_variable": 1234,
"string_variable": "string_value",
"nested": {
"int_variable": 4321
},
"repeated": [1, 2, 3]
}
For serialize above dictionary, data class can be below code
class RepeatedData(TypeAnnotatedList):
@staticmethod
def get_type():
return int
class NestedData(TypeCheckingDictSerializer):
int_variable: int
class DefaultData(TypeCheckingDictSerializer):
int_variable: int
string_variable: str
nested: NestedData
repeated: RepeatedData
and usage:
>>> dictionary = {
'int_variable': 1234,
'string_variable': 'string_value',
'nested': {
'int_variable': 4321
},
'repeated': [1, 2, 3]
}
>>> data = DefaultData(dictionary)
>>> data.int_variable
1234
>>> data.string_variable
string_value
>>> data.nested.int_variable
4321
>>> len(data.repeated)
3
>>> data.repeated[0]
1
2.4. More complex
{
"int_variable": 1234,
"string_variable": "string_value",
"repeated_nested": [{
"int_variable": 3133
}, {
"int_variable": 1337
}]
}
For serialize above dictionary, data class can be below code
class NestedData(TypeCheckingDictSerializer):
int_variable: int
class RepeatedData(TypeAnnotatedList):
@staticmethod
def get_type():
return NestedData
class DefaultData(TypeCheckingDictSerializer):
int_variable: int
string_variable: str
repeated_nested: RepeatedData
and usage:
>>> dictionary = {
'int_variable': 1234,
'string_variable': 'string_value',
'repeated_nested': [{
'int_variable': 3133
}, {
'int_variable': 1337
}]
}
>>> data = DefaultData(dictionary)
>>> data.int_variable
1234
>>> data.string_variable
string_value
>>> len(data.repeated_nested)
3
>>> data.repeated[0].int_variable
3133
3. Test
> dserial$ python3 -m tests
Metadata
Release files for dserial 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dserial-0.0.1.tar.gz | 3.8 kB | Without provenance | Details for dserial-0.0.1.tar.gz |
Release files / dserial-0.0.1.tar.gz
| Download URL | dserial-0.0.1.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0169d3654d3dad73e8cb8e15d8dd95995de665f8e9da26bf8a3d48d8cbc048cd
|
|
BLAKE2b-256 checksum How to use checksums |
f84a65dc5fd6b7392523a41470475fe5e003ba47bad0f5ecb3a500fbcc4566a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.3
|
Security for dserial 0.0.1
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.