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