ormsgpack 1.4.2__cp39-none-win_amd64.whl → 1.5.0__cp39-none-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.
Potentially problematic release.
This version of ormsgpack might be problematic. Click here for more details.
- ormsgpack/__init__.py +21 -3
- ormsgpack/ormsgpack.cp39-win_amd64.pyd +0 -0
- {ormsgpack-1.4.2.dist-info → ormsgpack-1.5.0.dist-info}/METADATA +200 -176
- ormsgpack-1.5.0.dist-info/RECORD +9 -0
- {ormsgpack-1.4.2.dist-info → ormsgpack-1.5.0.dist-info}/WHEEL +1 -1
- ormsgpack-1.4.2.dist-info/RECORD +0 -9
- {ormsgpack-1.4.2.dist-info → ormsgpack-1.5.0.dist-info}/license_files/LICENSE-APACHE +0 -0
- {ormsgpack-1.4.2.dist-info → ormsgpack-1.5.0.dist-info}/license_files/LICENSE-MIT +0 -0
ormsgpack/__init__.py
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
|
2
2
|
|
|
3
|
-
from .ormsgpack import
|
|
4
|
-
|
|
3
|
+
from .ormsgpack import (
|
|
4
|
+
OPT_NAIVE_UTC,
|
|
5
|
+
OPT_NON_STR_KEYS,
|
|
6
|
+
OPT_OMIT_MICROSECONDS,
|
|
7
|
+
OPT_PASSTHROUGH_BIG_INT,
|
|
8
|
+
OPT_PASSTHROUGH_DATACLASS,
|
|
9
|
+
OPT_PASSTHROUGH_DATETIME,
|
|
10
|
+
OPT_PASSTHROUGH_SUBCLASS,
|
|
11
|
+
OPT_PASSTHROUGH_TUPLE,
|
|
12
|
+
OPT_SERIALIZE_NUMPY,
|
|
13
|
+
OPT_SERIALIZE_PYDANTIC,
|
|
14
|
+
OPT_SORT_KEYS,
|
|
15
|
+
OPT_UTC_Z,
|
|
16
|
+
Ext,
|
|
17
|
+
MsgpackDecodeError,
|
|
18
|
+
MsgpackEncodeError,
|
|
19
|
+
__version__,
|
|
20
|
+
packb,
|
|
21
|
+
unpackb,
|
|
22
|
+
)
|
|
5
23
|
|
|
6
24
|
__all__ = (
|
|
7
25
|
"__version__",
|
|
@@ -13,7 +31,7 @@ __all__ = (
|
|
|
13
31
|
"OPT_NAIVE_UTC",
|
|
14
32
|
"OPT_NON_STR_KEYS",
|
|
15
33
|
"OPT_OMIT_MICROSECONDS",
|
|
16
|
-
"
|
|
34
|
+
"OPT_PASSTHROUGH_BIG_INT",
|
|
17
35
|
"OPT_PASSTHROUGH_DATACLASS",
|
|
18
36
|
"OPT_PASSTHROUGH_DATETIME",
|
|
19
37
|
"OPT_PASSTHROUGH_SUBCLASS",
|
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: ormsgpack
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.0
|
|
4
4
|
Classifier: Development Status :: 5 - Production/Stable
|
|
5
5
|
Classifier: Intended Audience :: Developers
|
|
6
6
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
@@ -104,11 +104,11 @@ This is an example of serializing, with options specified, and deserializing:
|
|
|
104
104
|
```python
|
|
105
105
|
>>> import ormsgpack, datetime, numpy
|
|
106
106
|
>>> data = {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
107
|
+
... "type": "job",
|
|
108
|
+
... "created_at": datetime.datetime(1970, 1, 1),
|
|
109
|
+
... "status": "🆗",
|
|
110
|
+
... "payload": numpy.array([[1, 2], [3, 4]]),
|
|
111
|
+
... }
|
|
112
112
|
>>> ormsgpack.packb(data, option=ormsgpack.OPT_NAIVE_UTC | ormsgpack.OPT_SERIALIZE_NUMPY)
|
|
113
113
|
b'\x84\xa4type\xa3job\xaacreated_at\xb91970-01-01T00:00:00+00:00\xa6status\xa4\xf0\x9f\x86\x97\xa7payload\x92\x92\x01\x02\x92\x03\x04'
|
|
114
114
|
>>> ormsgpack.unpackb(_)
|
|
@@ -170,18 +170,17 @@ handled by `default`, raise an exception such as `TypeError`.
|
|
|
170
170
|
|
|
171
171
|
```python
|
|
172
172
|
>>> import ormsgpack, decimal
|
|
173
|
-
>>>
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
173
|
+
>>> def default(obj):
|
|
174
|
+
... if isinstance(obj, decimal.Decimal):
|
|
175
|
+
... return str(obj)
|
|
176
|
+
... raise TypeError
|
|
177
|
+
...
|
|
179
178
|
>>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"))
|
|
180
|
-
|
|
179
|
+
TypeError: Type is not msgpack serializable: decimal.Decimal
|
|
181
180
|
>>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"), default=default)
|
|
182
181
|
b'\xb80.0842389659712649442845'
|
|
183
182
|
>>> ormsgpack.packb({1, 2}, default=default)
|
|
184
|
-
|
|
183
|
+
TypeError: Type is not msgpack serializable: set
|
|
185
184
|
```
|
|
186
185
|
|
|
187
186
|
The `default` callable may return an object that itself
|
|
@@ -193,13 +192,14 @@ Python otherwise implicitly returns `None`, which appears to the caller
|
|
|
193
192
|
like a legitimate value and is serialized:
|
|
194
193
|
|
|
195
194
|
```python
|
|
196
|
-
>>> import ormsgpack,
|
|
197
|
-
>>>
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
195
|
+
>>> import ormsgpack, decimal
|
|
196
|
+
>>> def default(obj):
|
|
197
|
+
... if isinstance(obj, decimal.Decimal):
|
|
198
|
+
... return str(obj)
|
|
199
|
+
...
|
|
200
|
+
>>> ormsgpack.packb({"set":{1, 2}}, default=default)
|
|
201
|
+
b'\x81\xa3set\xc0'
|
|
202
|
+
>>> ormsgpack.unpackb(_)
|
|
203
203
|
{'set': None}
|
|
204
204
|
```
|
|
205
205
|
|
|
@@ -210,12 +210,11 @@ value, respectively.
|
|
|
210
210
|
|
|
211
211
|
```python
|
|
212
212
|
>>> import ormsgpack, decimal
|
|
213
|
-
>>>
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
213
|
+
>>> def default(obj):
|
|
214
|
+
... if isinstance(obj, decimal.Decimal):
|
|
215
|
+
... return ormsgpack.Ext(0, str(obj).encode())
|
|
216
|
+
... raise TypeError
|
|
217
|
+
...
|
|
219
218
|
>>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"), default=default)
|
|
220
219
|
b'\xc7\x18\x000.0842389659712649442845'
|
|
221
220
|
```
|
|
@@ -228,20 +227,25 @@ constant in `ormsgpack`. To specify multiple options, mask them together, e.g.,
|
|
|
228
227
|
|
|
229
228
|
##### OPT_NAIVE_UTC
|
|
230
229
|
|
|
231
|
-
Serialize `datetime.datetime` objects without a `tzinfo`
|
|
232
|
-
has no effect on `datetime.datetime` objects that have
|
|
230
|
+
Serialize `datetime.datetime` objects without a `tzinfo` and `numpy.datetime64`
|
|
231
|
+
objects as UTC. This has no effect on `datetime.datetime` objects that have
|
|
232
|
+
`tzinfo` set.
|
|
233
233
|
|
|
234
234
|
```python
|
|
235
235
|
>>> import ormsgpack, datetime
|
|
236
|
-
>>> ormsgpack.
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
>>> ormsgpack.unpackb(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
236
|
+
>>> ormsgpack.packb(
|
|
237
|
+
... datetime.datetime(1970, 1, 1, 0, 0, 0),
|
|
238
|
+
... )
|
|
239
|
+
b'\xb31970-01-01T00:00:00'
|
|
240
|
+
>>> ormsgpack.unpackb(_)
|
|
241
|
+
'1970-01-01T00:00:00'
|
|
242
|
+
>>> ormsgpack.packb(
|
|
243
|
+
... datetime.datetime(1970, 1, 1, 0, 0, 0),
|
|
244
|
+
... option=ormsgpack.OPT_NAIVE_UTC,
|
|
245
|
+
... )
|
|
246
|
+
b'\xb91970-01-01T00:00:00+00:00'
|
|
247
|
+
>>> ormsgpack.unpackb(_)
|
|
248
|
+
'1970-01-01T00:00:00+00:00'
|
|
245
249
|
```
|
|
246
250
|
|
|
247
251
|
##### OPT_NON_STR_KEYS
|
|
@@ -253,13 +257,19 @@ to be one of `str`, `int`, `float`, `bool`, `None`, `datetime.datetime`,
|
|
|
253
257
|
```python
|
|
254
258
|
>>> import ormsgpack, datetime, uuid
|
|
255
259
|
>>> ormsgpack.packb(
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
260
|
+
... {uuid.UUID("7202d115-7ff3-4c81-a7c1-2a1f067b1ece"): [1, 2, 3]},
|
|
261
|
+
... option=ormsgpack.OPT_NON_STR_KEYS,
|
|
262
|
+
... )
|
|
263
|
+
b'\x81\xd9$7202d115-7ff3-4c81-a7c1-2a1f067b1ece\x93\x01\x02\x03'
|
|
264
|
+
>>> ormsgpack.unpackb(_)
|
|
265
|
+
{'7202d115-7ff3-4c81-a7c1-2a1f067b1ece': [1, 2, 3]}
|
|
259
266
|
>>> ormsgpack.packb(
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
267
|
+
... {datetime.datetime(1970, 1, 1, 0, 0, 0): [1, 2, 3]},
|
|
268
|
+
... option=ormsgpack.OPT_NON_STR_KEYS | ormsgpack.OPT_NAIVE_UTC,
|
|
269
|
+
... )
|
|
270
|
+
b'\x81\xb91970-01-01T00:00:00+00:00\x93\x01\x02\x03'
|
|
271
|
+
>>> ormsgpack.unpackb(_)
|
|
272
|
+
{'1970-01-01T00:00:00+00:00': [1, 2, 3]}
|
|
263
273
|
```
|
|
264
274
|
|
|
265
275
|
These types are generally serialized how they would be as
|
|
@@ -276,18 +286,24 @@ This option is not compatible with `ormsgpack.OPT_SORT_KEYS`.
|
|
|
276
286
|
|
|
277
287
|
##### OPT_OMIT_MICROSECONDS
|
|
278
288
|
|
|
279
|
-
Do not serialize the
|
|
280
|
-
`datetime.time` instances.
|
|
289
|
+
Do not serialize the microsecond component of `datetime.datetime`,
|
|
290
|
+
`datetime.time` and `numpy.datetime64` instances.
|
|
281
291
|
|
|
282
292
|
```python
|
|
283
293
|
>>> import ormsgpack, datetime
|
|
284
294
|
>>> ormsgpack.packb(
|
|
285
|
-
|
|
286
|
-
|
|
295
|
+
... datetime.datetime(1970, 1, 1, 0, 0, 0, 1),
|
|
296
|
+
... )
|
|
297
|
+
b'\xba1970-01-01T00:00:00.000001'
|
|
298
|
+
>>> ormsgpack.unpackb(_)
|
|
299
|
+
'1970-01-01T00:00:00.000001'
|
|
287
300
|
>>> ormsgpack.packb(
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
301
|
+
... datetime.datetime(1970, 1, 1, 0, 0, 0, 1),
|
|
302
|
+
... option=ormsgpack.OPT_OMIT_MICROSECONDS,
|
|
303
|
+
... )
|
|
304
|
+
b'\xb31970-01-01T00:00:00'
|
|
305
|
+
>>> ormsgpack.unpackb(_)
|
|
306
|
+
'1970-01-01T00:00:00'
|
|
291
307
|
```
|
|
292
308
|
|
|
293
309
|
##### OPT_PASSTHROUGH_BIG_INT
|
|
@@ -297,16 +313,16 @@ Enables passthrough of big (Python) ints. By setting this option, one can set a
|
|
|
297
313
|
```python
|
|
298
314
|
>>> import ormsgpack
|
|
299
315
|
>>> ormsgpack.packb(
|
|
300
|
-
|
|
301
|
-
|
|
316
|
+
... 2**65,
|
|
317
|
+
... )
|
|
302
318
|
TypeError: Integer exceeds 64-bit range
|
|
303
|
-
>>> ormsgpack.
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
319
|
+
>>> ormsgpack.packb(
|
|
320
|
+
... 2**65,
|
|
321
|
+
... option=ormsgpack.OPT_PASSTHROUGH_BIG_INT,
|
|
322
|
+
... default=lambda _: {"type": "bigint", "value": str(_) }
|
|
323
|
+
... )
|
|
324
|
+
b'\x82\xa4type\xa6bigint\xa5value\xb436893488147419103232'
|
|
325
|
+
>>> ormsgpack.unpackb(_)
|
|
310
326
|
{'type': 'bigint', 'value': '36893488147419103232'}
|
|
311
327
|
```
|
|
312
328
|
|
|
@@ -318,27 +334,26 @@ customizing their output but is much slower.
|
|
|
318
334
|
|
|
319
335
|
```python
|
|
320
336
|
>>> import ormsgpack, dataclasses
|
|
321
|
-
>>>
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
337
|
+
>>> @dataclasses.dataclass
|
|
338
|
+
... class User:
|
|
339
|
+
... id: str
|
|
340
|
+
... name: str
|
|
341
|
+
... password: str
|
|
342
|
+
...
|
|
343
|
+
>>> def default(obj):
|
|
344
|
+
... if isinstance(obj, User):
|
|
345
|
+
... return {"id": obj.id, "name": obj.name}
|
|
346
|
+
... raise TypeError
|
|
347
|
+
...
|
|
333
348
|
>>> ormsgpack.packb(User("3b1", "asd", "zxc"))
|
|
334
349
|
b'\x83\xa2id\xa33b1\xa4name\xa3asd\xa8password\xa3zxc'
|
|
335
350
|
>>> ormsgpack.packb(User("3b1", "asd", "zxc"), option=ormsgpack.OPT_PASSTHROUGH_DATACLASS)
|
|
336
351
|
TypeError: Type is not msgpack serializable: User
|
|
337
352
|
>>> ormsgpack.packb(
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
353
|
+
... User("3b1", "asd", "zxc"),
|
|
354
|
+
... option=ormsgpack.OPT_PASSTHROUGH_DATACLASS,
|
|
355
|
+
... default=default,
|
|
356
|
+
... )
|
|
342
357
|
b'\x82\xa2id\xa33b1\xa4name\xa3asd'
|
|
343
358
|
```
|
|
344
359
|
|
|
@@ -350,21 +365,20 @@ HTTP dates:
|
|
|
350
365
|
|
|
351
366
|
```python
|
|
352
367
|
>>> import ormsgpack, datetime
|
|
353
|
-
>>>
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
368
|
+
>>> def default(obj):
|
|
369
|
+
... if isinstance(obj, datetime.datetime):
|
|
370
|
+
... return obj.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
|
371
|
+
... raise TypeError
|
|
372
|
+
...
|
|
359
373
|
>>> ormsgpack.packb({"created_at": datetime.datetime(1970, 1, 1)})
|
|
360
374
|
b'\x81\xaacreated_at\xb31970-01-01T00:00:00'
|
|
361
375
|
>>> ormsgpack.packb({"created_at": datetime.datetime(1970, 1, 1)}, option=ormsgpack.OPT_PASSTHROUGH_DATETIME)
|
|
362
376
|
TypeError: Type is not msgpack serializable: datetime.datetime
|
|
363
377
|
>>> ormsgpack.packb(
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
378
|
+
... {"created_at": datetime.datetime(1970, 1, 1)},
|
|
379
|
+
... option=ormsgpack.OPT_PASSTHROUGH_DATETIME,
|
|
380
|
+
... default=default,
|
|
381
|
+
... )
|
|
368
382
|
b'\x81\xaacreated_at\xbdThu, 01 Jan 1970 00:00:00 GMT'
|
|
369
383
|
```
|
|
370
384
|
|
|
@@ -376,15 +390,14 @@ Passthrough subclasses of builtin types to `default`.
|
|
|
376
390
|
|
|
377
391
|
```python
|
|
378
392
|
>>> import ormsgpack
|
|
379
|
-
>>>
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
393
|
+
>>> class Secret(str):
|
|
394
|
+
... pass
|
|
395
|
+
...
|
|
396
|
+
>>> def default(obj):
|
|
397
|
+
... if isinstance(obj, Secret):
|
|
398
|
+
... return "******"
|
|
399
|
+
... raise TypeError
|
|
400
|
+
...
|
|
388
401
|
>>> ormsgpack.packb(Secret("zxc"))
|
|
389
402
|
b'\xa3zxc'
|
|
390
403
|
>>> ormsgpack.packb(Secret("zxc"), option=ormsgpack.OPT_PASSTHROUGH_SUBCLASS)
|
|
@@ -402,19 +415,19 @@ Passthrough tuples to `default`.
|
|
|
402
415
|
|
|
403
416
|
```python
|
|
404
417
|
>>> import ormsgpack
|
|
405
|
-
>>> ormsgpack.
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
418
|
+
>>> ormsgpack.packb(
|
|
419
|
+
... (9193, "test", 42),
|
|
420
|
+
... )
|
|
421
|
+
b'\x93\xcd#\xe9\xa4test*'
|
|
422
|
+
>>> ormsgpack.unpackb(_)
|
|
410
423
|
[9193, 'test', 42]
|
|
411
|
-
>>> ormsgpack.
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
424
|
+
>>> ormsgpack.packb(
|
|
425
|
+
... (9193, "test", 42),
|
|
426
|
+
... option=ormsgpack.OPT_PASSTHROUGH_TUPLE,
|
|
427
|
+
... default=lambda _: {"type": "tuple", "value": list(_)}
|
|
428
|
+
... )
|
|
429
|
+
b'\x82\xa4type\xa5tuple\xa5value\x93\xcd#\xe9\xa4test*'
|
|
430
|
+
>>> ormsgpack.unpackb(_)
|
|
418
431
|
{'type': 'tuple', 'value': [9193, 'test', 42]}
|
|
419
432
|
```
|
|
420
433
|
|
|
@@ -454,20 +467,20 @@ b'\x83\xa1A\x03\xa1a\x01\xa2\xc3\xa4\x02'
|
|
|
454
467
|
|
|
455
468
|
##### OPT_UTC_Z
|
|
456
469
|
|
|
457
|
-
Serialize a UTC timezone on `datetime.datetime`
|
|
458
|
-
of `+00:00`.
|
|
470
|
+
Serialize a UTC timezone on `datetime.datetime` and `numpy.datetime64` instances
|
|
471
|
+
as `Z` instead of `+00:00`.
|
|
459
472
|
|
|
460
473
|
```python
|
|
461
474
|
>>> import ormsgpack, datetime
|
|
462
475
|
>>> ormsgpack.packb(
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
b'
|
|
476
|
+
... datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc),
|
|
477
|
+
... )
|
|
478
|
+
b'\xb91970-01-01T00:00:00+00:00'
|
|
466
479
|
>>> ormsgpack.packb(
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
b'
|
|
480
|
+
... datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc),
|
|
481
|
+
... option=ormsgpack.OPT_UTC_Z
|
|
482
|
+
... )
|
|
483
|
+
b'\xb41970-01-01T00:00:00Z'
|
|
471
484
|
```
|
|
472
485
|
|
|
473
486
|
### Deserialize
|
|
@@ -504,17 +517,17 @@ extension type and value as arguments.
|
|
|
504
517
|
|
|
505
518
|
```python
|
|
506
519
|
>>> import ormsgpack, decimal
|
|
507
|
-
>>>
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
520
|
+
>>> def ext_hook(tag, data):
|
|
521
|
+
... if tag == 0:
|
|
522
|
+
... return decimal.Decimal(data.decode())
|
|
523
|
+
... raise TypeError
|
|
524
|
+
...
|
|
513
525
|
>>> ormsgpack.packb(
|
|
514
|
-
|
|
515
|
-
)
|
|
526
|
+
... ormsgpack.Ext(0, str(decimal.Decimal("0.0842389659712649442845")).encode())
|
|
527
|
+
... )
|
|
528
|
+
b'\xc7\x18\x000.0842389659712649442845'
|
|
516
529
|
>>> ormsgpack.unpackb(_, ext_hook=ext_hook)
|
|
517
|
-
Decimal('0.0842389659712649442845'
|
|
530
|
+
Decimal('0.0842389659712649442845'
|
|
518
531
|
```
|
|
519
532
|
|
|
520
533
|
#### option
|
|
@@ -539,18 +552,17 @@ the order given on class definition:
|
|
|
539
552
|
|
|
540
553
|
```python
|
|
541
554
|
>>> import dataclasses, ormsgpack, typing
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
555
|
+
>>> @dataclasses.dataclass
|
|
556
|
+
... class Member:
|
|
557
|
+
... id: int
|
|
558
|
+
... active: bool = dataclasses.field(default=False)
|
|
559
|
+
...
|
|
560
|
+
>>> @dataclasses.dataclass
|
|
561
|
+
... class Object:
|
|
562
|
+
... id: int
|
|
563
|
+
... name: str
|
|
564
|
+
... members: typing.List[Member]
|
|
565
|
+
...
|
|
554
566
|
>>> ormsgpack.packb(Object(1, "a", [Member(1, True), Member(2)]))
|
|
555
567
|
b'\x83\xa2id\x01\xa4name\xa1a\xa7members\x92\x82\xa2id\x01\xa6active\xc3\x82\xa2id\x02\xa6active\xc2'
|
|
556
568
|
```
|
|
@@ -576,20 +588,23 @@ compatible with `isoformat()` in the standard library.
|
|
|
576
588
|
```python
|
|
577
589
|
>>> import ormsgpack, datetime, zoneinfo
|
|
578
590
|
>>> ormsgpack.packb(
|
|
579
|
-
|
|
580
|
-
)
|
|
591
|
+
... datetime.datetime(2018, 12, 1, 2, 3, 4, 9, tzinfo=zoneinfo.ZoneInfo('Australia/Adelaide'))
|
|
592
|
+
... )
|
|
593
|
+
b'\xd9 2018-12-01T02:03:04.000009+10:30'
|
|
581
594
|
>>> ormsgpack.unpackb(_)
|
|
582
|
-
|
|
595
|
+
'2018-12-01T02:03:04.000009+10:30'
|
|
583
596
|
>>> ormsgpack.packb(
|
|
584
|
-
|
|
585
|
-
)
|
|
597
|
+
... datetime.datetime.fromtimestamp(4123518902).replace(tzinfo=datetime.timezone.utc)
|
|
598
|
+
... )
|
|
599
|
+
b'\xb92100-09-02T00:55:02+00:00'
|
|
586
600
|
>>> ormsgpack.unpackb(_)
|
|
587
|
-
|
|
601
|
+
'2100-09-02T00:55:02+00:00'
|
|
588
602
|
>>> ormsgpack.packb(
|
|
589
|
-
|
|
590
|
-
)
|
|
603
|
+
... datetime.datetime.fromtimestamp(4123518902)
|
|
604
|
+
... )
|
|
605
|
+
b'\xb32100-09-02T00:55:02'
|
|
591
606
|
>>> ormsgpack.unpackb(_)
|
|
592
|
-
|
|
607
|
+
'2100-09-02T00:55:02'
|
|
593
608
|
```
|
|
594
609
|
|
|
595
610
|
`datetime.datetime` supports instances with a `tzinfo` that is `None`,
|
|
@@ -602,8 +617,9 @@ module, or a timezone instance from the third-party `pendulum`, `pytz`, or
|
|
|
602
617
|
```python
|
|
603
618
|
>>> import ormsgpack, datetime
|
|
604
619
|
>>> ormsgpack.packb(datetime.time(12, 0, 15, 290))
|
|
620
|
+
b'\xaf12:00:15.000290'
|
|
605
621
|
>>> ormsgpack.unpackb(_)
|
|
606
|
-
|
|
622
|
+
'12:00:15.000290'
|
|
607
623
|
```
|
|
608
624
|
|
|
609
625
|
`datetime.date` objects will always serialize.
|
|
@@ -611,8 +627,9 @@ module, or a timezone instance from the third-party `pendulum`, `pytz`, or
|
|
|
611
627
|
```python
|
|
612
628
|
>>> import ormsgpack, datetime
|
|
613
629
|
>>> ormsgpack.packb(datetime.date(1900, 1, 2))
|
|
630
|
+
b'\xaa1900-01-02'
|
|
614
631
|
>>> ormsgpack.unpackb(_)
|
|
615
|
-
|
|
632
|
+
'1900-01-02'
|
|
616
633
|
```
|
|
617
634
|
|
|
618
635
|
Errors with `tzinfo` result in `MsgpackEncodeError` being raised.
|
|
@@ -631,15 +648,17 @@ ormsgpack serializes enums natively. Options apply to their values.
|
|
|
631
648
|
|
|
632
649
|
```python
|
|
633
650
|
>>> import enum, datetime, ormsgpack
|
|
634
|
-
>>>
|
|
635
|
-
|
|
636
|
-
|
|
651
|
+
>>> class DatetimeEnum(enum.Enum):
|
|
652
|
+
... EPOCH = datetime.datetime(1970, 1, 1, 0, 0, 0)
|
|
653
|
+
...
|
|
637
654
|
>>> ormsgpack.packb(DatetimeEnum.EPOCH)
|
|
655
|
+
b'\xb31970-01-01T00:00:00'
|
|
638
656
|
>>> ormsgpack.unpackb(_)
|
|
639
|
-
|
|
657
|
+
'1970-01-01T00:00:00'
|
|
640
658
|
>>> ormsgpack.packb(DatetimeEnum.EPOCH, option=ormsgpack.OPT_NAIVE_UTC)
|
|
659
|
+
b'\xb91970-01-01T00:00:00+00:00'
|
|
641
660
|
>>> ormsgpack.unpackb(_)
|
|
642
|
-
|
|
661
|
+
'1970-01-01T00:00:00+00:00'
|
|
643
662
|
```
|
|
644
663
|
|
|
645
664
|
Enums with members that are not supported types can be serialized using
|
|
@@ -647,20 +666,20 @@ Enums with members that are not supported types can be serialized using
|
|
|
647
666
|
|
|
648
667
|
```python
|
|
649
668
|
>>> import enum, ormsgpack
|
|
650
|
-
>>>
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
669
|
+
>>> class Custom:
|
|
670
|
+
... def __init__(self, val):
|
|
671
|
+
... self.val = val
|
|
672
|
+
...
|
|
673
|
+
>>> def default(obj):
|
|
674
|
+
... if isinstance(obj, Custom):
|
|
675
|
+
... return obj.val
|
|
676
|
+
... raise TypeError
|
|
677
|
+
...
|
|
678
|
+
>>> class CustomEnum(enum.Enum):
|
|
679
|
+
... ONE = Custom(1)
|
|
680
|
+
...
|
|
663
681
|
>>> ormsgpack.packb(CustomEnum.ONE, default=default)
|
|
682
|
+
b'\x01'
|
|
664
683
|
>>> ormsgpack.unpackb(_)
|
|
665
684
|
1
|
|
666
685
|
```
|
|
@@ -679,12 +698,14 @@ an unsigned 64-bit integer's maximum (18446744073709551615).
|
|
|
679
698
|
### numpy
|
|
680
699
|
|
|
681
700
|
ormsgpack natively serializes `numpy.ndarray` and individual
|
|
682
|
-
`numpy.float64`, `numpy.float32`,
|
|
701
|
+
`numpy.float64`, `numpy.float32`, `numpy.float16`,
|
|
683
702
|
`numpy.int64`, `numpy.int32`, `numpy.int16`, `numpy.int8`,
|
|
684
703
|
`numpy.uint64`, `numpy.uint32`, `numpy.uint16`, `numpy.uint8`,
|
|
685
|
-
`numpy.uintp`, `numpy.intp`, and `numpy.bool`
|
|
704
|
+
`numpy.uintp`, `numpy.intp`, `numpy.datetime64`, and `numpy.bool`
|
|
686
705
|
instances.
|
|
687
706
|
|
|
707
|
+
`numpy.datetime64` instances are serialized as RFC 3339 strings.
|
|
708
|
+
|
|
688
709
|
ormsgpack is faster than all compared libraries at serializing
|
|
689
710
|
numpy instances. Serializing numpy data requires specifying
|
|
690
711
|
`option=ormsgpack.OPT_SERIALIZE_NUMPY`.
|
|
@@ -692,11 +713,12 @@ numpy instances. Serializing numpy data requires specifying
|
|
|
692
713
|
```python
|
|
693
714
|
>>> import ormsgpack, numpy
|
|
694
715
|
>>> ormsgpack.packb(
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
)
|
|
716
|
+
... numpy.array([[1, 2, 3], [4, 5, 6]]),
|
|
717
|
+
... option=ormsgpack.OPT_SERIALIZE_NUMPY,
|
|
718
|
+
... )
|
|
719
|
+
b'\x92\x93\x01\x02\x03\x93\x04\x05\x06'
|
|
698
720
|
>>> ormsgpack.unpackb(_)
|
|
699
|
-
[[1,2,3],[4,5,6]]
|
|
721
|
+
[[1, 2, 3], [4, 5, 6]]
|
|
700
722
|
```
|
|
701
723
|
|
|
702
724
|
The array must be a contiguous C array (`C_CONTIGUOUS`) and one of the
|
|
@@ -760,14 +782,16 @@ ormsgpack serializes `uuid.UUID` instances to
|
|
|
760
782
|
[RFC 4122](https://tools.ietf.org/html/rfc4122) format, e.g.,
|
|
761
783
|
"f81d4fae-7dec-11d0-a765-00a0c91e6bf6".
|
|
762
784
|
|
|
763
|
-
```
|
|
785
|
+
```python
|
|
764
786
|
>>> import ormsgpack, uuid
|
|
765
787
|
>>> ormsgpack.packb(uuid.UUID('f81d4fae-7dec-11d0-a765-00a0c91e6bf6'))
|
|
788
|
+
b'\xd9$f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
|
|
766
789
|
>>> ormsgpack.unpackb(_)
|
|
767
|
-
|
|
790
|
+
'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
|
|
768
791
|
>>> ormsgpack.packb(uuid.uuid5(uuid.NAMESPACE_DNS, "python.org"))
|
|
792
|
+
b'\xd9$886313e1-3b8a-5372-9b90-0c9aee199e5d'
|
|
769
793
|
>>> ormsgpack.unpackb(_)
|
|
770
|
-
|
|
794
|
+
'886313e1-3b8a-5372-9b90-0c9aee199e5d
|
|
771
795
|
```
|
|
772
796
|
|
|
773
797
|
### Pydantic
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
ormsgpack-1.5.0.dist-info/METADATA,sha256=KzJsbOVJn139IMkgpmb4bJyNZHBQrgrQNxo_E5QLQww,44803
|
|
2
|
+
ormsgpack-1.5.0.dist-info/WHEEL,sha256=7Ui73pGgidyUA-5snShG0g3e0MxNIiYlCeND1YtcadQ,94
|
|
3
|
+
ormsgpack-1.5.0.dist-info/license_files/LICENSE-APACHE,sha256=fP1zjFPWHHnwfjSPYiv3cHyQhCNwVNN_vgd4inX1iBw,11048
|
|
4
|
+
ormsgpack-1.5.0.dist-info/license_files/LICENSE-MIT,sha256=NlFq79yExdWh50hUJZE6ItvaaesZMMXoTWrklytRlLk,1046
|
|
5
|
+
ormsgpack/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
ormsgpack/__init__.py,sha256=cO7CRlLMoqVgapEc5lz2nE0SNNuvi659IAbl0fYU4_Q,969
|
|
7
|
+
ormsgpack/__init__.pyi,sha256=vVfpvAXniV3FAfa546Ni7ZjwYfb4l0OevDCkK2SH9CQ,784
|
|
8
|
+
ormsgpack/ormsgpack.cp39-win_amd64.pyd,sha256=hzBIOSAJYPLawM3atM8FwqUH8o97LqlFdfbBYs3-17o,291840
|
|
9
|
+
ormsgpack-1.5.0.dist-info/RECORD,,
|
ormsgpack-1.4.2.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
ormsgpack-1.4.2.dist-info/METADATA,sha256=gJMChYyXtvFITGJQD4kDWQ9cX6OJRTIl1AywwlG5TOs,43372
|
|
2
|
-
ormsgpack-1.4.2.dist-info/WHEEL,sha256=aUq0YpgMqG5VWoJyiSBR74qbEJt2FULFr1Rdxybsy1A,94
|
|
3
|
-
ormsgpack-1.4.2.dist-info/license_files/LICENSE-APACHE,sha256=fP1zjFPWHHnwfjSPYiv3cHyQhCNwVNN_vgd4inX1iBw,11048
|
|
4
|
-
ormsgpack-1.4.2.dist-info/license_files/LICENSE-MIT,sha256=NlFq79yExdWh50hUJZE6ItvaaesZMMXoTWrklytRlLk,1046
|
|
5
|
-
ormsgpack/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
ormsgpack/__init__.py,sha256=jGcrk6dQSfTAgcqkXznT4VlrV-z9KZ9t6bHuDepqfJA,583
|
|
7
|
-
ormsgpack/__init__.pyi,sha256=vVfpvAXniV3FAfa546Ni7ZjwYfb4l0OevDCkK2SH9CQ,784
|
|
8
|
-
ormsgpack/ormsgpack.cp39-win_amd64.pyd,sha256=LMjNG-hI-oXlKSs2puxaolnkuqBGdb7apRB7tk8dxsI,282624
|
|
9
|
-
ormsgpack-1.4.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|