dataclass-wizard 0.36.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dataclass_wizard/__init__.py +148 -0
- dataclass_wizard/__version__.py +14 -0
- dataclass_wizard/abstractions.py +680 -0
- dataclass_wizard/abstractions.pyi +850 -0
- dataclass_wizard/bases.py +582 -0
- dataclass_wizard/bases_meta.py +401 -0
- dataclass_wizard/bases_meta.pyi +109 -0
- dataclass_wizard/class_helper.py +609 -0
- dataclass_wizard/class_helper.pyi +319 -0
- dataclass_wizard/constants.py +57 -0
- dataclass_wizard/decorators.py +252 -0
- dataclass_wizard/dumpers.py +517 -0
- dataclass_wizard/enums.py +52 -0
- dataclass_wizard/environ/lookups.pyi +60 -0
- dataclass_wizard/environ/wizard.pyi +72 -0
- dataclass_wizard/errors.py +518 -0
- dataclass_wizard/errors.pyi +265 -0
- dataclass_wizard/lazy_imports.py +29 -0
- dataclass_wizard/loader_selection.py +221 -0
- dataclass_wizard/loaders.py +785 -0
- dataclass_wizard/log.py +7 -0
- dataclass_wizard/models.py +550 -0
- dataclass_wizard/models.pyi +545 -0
- dataclass_wizard/parsers.py +628 -0
- dataclass_wizard/property_wizard.py +354 -0
- dataclass_wizard/py.typed +1 -0
- dataclass_wizard/serial_json.py +194 -0
- dataclass_wizard/serial_json.pyi +202 -0
- dataclass_wizard/type_def.py +233 -0
- dataclass_wizard/utils/object_path.pyi +86 -0
- dataclass_wizard/v1/models.pyi +654 -0
- dataclass_wizard/wizard_mixins.py +303 -0
- dataclass_wizard/wizard_mixins.pyi +128 -0
- dataclass_wizard-0.36.3.dist-info/METADATA +1756 -0
- dataclass_wizard-0.36.3.dist-info/RECORD +39 -0
- dataclass_wizard-0.36.3.dist-info/WHEEL +5 -0
- dataclass_wizard-0.36.3.dist-info/entry_points.txt +2 -0
- dataclass_wizard-0.36.3.dist-info/licenses/LICENSE +16 -0
- dataclass_wizard-0.36.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Dataclass Wizard
|
|
3
|
+
~~~~~~~~~~~~~~~~
|
|
4
|
+
|
|
5
|
+
Lightning-fast JSON wizardry for Python dataclasses — effortless
|
|
6
|
+
serialization right out of the box!
|
|
7
|
+
|
|
8
|
+
Sample Usage:
|
|
9
|
+
|
|
10
|
+
>>> from dataclasses import dataclass, field
|
|
11
|
+
>>> from datetime import datetime
|
|
12
|
+
>>> from typing import Optional
|
|
13
|
+
>>>
|
|
14
|
+
>>> from dataclass_wizard import JSONSerializable, property_wizard
|
|
15
|
+
>>>
|
|
16
|
+
>>>
|
|
17
|
+
>>> @dataclass
|
|
18
|
+
>>> class MyClass(JSONSerializable, metaclass=property_wizard):
|
|
19
|
+
>>>
|
|
20
|
+
>>> my_str: Optional[str]
|
|
21
|
+
>>> list_of_int: list[int] = field(default_factory=list)
|
|
22
|
+
>>> # You can also define this as `my_dt`, however only the annotation
|
|
23
|
+
>>> # will carry over in that case, since the value is re-declared by
|
|
24
|
+
>>> # the property below.
|
|
25
|
+
>>> _my_dt: datetime = datetime(2000, 1, 1)
|
|
26
|
+
>>>
|
|
27
|
+
>>> @property
|
|
28
|
+
>>> def my_dt(self):
|
|
29
|
+
>>> # A sample `getter` which returns the datetime with year set as 2010
|
|
30
|
+
>>> if self._my_dt is not None:
|
|
31
|
+
>>> return self._my_dt.replace(year=2010)
|
|
32
|
+
>>> return self._my_dt
|
|
33
|
+
>>>
|
|
34
|
+
>>> @my_dt.setter
|
|
35
|
+
>>> def my_dt(self, new_dt: datetime):
|
|
36
|
+
>>> # A sample `setter` which sets the inverse (roughly) of the `month` and `day`
|
|
37
|
+
>>> self._my_dt = new_dt.replace(month=13 - new_dt.month,
|
|
38
|
+
>>> day=30 - new_dt.day)
|
|
39
|
+
>>>
|
|
40
|
+
>>>
|
|
41
|
+
>>> string = '''{"myStr": 42, "listOFInt": [1, "2", 3]}'''
|
|
42
|
+
>>> c = MyClass.from_json(string)
|
|
43
|
+
>>> print(repr(c))
|
|
44
|
+
>>> # prints:
|
|
45
|
+
>>> # MyClass(
|
|
46
|
+
>>> # my_str='42',
|
|
47
|
+
>>> # list_of_int=[1, 2, 3],
|
|
48
|
+
>>> # my_dt=datetime.datetime(2010, 12, 29, 0, 0)
|
|
49
|
+
>>> # )
|
|
50
|
+
>>> my_dict = {'My_Str': 'string', 'myDT': '2021-01-20T15:55:30Z'}
|
|
51
|
+
>>> c = MyClass.from_dict(my_dict)
|
|
52
|
+
>>> print(repr(c))
|
|
53
|
+
>>> # prints:
|
|
54
|
+
>>> # MyClass(
|
|
55
|
+
>>> # my_str='string',
|
|
56
|
+
>>> # list_of_int=[],
|
|
57
|
+
>>> # my_dt=datetime.datetime(2010, 12, 10, 15, 55, 30,
|
|
58
|
+
>>> # tzinfo=datetime.timezone.utc)
|
|
59
|
+
>>> # )
|
|
60
|
+
>>> print(c.to_json())
|
|
61
|
+
>>> # prints:
|
|
62
|
+
>>> # {"myStr": "string", "listOfInt": [], "myDt": "2010-12-10T15:55:30Z"}
|
|
63
|
+
|
|
64
|
+
For full documentation and more advanced usage, please see
|
|
65
|
+
<https://dcw.ritviknag.com>.
|
|
66
|
+
|
|
67
|
+
:copyright: (c) 2021-2025 by Ritvik Nag.
|
|
68
|
+
:license: Apache 2.0, see LICENSE for more details.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
__all__ = [
|
|
72
|
+
# Base exports
|
|
73
|
+
'DataclassWizard',
|
|
74
|
+
'JSONSerializable',
|
|
75
|
+
'JSONPyWizard',
|
|
76
|
+
'JSONWizard',
|
|
77
|
+
'LoadMixin',
|
|
78
|
+
'DumpMixin',
|
|
79
|
+
'property_wizard',
|
|
80
|
+
# Wizard Mixins
|
|
81
|
+
'EnvWizard',
|
|
82
|
+
'JSONListWizard',
|
|
83
|
+
'JSONFileWizard',
|
|
84
|
+
'TOMLWizard',
|
|
85
|
+
'YAMLWizard',
|
|
86
|
+
# Helper serializer functions + meta config
|
|
87
|
+
'fromlist',
|
|
88
|
+
'fromdict',
|
|
89
|
+
'asdict',
|
|
90
|
+
'LoadMeta',
|
|
91
|
+
'DumpMeta',
|
|
92
|
+
'EnvMeta',
|
|
93
|
+
# Models
|
|
94
|
+
'env_field',
|
|
95
|
+
'json_field',
|
|
96
|
+
'json_key',
|
|
97
|
+
'path_field',
|
|
98
|
+
'skip_if_field',
|
|
99
|
+
'KeyPath',
|
|
100
|
+
'Container',
|
|
101
|
+
'Pattern',
|
|
102
|
+
'DatePattern',
|
|
103
|
+
'TimePattern',
|
|
104
|
+
'DateTimePattern',
|
|
105
|
+
'CatchAll',
|
|
106
|
+
'SkipIf',
|
|
107
|
+
'SkipIfNone',
|
|
108
|
+
'EQ',
|
|
109
|
+
'NE',
|
|
110
|
+
'LT',
|
|
111
|
+
'LE',
|
|
112
|
+
'GT',
|
|
113
|
+
'GE',
|
|
114
|
+
'IS',
|
|
115
|
+
'IS_NOT',
|
|
116
|
+
'IS_TRUTHY',
|
|
117
|
+
'IS_FALSY',
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
import logging
|
|
121
|
+
|
|
122
|
+
from .bases_meta import LoadMeta, DumpMeta, EnvMeta
|
|
123
|
+
from .constants import PACKAGE_NAME
|
|
124
|
+
from .dumpers import DumpMixin, setup_default_dumper
|
|
125
|
+
from .loaders import LoadMixin, setup_default_loader
|
|
126
|
+
from .loader_selection import asdict, fromlist, fromdict
|
|
127
|
+
from .models import (env_field, json_field, json_key, path_field, skip_if_field,
|
|
128
|
+
KeyPath, Container,
|
|
129
|
+
Pattern, DatePattern, TimePattern, DateTimePattern,
|
|
130
|
+
CatchAll, SkipIf, SkipIfNone,
|
|
131
|
+
EQ, NE, LT, LE, GT, GE, IS, IS_NOT, IS_TRUTHY, IS_FALSY)
|
|
132
|
+
from .environ.wizard import EnvWizard
|
|
133
|
+
from .property_wizard import property_wizard
|
|
134
|
+
from .serial_json import DataclassWizard, JSONWizard, JSONPyWizard, JSONSerializable
|
|
135
|
+
from .wizard_mixins import JSONListWizard, JSONFileWizard, TOMLWizard, YAMLWizard
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
# Set up logging to ``/dev/null`` like a library is supposed to.
|
|
139
|
+
# http://docs.python.org/3.3/howto/logging.html#configuring-logging-for-a-library
|
|
140
|
+
logging.getLogger(PACKAGE_NAME).addHandler(logging.NullHandler())
|
|
141
|
+
|
|
142
|
+
# Setup the default type hooks to use when converting `str` (json) or a Python
|
|
143
|
+
# `dict` object to a `dataclass` instance.
|
|
144
|
+
setup_default_loader()
|
|
145
|
+
|
|
146
|
+
# Setup the default type hooks to use when converting `dataclass` instances to
|
|
147
|
+
# a JSON `string` or a Python `dict` object.
|
|
148
|
+
setup_default_dumper()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Dataclass Wizard - a set of wizarding tools for interacting with `dataclasses`
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
__title__ = 'dataclass-wizard'
|
|
6
|
+
|
|
7
|
+
__description__ = ('Lightning-fast JSON wizardry for Python dataclasses — '
|
|
8
|
+
'effortless serialization right out of the box!')
|
|
9
|
+
__url__ = 'https://github.com/rnag/dataclass-wizard'
|
|
10
|
+
__version__ = '0.36.3'
|
|
11
|
+
__author__ = 'Ritvik Nag'
|
|
12
|
+
__author_email__ = 'me@ritviknag.com'
|
|
13
|
+
__license__ = 'Apache 2.0'
|
|
14
|
+
__copyright__ = 'Copyright 2021-2025 Ritvik Nag'
|