python-datamodel 0.6.19__cp312-cp312-win_amd64.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.
datamodel/version.py ADDED
@@ -0,0 +1,9 @@
1
+ """DataModel Meta information."""
2
+
3
+ __title__ = 'python-datamodel'
4
+ __description__ = ('simple library based on python +3.8 to use Dataclass-syntax'
5
+ 'for interacting with Data')
6
+ __version__ = '0.6.19'
7
+ __author__ = 'Jesus Lara'
8
+ __author_email__ = 'jesuslarag@gmail.com'
9
+ __license__ = 'BSD'
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2022, phenobarbital
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,315 @@
1
+ Metadata-Version: 2.1
2
+ Name: python-datamodel
3
+ Version: 0.6.19
4
+ Summary: simple library based on python +3.8 to use Dataclass-syntaxfor interacting with Data
5
+ Home-page: https://github.com/phenobarbital/python-datamodel
6
+ Author: Jesus Lara
7
+ Author-email: jesuslarag@gmail.com
8
+ License: BSD
9
+ Project-URL: Source, https://github.com/phenobarbital/datamodels
10
+ Project-URL: Funding, https://paypal.me/phenobarbital
11
+ Project-URL: Say Thanks!, https://saythanks.io/to/phenobarbital
12
+ Keywords: asyncio,dataclass,dataclasses,data models
13
+ Platform: any
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: System Administrators
17
+ Classifier: Topic :: Software Development :: Build Tools
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3 :: Only
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Framework :: AsyncIO
25
+ Classifier: License :: OSI Approved :: BSD License
26
+ Classifier: Operating System :: OS Independent
27
+ Classifier: Topic :: System :: Systems Administration
28
+ Classifier: Topic :: Utilities
29
+ Classifier: Environment :: Web Environment
30
+ Requires-Python: >=3.9.13
31
+ Description-Content-Type: text/markdown
32
+ License-File: LICENSE
33
+ Requires-Dist: numpy ==1.24.2
34
+ Requires-Dist: uvloop ==0.19.0
35
+ Requires-Dist: asyncio ==3.4.3
36
+ Requires-Dist: faust-cchardet ==2.1.19
37
+ Requires-Dist: ciso8601 ==2.3.1
38
+ Requires-Dist: objectpath ==0.6.1
39
+ Requires-Dist: orjson ==3.9.10
40
+ Requires-Dist: typing-extensions ==4.8.0
41
+ Requires-Dist: asyncpg ==0.29.0
42
+ Requires-Dist: python-dateutil ==2.8.2
43
+ Requires-Dist: pendulum ==2.1.2
44
+ Requires-Dist: python-slugify ==8.0.1
45
+
46
+ # DataModel
47
+ DataModel is a simple library based on python +3.8 to use Dataclass-syntax for interacting with
48
+ Data, using the same syntax of Dataclass, users can write Python Objects
49
+ and work with Data in the same way (like ORM's), is a reimplementation of python Dataclasses supporting true inheritance (without decorators), true composition and other good features.
50
+
51
+ The key features are:
52
+ * **Easy to use**: No more using decorators, concerns abour re-ordering attributes or common problems with using dataclasses with inheritance.
53
+ * **Extensibility**: Can use other dataclasses, Data objects or primitives as data-types.
54
+ * **Fast**: DataModel is a replacement 100% full compatible with dataclasses, without any overhead.
55
+
56
+
57
+
58
+ ## Requirements
59
+
60
+ Python 3.8+
61
+
62
+ ## Installation
63
+
64
+ <div class="termy">
65
+
66
+ ```console
67
+ $ pip install python-datamodel
68
+ ---> 100%
69
+ Successfully installed datamodel
70
+ ```
71
+
72
+
73
+ </div>
74
+
75
+ ## Quickstart
76
+
77
+
78
+ ```python
79
+
80
+ from datamodel import Field, BaseModel
81
+ from dataclasses import dataclass, fields, is_dataclass
82
+
83
+
84
+ # This pure Dataclass:
85
+ @dataclass
86
+ class Point:
87
+ x: int = Field(default=0, min=0, max=10)
88
+ y: int = Field(default=0, min=0, max=10)
89
+
90
+ point = Point(x=10, y=10)
91
+ print(point)
92
+ print(fields(point))
93
+ print('IS a Dataclass?: ', is_dataclass(point))
94
+
95
+ # Can be represented by BaseModel
96
+ class newPoint(BaseModel):
97
+ x: int = Field(default=0, min=0, max=10)
98
+ y: int = Field(default=0, min=0, max=10)
99
+
100
+ def get_coordinate(self):
101
+ return (self.x, self.y)
102
+
103
+ point = newPoint(x=10, y=10)
104
+ print(point)
105
+ print(fields(point))
106
+ print('IS a Dataclass?: ', is_dataclass(point))
107
+ print(point.get_coordinate())
108
+ ```
109
+ ## Supported types
110
+
111
+ DataModel support recursive transformation of fields, so you can easily work with nested dataclasses or complex types.
112
+
113
+ DataModel supports automatic conversion of:
114
+
115
+ - [datetime](https://docs.python.org/3/library/datetime.html#available-types)
116
+ objects. `datetime` objects are encoded to str exactly like orjson conversion, any str typed as datetime is decoded to datetime.
117
+ The same behavior is used to decoding time, date and timedelta objects.
118
+
119
+ - [UUID](https://docs.python.org/3/library/uuid.html#uuid.UUID) objects. They
120
+ are encoded as `str` (JSON string) and decoded back to uuid.UUID objects.
121
+
122
+ - [Decimal](https://docs.python.org/3/library/decimal.html) objects. They are
123
+ also encoded as `float` and decoded back to Decimal.
124
+
125
+ Also, "custom" encoders are supported.
126
+
127
+ ```python
128
+
129
+ import uuid
130
+ from typing import (
131
+ List,
132
+ Optional,
133
+ Union
134
+ )
135
+ from dataclasses import dataclass, field
136
+ from datamodel import BaseModel, Field
137
+
138
+ @dataclass
139
+ class Point:
140
+ x: int = Field(default=0, min=0, max=10)
141
+ y: int = Field(default=0, min=0, max=10)
142
+
143
+ class coordinate(BaseModel, intSum):
144
+ latitude: float
145
+ longitude: float
146
+
147
+ def get_location(self) -> tuple:
148
+ return (self.latitude, self.longitude)
149
+
150
+ def auto_uid():
151
+ return uuid.uuid4()
152
+
153
+ def default_rect():
154
+ return [0,0,0,0]
155
+
156
+ def valid_zipcode(field, value):
157
+ return value > 1000
158
+
159
+ class Address(BaseModel):
160
+ id: uuid.UUID = field(default_factory=auto_uid)
161
+ street: str = Field(required=True)
162
+ zipcode: int = Field(required=False, default=1010, validator=valid_zipcode)
163
+ location: Optional[coordinate]
164
+ box: List[Optional[Point]]
165
+ rect: List[int] = Field(factory=default_rect)
166
+
167
+
168
+ addr = Address(street="Calle Mayor", location=(18.1, 22.1), zipcode=3021, box=[(2, 10), (4, 8)], rect=[1, 2, 3, 4])
169
+ print('IS a Dataclass?: ', is_dataclass(addr))
170
+
171
+ print(addr.location.get_location())
172
+ ```
173
+ ```console
174
+ # returns
175
+ Address(id=UUID('24b34dd5-8d35-4cfd-8916-7876b28cdae3'), street='Calle Mayor', zipcode=3021, location=coordinate(latitude=18.1, longitude=22.1), box=[Point(x=2, y=10), Point(x=4, y=8)], rect=[1, 2, 3, 4])
176
+ ```
177
+
178
+ * Fast and convenience conversion from-to JSON (using orjson):
179
+
180
+ ```python
181
+ import orjson
182
+
183
+ b = addr.json()
184
+ print(b)
185
+ ```
186
+ ```console
187
+ {"id":"24b34dd5-8d35-4cfd-8916-7876b28cdae3","street":"Calle Mayor","zipcode":3021,"location":{"latitude":18.1,"longitude":22.1}, "box":[{"x":2,"y":10},{"x":4,"y":8}],"rect":[1,2,3,4]}
188
+ ```
189
+
190
+ ```python
191
+ # and re-imported from json
192
+ new_addr = Address.from_json(b) # load directly from json string
193
+ # or using a dictionary decoded by orjson
194
+ data = orjson.loads(b)
195
+ new_addr = Address(**data)
196
+
197
+ ```
198
+
199
+ ## Inheritance
200
+
201
+ python-datamodel supports inheritance of classes.
202
+
203
+ ```python
204
+ import uuid
205
+ from typing import Union, List
206
+ from dataclasses import dataclass, field
207
+ from datamodel import BaseModel, Column, Field
208
+
209
+
210
+ def auto_uid():
211
+ return uuid.uuid4()
212
+
213
+ class User(BaseModel):
214
+ id: uuid.UUID = field(default_factory=auto_uid)
215
+ name: str
216
+ first_name: str
217
+ last_name: str
218
+
219
+
220
+ @dataclass
221
+ class Address:
222
+ street: str
223
+ city: str
224
+ state: str
225
+ zipcode: str
226
+ country: Optional[str] = 'US'
227
+
228
+ def __str__(self) -> str:
229
+ """Provides pretty response of address"""
230
+ lines = [self.street]
231
+ lines.append(f"{self.city}, {self.zipcode} {self.state}")
232
+ lines.append(f"{self.country}")
233
+ return "\n".join(lines)
234
+
235
+ class Employee(User):
236
+ """
237
+ Base Employee.
238
+ """
239
+ role: str
240
+ address: Address # composition of a dataclass inside of DataModel is possible.
241
+
242
+ # Supporting multiple inheritance and composition
243
+ # Wage Policies
244
+ class MonthlySalary(BaseModel):
245
+ salary: Union[float, int]
246
+
247
+ def calculate_payroll(self) -> Union[float, int]:
248
+ return self.salary
249
+
250
+ class HourlySalary(BaseModel):
251
+ salary: Union[float, int] = Field(default=0)
252
+ hours_worked: Union[float, int] = Field(default=0)
253
+
254
+ def calculate_payroll(self) -> Union[float, int]:
255
+ return (self.hours_worked * self.salary)
256
+
257
+ # employee types
258
+ class Secretary(Employee, MonthlySalary):
259
+ """Secretary.
260
+
261
+ Person with montly salary policy and no commissions.
262
+ """
263
+ role: str = 'Secretary'
264
+
265
+ class FactoryWorker(Employee, HourlySalary):
266
+ """
267
+ FactoryWorker is an employee with hourly salary policy and no commissions.
268
+ """
269
+ role: str = 'Factory Worker'
270
+
271
+ class PayrollSystem:
272
+ def calculate_payroll(self, employees: List[dataclass]) -> None:
273
+ print('=== Calculating Payroll === ')
274
+ for employee in employees:
275
+ print(f"Payroll for employee {employee.id} - {employee.name}")
276
+ print(f"- {employee.role} Amount: {employee.calculate_payroll()}")
277
+ if employee.address:
278
+ print('- Sent to:')
279
+ print(employee.address)
280
+ print("")
281
+
282
+ jane = Secretary(name='Jane Doe', first_name='Jane', last_name='Doe', salary=1500)
283
+ bob = FactoryWorker(name='Bob Doyle', first_name='Bob', last_name='Doyle', salary=15, hours_worked=40)
284
+ mitch = FactoryWorker(name='Mitch Brian', first_name='Mitch', last_name='Brian', salary=20, hours_worked=35)
285
+
286
+ payroll = PayrollSystem()
287
+ payroll.calculate_payroll([jane, bob, mitch])
288
+ ```
289
+ A sample of output:
290
+ ```
291
+ ```console
292
+ === Calculating Payroll ===
293
+ Payroll for employee 745a2623-d4d2-4da6-bf0a-1fa691bafd33 - Jane Doe
294
+ - Secretary Amount: 1500
295
+ - Sent to:
296
+ Rodeo Drive, Rd
297
+ Los Angeles, 31050 CA
298
+ US
299
+ ```
300
+ ## Contributing
301
+
302
+ First of all, thank you for being interested in contributing to this library.
303
+ I really appreciate you taking the time to work on this project.
304
+
305
+ - If you're just interested in getting into the code, a good place to start are
306
+ issues tagged as bugs.
307
+ - If introducing a new feature, especially one that modifies the public API,
308
+ consider submitting an issue for discussion before a PR. Please also take a look
309
+ at existing issues / PRs to see what you're proposing has already been covered
310
+ before / exists.
311
+ - I like to follow the commit conventions documented [here](https://www.conventionalcommits.org/en/v1.0.0/#summary)
312
+
313
+ ## License
314
+
315
+ This project is licensed under the terms of the BSD v3. license.
@@ -0,0 +1,29 @@
1
+ datamodel/__init__.py,sha256=k6FaIeF_ElduM4jAO5DCv6ZAb0nHgD2mKHxIzljvIrI,412
2
+ datamodel/abstract.py,sha256=IlsW7Hw0NmeRIQq94Fxgoca8s2G6161MCnTjWxF4NaI,6051
3
+ datamodel/base.py,sha256=nc9CQkAGb74xrsVr4ZPwIm-5ZM2wQ4TRdxfQqcarsx4,20037
4
+ datamodel/converters.c,sha256=lV3dwlAS0oZk9F9wJDzHi7wLqyTGJOQ8JveL8SzIhVw,969582
5
+ datamodel/converters.cp312-win_amd64.pyd,sha256=DjhiZaJYlxQP42VGoS-ya58gFtozXESLz2e_ZYzHp-U,147968
6
+ datamodel/exceptions.c,sha256=dhlhYpmtJA5RPt6UDij3g2SeY2qgsor5-RVx7OPWAR8,538428
7
+ datamodel/exceptions.cp312-win_amd64.pyd,sha256=YVwq-h7_-UATZ2PLzwyJ-vXwxug0ueWY8kXaYKDfEyY,77824
8
+ datamodel/fields.cp312-win_amd64.pyd,sha256=vjfu70OcmDvne6l0kn-5wX5vDrxOC8P8xNVZbFn-mAM,112640
9
+ datamodel/fields.cpp,sha256=1AW670HYEbZoxftdahz71wfAeN7HfAZZwBUlnQWnTRI,664717
10
+ datamodel/models.py,sha256=kXBk1W2FARTtof_KWa9hDmTm1nU8j5SFfLl5_mD8chQ,3119
11
+ datamodel/profiler.py,sha256=Cb7BYFV9886dvCHWL5V_znat1iU9XKAaoQ43olszlL4,520
12
+ datamodel/types.c,sha256=QLZd6GtqdwNL-gkBtC1Y83GMBcxtw7_EBwrgx_LFRjI,280446
13
+ datamodel/types.cp312-win_amd64.pyd,sha256=SpoRUYHOBnQjb8-u4O3G_RK9alfSgOuA6X3eamlhxd4,43008
14
+ datamodel/validation.cp312-win_amd64.pyd,sha256=hKTwETaVfjppgEruYIGtL1DzvQorrz6fObKaE_QK9kE,77312
15
+ datamodel/validation.cpp,sha256=sMHQ00zv7dn4LV-fgsMNunHF9iFcoPt6n1oKTP0cxEk,502044
16
+ datamodel/version.py,sha256=l4L__YA5bUVvVDhPpCEkMqOOZymFqZssE9Q02DNiv-M,315
17
+ datamodel/libs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
+ datamodel/libs/mapping.c,sha256=VqhFL0D8pgVI_fTZZDN6NSnhM2Th8y-wKWeLkxbKLjY,581173
19
+ datamodel/libs/mapping.cp312-win_amd64.pyd,sha256=7iK9uU5LBDXA9x7hk4qxJtb6sSw94hi6VZV6ZmzSxgc,90624
20
+ datamodel/libs/mutables.py,sha256=oGwOkn5ezk2qKVRjeDllAuIeVmhaHw_VppiksIpdQ5Q,3696
21
+ datamodel/parsers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ datamodel/parsers/encoders.py,sha256=Ku02PGA9bI-yOOUrFDewhCF8wi1YICbuERpPOmLJ-1E,331
23
+ datamodel/parsers/json.cp312-win_amd64.pyd,sha256=rxpoxX82FX31GkpD1MqdR5W4T0Qy3Tv4FC5hCV19BL8,82432
24
+ datamodel/parsers/json.cpp,sha256=n08ApfXqt09NtLYH09QoW1kJLK6lq0d1wfPn2YdGBuc,520162
25
+ python_datamodel-0.6.19.dist-info/LICENSE,sha256=_EiwMP8q1rs_BSFvxlBQSFwP_edqbBhOu45VBhMRPG0,1550
26
+ python_datamodel-0.6.19.dist-info/METADATA,sha256=uxHjYBRjHxHHtXnvwm2YEIQ07_B89BLq-GO79DB_gMU,9857
27
+ python_datamodel-0.6.19.dist-info/WHEEL,sha256=j9Aissza3750LQHFAQyYerNjmkEON1-8w_RaZNFtKSs,102
28
+ python_datamodel-0.6.19.dist-info/top_level.txt,sha256=UsBQ6QEFuPGiQI1zqcnYox8lCSYAVgDpxxIlShl-gac,10
29
+ python_datamodel-0.6.19.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.42.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp312-cp312-win_amd64
5
+
@@ -0,0 +1 @@
1
+ datamodel