ormsgpack 1.7.0__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.

Potentially problematic release.


This version of ormsgpack might be problematic. Click here for more details.

ormsgpack/__init__.py ADDED
@@ -0,0 +1,43 @@
1
+ # SPDX-License-Identifier: (Apache-2.0 OR MIT)
2
+
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
+ )
23
+
24
+ __all__ = (
25
+ "__version__",
26
+ "packb",
27
+ "unpackb",
28
+ "Ext",
29
+ "MsgpackDecodeError",
30
+ "MsgpackEncodeError",
31
+ "OPT_NAIVE_UTC",
32
+ "OPT_NON_STR_KEYS",
33
+ "OPT_OMIT_MICROSECONDS",
34
+ "OPT_PASSTHROUGH_BIG_INT",
35
+ "OPT_PASSTHROUGH_DATACLASS",
36
+ "OPT_PASSTHROUGH_DATETIME",
37
+ "OPT_PASSTHROUGH_SUBCLASS",
38
+ "OPT_PASSTHROUGH_TUPLE",
39
+ "OPT_SERIALIZE_NUMPY",
40
+ "OPT_SERIALIZE_PYDANTIC",
41
+ "OPT_SORT_KEYS",
42
+ "OPT_UTC_Z",
43
+ )
ormsgpack/__init__.pyi ADDED
@@ -0,0 +1,33 @@
1
+ from typing import Any, Callable, Optional, Union
2
+
3
+ __version__: str
4
+
5
+ def packb(
6
+ obj: Any,
7
+ default: Optional[Callable[[Any], Any]] = ...,
8
+ option: Optional[int] = None,
9
+ ) -> bytes: ...
10
+ def unpackb(
11
+ obj: Union[bytes, bytearray, memoryview],
12
+ ext_hook: Optional[Callable[[int, bytes], Any]] = ...,
13
+ option: Optional[int] = ...,
14
+ ) -> Any: ...
15
+
16
+ class MsgpackDecodeError(ValueError): ...
17
+ class MsgpackEncodeError(TypeError): ...
18
+
19
+ class Ext:
20
+ def __init__(self, tag: int, data: bytes) -> None: ...
21
+
22
+ OPT_NAIVE_UTC: int
23
+ OPT_OMIT_MICROSECONDS: int
24
+ OPT_PASSTHROUGH_BIG_INT: int
25
+ OPT_PASSTHROUGH_DATACLASS: int
26
+ OPT_PASSTHROUGH_DATETIME: int
27
+ OPT_PASSTHROUGH_SUBCLASS: int
28
+ OPT_PASSTHROUGH_TUPLE: int
29
+ OPT_SERIALIZE_NUMPY: int
30
+ OPT_SERIALIZE_PYDANTIC: int
31
+ OPT_NON_STR_KEYS: int
32
+ OPT_SORT_KEYS: int
33
+ OPT_UTC_Z: int
Binary file
ormsgpack/py.typed ADDED
File without changes
@@ -0,0 +1,918 @@
1
+ Metadata-Version: 2.4
2
+ Name: ormsgpack
3
+ Version: 1.7.0
4
+ Classifier: Development Status :: 5 - Production/Stable
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: License :: OSI Approved :: Apache Software License
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: MacOS
9
+ Classifier: Operating System :: Microsoft :: Windows
10
+ Classifier: Operating System :: POSIX :: Linux
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: Implementation :: CPython
18
+ Classifier: Programming Language :: Python
19
+ Classifier: Programming Language :: Rust
20
+ Classifier: Typing :: Typed
21
+ License-File: LICENSE-APACHE
22
+ License-File: LICENSE-MIT
23
+ Summary: Fast, correct Python msgpack library supporting dataclasses, datetimes, and numpy
24
+ Keywords: fast,msgpack,dataclass,dataclasses,datetime
25
+ Home-Page: https://github.com/aviramha/ormsgpack
26
+ Author: Aviram Hassan <aviramyhassan@gmail.com>, Emanuele Giaquinta <emanuele.giaquinta@gmail.com>
27
+ Author-email: Aviram Hassan <aviramyhassan@gmail.com>, Emanuele Giaquinta <emanuele.giaquinta@gmail.com>
28
+ License: Apache-2.0 OR MIT
29
+ Requires-Python: >=3.9
30
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
31
+ Project-URL: Source Code, https://github.com/aviramha/ormsgpack
32
+
33
+ # ormsgpack
34
+ ![PyPI](https://img.shields.io/pypi/v/ormsgpack)
35
+ ![PyPI - Downloads](https://img.shields.io/pypi/dm/ormsgpack)
36
+
37
+ ormsgpack is a fast msgpack serialization library for Python derived
38
+ from [orjson](https://github.com/ijl/orjson), with native support for
39
+ various Python types.
40
+
41
+ ormsgpack supports CPython 3.9, 3.10, 3.11, 3.12 and 3.13. Releases
42
+ follow semantic versioning and serializing a new object type without
43
+ an opt-in flag is considered a breaking change.
44
+
45
+ ormsgpack is licensed under both the Apache 2.0 and MIT licenses. The
46
+ repository and issue tracker is
47
+ [github.com/aviramha/ormsgpack](https://github.com/aviramha/ormsgpack), and patches may be
48
+ submitted there. There is a
49
+ [CHANGELOG](https://github.com/aviramha/ormsgpack/blob/master/CHANGELOG.md)
50
+ available in the repository.
51
+
52
+ 1. [Usage](#usage)
53
+ 1. [Install](#install)
54
+ 2. [Quickstart](#quickstart)
55
+ 4. [Serialize](#serialize)
56
+ 1. [default](#default)
57
+ 2. [option](#option)
58
+ 5. [Deserialize](#deserialize)
59
+ 2. [Types](#types)
60
+ 1. [dataclass](#dataclass)
61
+ 2. [datetime](#datetime)
62
+ 3. [enum](#enum)
63
+ 4. [float](#float)
64
+ 5. [int](#int)
65
+ 6. [numpy](#numpy)
66
+ 7. [uuid](#uuid)
67
+ 8. [pydantic](#pydantic)
68
+ 3. [Latency](#latency)
69
+ 4. [Questions](#questions)
70
+ 5. [Packaging](#packaging)
71
+ 6. [License](#license)
72
+
73
+ ## Usage
74
+
75
+ ### Install
76
+
77
+ To install a wheel from PyPI:
78
+
79
+ ```sh
80
+ pip install --upgrade "pip>=20.3" # manylinux_x_y, universal2 wheel support
81
+ pip install --upgrade ormsgpack
82
+ ```
83
+
84
+ To build a wheel, see [packaging](#packaging).
85
+
86
+ ### Quickstart
87
+
88
+ This is an example of serializing, with options specified, and deserializing:
89
+
90
+ ```python
91
+ >>> import ormsgpack, datetime, numpy
92
+ >>> data = {
93
+ ... "type": "job",
94
+ ... "created_at": datetime.datetime(1970, 1, 1),
95
+ ... "status": "🆗",
96
+ ... "payload": numpy.array([[1, 2], [3, 4]]),
97
+ ... }
98
+ >>> ormsgpack.packb(data, option=ormsgpack.OPT_NAIVE_UTC | ormsgpack.OPT_SERIALIZE_NUMPY)
99
+ 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'
100
+ >>> ormsgpack.unpackb(_)
101
+ {'type': 'job', 'created_at': '1970-01-01T00:00:00+00:00', 'status': '🆗', 'payload': [[1, 2], [3, 4]]}
102
+ ```
103
+
104
+ ### Serialize
105
+
106
+ ```python
107
+ def packb(
108
+ __obj: Any,
109
+ default: Optional[Callable[[Any], Any]] = ...,
110
+ option: Optional[int] = ...,
111
+ ) -> bytes: ...
112
+ ```
113
+
114
+ `packb()` serializes Python objects to msgpack.
115
+
116
+ It natively serializes
117
+ `bytes`, `str`, `dict`, `list`, `tuple`, `int`, `float`, `bool`,
118
+ `dataclasses.dataclass`, `typing.TypedDict`, `datetime.datetime`,
119
+ `datetime.date`, `datetime.time`, `uuid.UUID`, `numpy.ndarray`, and
120
+ `None` instances. It supports arbitrary types through `default`. It
121
+ serializes subclasses of `str`, `int`, `dict`, `list`,
122
+ `dataclasses.dataclass`, and `enum.Enum`. It does not serialize subclasses
123
+ of `tuple` to avoid serializing `namedtuple` objects as arrays. To avoid
124
+ serializing subclasses, specify the option `ormsgpack.OPT_PASSTHROUGH_SUBCLASS`.
125
+
126
+ The output is a `bytes` object.
127
+
128
+ The global interpreter lock (GIL) is held for the duration of the call.
129
+
130
+ It raises `MsgpackEncodeError` on an unsupported type. This exception message
131
+ describes the invalid object with the error message
132
+ `Type is not msgpack serializable: ...`. To fix this, specify
133
+ [default](#default).
134
+
135
+ It raises `MsgpackEncodeError` on a `str` that contains invalid UTF-8.
136
+
137
+ It raises `MsgpackEncodeError` if a `dict` has a key of a type other than `str` or `bytes`,
138
+ unless `OPT_NON_STR_KEYS` is specified.
139
+
140
+ It raises `MsgpackEncodeError` if the output of `default` recurses to handling by
141
+ `default` more than 254 levels deep.
142
+
143
+ It raises `MsgpackEncodeError` on circular references.
144
+
145
+ It raises `MsgpackEncodeError` if a `tzinfo` on a datetime object is
146
+ unsupported.
147
+
148
+ `MsgpackEncodeError` is a subclass of `TypeError`.
149
+
150
+ #### default
151
+
152
+ To serialize a subclass or arbitrary types, specify `default` as a
153
+ callable that returns a supported type. `default` may be a function,
154
+ lambda, or callable class instance. To specify that a type was not
155
+ handled by `default`, raise an exception such as `TypeError`.
156
+
157
+ ```python
158
+ >>> import ormsgpack, decimal
159
+ >>> def default(obj):
160
+ ... if isinstance(obj, decimal.Decimal):
161
+ ... return str(obj)
162
+ ... raise TypeError
163
+ ...
164
+ >>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"))
165
+ TypeError: Type is not msgpack serializable: decimal.Decimal
166
+ >>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"), default=default)
167
+ b'\xb80.0842389659712649442845'
168
+ >>> ormsgpack.packb({1, 2}, default=default)
169
+ TypeError: Type is not msgpack serializable: set
170
+ ```
171
+
172
+ The `default` callable may return an object that itself
173
+ must be handled by `default` up to 254 times before an exception
174
+ is raised.
175
+
176
+ It is important that `default` raise an exception if a type cannot be handled.
177
+ Python otherwise implicitly returns `None`, which appears to the caller
178
+ like a legitimate value and is serialized:
179
+
180
+ ```python
181
+ >>> import ormsgpack, decimal
182
+ >>> def default(obj):
183
+ ... if isinstance(obj, decimal.Decimal):
184
+ ... return str(obj)
185
+ ...
186
+ >>> ormsgpack.packb({"set":{1, 2}}, default=default)
187
+ b'\x81\xa3set\xc0'
188
+ >>> ormsgpack.unpackb(_)
189
+ {'set': None}
190
+ ```
191
+
192
+ To serialize a type as a MessagePack extension type, return an
193
+ `ormsgpack.Ext` object. The instantiation arguments are an integer in
194
+ the range `[0, 127]` and a `bytes` object, defining the type and
195
+ value, respectively.
196
+
197
+ ```python
198
+ >>> import ormsgpack, decimal
199
+ >>> def default(obj):
200
+ ... if isinstance(obj, decimal.Decimal):
201
+ ... return ormsgpack.Ext(0, str(obj).encode())
202
+ ... raise TypeError
203
+ ...
204
+ >>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"), default=default)
205
+ b'\xc7\x18\x000.0842389659712649442845'
206
+ ```
207
+
208
+ #### option
209
+
210
+ To modify how data is serialized, specify `option`. Each `option` is an integer
211
+ constant in `ormsgpack`. To specify multiple options, mask them together, e.g.,
212
+ `option=ormsgpack.OPT_NON_STR_KEYS | ormsgpack.OPT_NAIVE_UTC`.
213
+
214
+ ##### OPT_NAIVE_UTC
215
+
216
+ Serialize `datetime.datetime` objects without a `tzinfo` and `numpy.datetime64`
217
+ objects as UTC. This has no effect on `datetime.datetime` objects that have
218
+ `tzinfo` set.
219
+
220
+ ```python
221
+ >>> import ormsgpack, datetime
222
+ >>> ormsgpack.packb(
223
+ ... datetime.datetime(1970, 1, 1, 0, 0, 0),
224
+ ... )
225
+ b'\xb31970-01-01T00:00:00'
226
+ >>> ormsgpack.unpackb(_)
227
+ '1970-01-01T00:00:00'
228
+ >>> ormsgpack.packb(
229
+ ... datetime.datetime(1970, 1, 1, 0, 0, 0),
230
+ ... option=ormsgpack.OPT_NAIVE_UTC,
231
+ ... )
232
+ b'\xb91970-01-01T00:00:00+00:00'
233
+ >>> ormsgpack.unpackb(_)
234
+ '1970-01-01T00:00:00+00:00'
235
+ ```
236
+
237
+ ##### OPT_NON_STR_KEYS
238
+
239
+ Serialize `dict` keys of type other than `str`. This allows `dict` keys
240
+ to be one of `str`, `int`, `float`, `bool`, `None`, `datetime.datetime`,
241
+ `datetime.date`, `datetime.time`, `enum.Enum`, and `uuid.UUID`.
242
+
243
+ ```python
244
+ >>> import ormsgpack, datetime, uuid
245
+ >>> ormsgpack.packb(
246
+ ... {uuid.UUID("7202d115-7ff3-4c81-a7c1-2a1f067b1ece"): [1, 2, 3]},
247
+ ... option=ormsgpack.OPT_NON_STR_KEYS,
248
+ ... )
249
+ b'\x81\xd9$7202d115-7ff3-4c81-a7c1-2a1f067b1ece\x93\x01\x02\x03'
250
+ >>> ormsgpack.unpackb(_)
251
+ {'7202d115-7ff3-4c81-a7c1-2a1f067b1ece': [1, 2, 3]}
252
+ >>> ormsgpack.packb(
253
+ ... {datetime.datetime(1970, 1, 1, 0, 0, 0): [1, 2, 3]},
254
+ ... option=ormsgpack.OPT_NON_STR_KEYS | ormsgpack.OPT_NAIVE_UTC,
255
+ ... )
256
+ b'\x81\xb91970-01-01T00:00:00+00:00\x93\x01\x02\x03'
257
+ >>> ormsgpack.unpackb(_)
258
+ {'1970-01-01T00:00:00+00:00': [1, 2, 3]}
259
+ ```
260
+
261
+ These types are generally serialized how they would be as
262
+ values, e.g., `datetime.datetime` is still an RFC 3339 string and respects
263
+ options affecting it.
264
+
265
+ This option has the risk of creating duplicate keys. This is because non-`str`
266
+ objects may serialize to the same `str` as an existing key, e.g.,
267
+ `{"1970-01-01T00:00:00+00:00": true, datetime.datetime(1970, 1, 1, 0, 0, 0): false}`.
268
+ The last key to be inserted to the `dict` will be serialized last and a msgpack deserializer will presumably take the last
269
+ occurrence of a key (in the above, `false`). The first value will be lost.
270
+
271
+ This option is not compatible with `ormsgpack.OPT_SORT_KEYS`.
272
+
273
+ ##### OPT_OMIT_MICROSECONDS
274
+
275
+ Do not serialize the microsecond component of `datetime.datetime`,
276
+ `datetime.time` and `numpy.datetime64` instances.
277
+
278
+ ```python
279
+ >>> import ormsgpack, datetime
280
+ >>> ormsgpack.packb(
281
+ ... datetime.datetime(1970, 1, 1, 0, 0, 0, 1),
282
+ ... )
283
+ b'\xba1970-01-01T00:00:00.000001'
284
+ >>> ormsgpack.unpackb(_)
285
+ '1970-01-01T00:00:00.000001'
286
+ >>> ormsgpack.packb(
287
+ ... datetime.datetime(1970, 1, 1, 0, 0, 0, 1),
288
+ ... option=ormsgpack.OPT_OMIT_MICROSECONDS,
289
+ ... )
290
+ b'\xb31970-01-01T00:00:00'
291
+ >>> ormsgpack.unpackb(_)
292
+ '1970-01-01T00:00:00'
293
+ ```
294
+
295
+ ##### OPT_PASSTHROUGH_BIG_INT
296
+
297
+ Enables passthrough of big (Python) ints. By setting this option, one can set a `default` function for ints larger than 63 bits, smaller ints are still serialized efficiently.
298
+
299
+ ```python
300
+ >>> import ormsgpack
301
+ >>> ormsgpack.packb(
302
+ ... 2**65,
303
+ ... )
304
+ TypeError: Integer exceeds 64-bit range
305
+ >>> ormsgpack.packb(
306
+ ... 2**65,
307
+ ... option=ormsgpack.OPT_PASSTHROUGH_BIG_INT,
308
+ ... default=lambda _: {"type": "bigint", "value": str(_) }
309
+ ... )
310
+ b'\x82\xa4type\xa6bigint\xa5value\xb436893488147419103232'
311
+ >>> ormsgpack.unpackb(_)
312
+ {'type': 'bigint', 'value': '36893488147419103232'}
313
+ ```
314
+
315
+ ##### OPT_PASSTHROUGH_DATACLASS
316
+
317
+ Passthrough `dataclasses.dataclass` instances to `default`. This allows
318
+ customizing their output but is much slower.
319
+
320
+
321
+ ```python
322
+ >>> import ormsgpack, dataclasses
323
+ >>> @dataclasses.dataclass
324
+ ... class User:
325
+ ... id: str
326
+ ... name: str
327
+ ... password: str
328
+ ...
329
+ >>> def default(obj):
330
+ ... if isinstance(obj, User):
331
+ ... return {"id": obj.id, "name": obj.name}
332
+ ... raise TypeError
333
+ ...
334
+ >>> ormsgpack.packb(User("3b1", "asd", "zxc"))
335
+ b'\x83\xa2id\xa33b1\xa4name\xa3asd\xa8password\xa3zxc'
336
+ >>> ormsgpack.packb(User("3b1", "asd", "zxc"), option=ormsgpack.OPT_PASSTHROUGH_DATACLASS)
337
+ TypeError: Type is not msgpack serializable: User
338
+ >>> ormsgpack.packb(
339
+ ... User("3b1", "asd", "zxc"),
340
+ ... option=ormsgpack.OPT_PASSTHROUGH_DATACLASS,
341
+ ... default=default,
342
+ ... )
343
+ b'\x82\xa2id\xa33b1\xa4name\xa3asd'
344
+ ```
345
+
346
+ ##### OPT_PASSTHROUGH_DATETIME
347
+
348
+ Passthrough `datetime.datetime`, `datetime.date`, and `datetime.time` instances
349
+ to `default`. This allows serializing datetimes to a custom format, e.g.,
350
+ HTTP dates:
351
+
352
+ ```python
353
+ >>> import ormsgpack, datetime
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
+ ...
359
+ >>> ormsgpack.packb({"created_at": datetime.datetime(1970, 1, 1)})
360
+ b'\x81\xaacreated_at\xb31970-01-01T00:00:00'
361
+ >>> ormsgpack.packb({"created_at": datetime.datetime(1970, 1, 1)}, option=ormsgpack.OPT_PASSTHROUGH_DATETIME)
362
+ TypeError: Type is not msgpack serializable: datetime.datetime
363
+ >>> ormsgpack.packb(
364
+ ... {"created_at": datetime.datetime(1970, 1, 1)},
365
+ ... option=ormsgpack.OPT_PASSTHROUGH_DATETIME,
366
+ ... default=default,
367
+ ... )
368
+ b'\x81\xaacreated_at\xbdThu, 01 Jan 1970 00:00:00 GMT'
369
+ ```
370
+
371
+ This does not affect datetimes in `dict` keys if using OPT_NON_STR_KEYS.
372
+
373
+ ##### OPT_PASSTHROUGH_SUBCLASS
374
+
375
+ Passthrough subclasses of builtin types to `default`.
376
+
377
+ ```python
378
+ >>> import ormsgpack
379
+ >>> class Secret(str):
380
+ ... pass
381
+ ...
382
+ >>> def default(obj):
383
+ ... if isinstance(obj, Secret):
384
+ ... return "******"
385
+ ... raise TypeError
386
+ ...
387
+ >>> ormsgpack.packb(Secret("zxc"))
388
+ b'\xa3zxc'
389
+ >>> ormsgpack.packb(Secret("zxc"), option=ormsgpack.OPT_PASSTHROUGH_SUBCLASS)
390
+ TypeError: Type is not msgpack serializable: Secret
391
+ >>> ormsgpack.packb(Secret("zxc"), option=ormsgpack.OPT_PASSTHROUGH_SUBCLASS, default=default)
392
+ b'\xa6******'
393
+ ```
394
+
395
+ This does not affect serializing subclasses as `dict` keys if using
396
+ OPT_NON_STR_KEYS.
397
+
398
+ ##### OPT_PASSTHROUGH_TUPLE
399
+
400
+ Passthrough tuples to `default`.
401
+
402
+ ```python
403
+ >>> import ormsgpack
404
+ >>> ormsgpack.packb(
405
+ ... (9193, "test", 42),
406
+ ... )
407
+ b'\x93\xcd#\xe9\xa4test*'
408
+ >>> ormsgpack.unpackb(_)
409
+ [9193, 'test', 42]
410
+ >>> ormsgpack.packb(
411
+ ... (9193, "test", 42),
412
+ ... option=ormsgpack.OPT_PASSTHROUGH_TUPLE,
413
+ ... default=lambda _: {"type": "tuple", "value": list(_)}
414
+ ... )
415
+ b'\x82\xa4type\xa5tuple\xa5value\x93\xcd#\xe9\xa4test*'
416
+ >>> ormsgpack.unpackb(_)
417
+ {'type': 'tuple', 'value': [9193, 'test', 42]}
418
+ ```
419
+
420
+ ##### OPT_SERIALIZE_NUMPY
421
+
422
+ Serialize `numpy.ndarray` instances. For more, see
423
+ [numpy](#numpy).
424
+
425
+ ##### OPT_SERIALIZE_PYDANTIC
426
+ Serialize `pydantic.BaseModel` instances.
427
+
428
+ ##### OPT_SORT_KEYS
429
+
430
+ Serialize `dict` keys and pydantic model fields in sorted order. The default
431
+ is to serialize in an unspecified order.
432
+
433
+ This can be used to ensure the order is deterministic for hashing or tests.
434
+ It has a substantial performance penalty and is not recommended in general.
435
+
436
+ ```python
437
+ >>> import ormsgpack
438
+ >>> ormsgpack.packb({"b": 1, "c": 2, "a": 3})
439
+ b'\x83\xa1b\x01\xa1c\x02\xa1a\x03'
440
+ >>> ormsgpack.packb({"b": 1, "c": 2, "a": 3}, option=ormsgpack.OPT_SORT_KEYS)
441
+ b'\x83\xa1a\x03\xa1b\x01\xa1c\x02'
442
+ ```
443
+
444
+ The sorting is not collation/locale-aware:
445
+
446
+ ```python
447
+ >>> import ormsgpack
448
+ >>> ormsgpack.packb({"a": 1, "ä": 2, "A": 3}, option=ormsgpack.OPT_SORT_KEYS)
449
+ b'\x83\xa1A\x03\xa1a\x01\xa2\xc3\xa4\x02'
450
+ ```
451
+
452
+ `dataclass` also serialize as maps but this has no effect on them.
453
+
454
+ ##### OPT_UTC_Z
455
+
456
+ Serialize a UTC timezone on `datetime.datetime` and `numpy.datetime64` instances
457
+ as `Z` instead of `+00:00`.
458
+
459
+ ```python
460
+ >>> import ormsgpack, datetime
461
+ >>> ormsgpack.packb(
462
+ ... datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc),
463
+ ... )
464
+ b'\xb91970-01-01T00:00:00+00:00'
465
+ >>> ormsgpack.packb(
466
+ ... datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc),
467
+ ... option=ormsgpack.OPT_UTC_Z
468
+ ... )
469
+ b'\xb41970-01-01T00:00:00Z'
470
+ ```
471
+
472
+ ### Deserialize
473
+ ```python
474
+ def unpackb(
475
+ __obj: Union[bytes, bytearray, memoryview],
476
+ /,
477
+ ext_hook: Optional[Callable[[int, bytes], Any]] = ...,
478
+ option: Optional[int] = ...,
479
+ ) -> Any: ...
480
+ ```
481
+
482
+ `unpackb()` deserializes msgpack to Python objects. It deserializes to `dict`,
483
+ `list`, `int`, `float`, `str`, `bool`, `bytes` and `None` objects.
484
+
485
+ `bytes`, `bytearray`, `memoryview` input are accepted.
486
+
487
+ ormsgpack maintains a cache of map keys for the duration of the process. This
488
+ causes a net reduction in memory usage by avoiding duplicate strings. The
489
+ keys must be at most 64 bytes to be cached and 512 entries are stored.
490
+
491
+ The global interpreter lock (GIL) is held for the duration of the call.
492
+
493
+ It raises `MsgpackDecodeError` if given an invalid type or invalid
494
+ msgpack.
495
+
496
+ `MsgpackDecodeError` is a subclass of `ValueError`.
497
+
498
+ #### ext_hook
499
+
500
+ To deserialize extension types, specify the optional `ext_hook`
501
+ argument. The value should be a callable and is invoked with the
502
+ extension type and value as arguments.
503
+
504
+ ```python
505
+ >>> import ormsgpack, decimal
506
+ >>> def ext_hook(tag, data):
507
+ ... if tag == 0:
508
+ ... return decimal.Decimal(data.decode())
509
+ ... raise TypeError
510
+ ...
511
+ >>> ormsgpack.packb(
512
+ ... ormsgpack.Ext(0, str(decimal.Decimal("0.0842389659712649442845")).encode())
513
+ ... )
514
+ b'\xc7\x18\x000.0842389659712649442845'
515
+ >>> ormsgpack.unpackb(_, ext_hook=ext_hook)
516
+ Decimal('0.0842389659712649442845'
517
+ ```
518
+
519
+ #### option
520
+ `unpackb()` supports the `OPT_NON_STR_KEYS` option, that is similar to original msgpack's `strict_map_key=False`.
521
+ Be aware that this option is considered unsafe and disabled by default in msgpack due to possibility of HashDoS.
522
+
523
+ ## Types
524
+
525
+ ### dataclass
526
+
527
+ ormsgpack serializes instances of `dataclasses.dataclass` natively. It serializes
528
+ instances 40-50x as fast as other libraries and avoids a severe slowdown seen
529
+ in other libraries compared to serializing `dict`.
530
+
531
+ It is supported to pass all variants of dataclasses, including dataclasses
532
+ using `__slots__`, frozen dataclasses, those with optional or default
533
+ attributes, and subclasses. There is a performance benefit to not
534
+ using `__slots__`.
535
+
536
+ Dataclasses are serialized as maps, with every attribute serialized and in
537
+ the order given on class definition:
538
+
539
+ ```python
540
+ >>> import dataclasses, ormsgpack, typing
541
+ >>> @dataclasses.dataclass
542
+ ... class Member:
543
+ ... id: int
544
+ ... active: bool = dataclasses.field(default=False)
545
+ ...
546
+ >>> @dataclasses.dataclass
547
+ ... class Object:
548
+ ... id: int
549
+ ... name: str
550
+ ... members: typing.List[Member]
551
+ ...
552
+ >>> ormsgpack.packb(Object(1, "a", [Member(1, True), Member(2)]))
553
+ b'\x83\xa2id\x01\xa4name\xa1a\xa7members\x92\x82\xa2id\x01\xa6active\xc3\x82\xa2id\x02\xa6active\xc2'
554
+ ```
555
+ #### Performance
556
+ ![alt text](doc/dataclass.svg "dataclass")
557
+
558
+ ```
559
+ --------------------------------------------------------------------------------- benchmark 'dataclass': 2 tests --------------------------------------------------------------------------------
560
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
561
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
562
+ test_dataclass_ormsgpack 3.4248 (1.0) 7.7949 (1.0) 3.6266 (1.0) 0.3293 (1.0) 3.5815 (1.0) 0.0310 (1.0) 4;34 275.7434 (1.0) 240 1
563
+ test_dataclass_msgpack 140.2774 (40.96) 143.6087 (18.42) 141.3847 (38.99) 1.0038 (3.05) 141.1823 (39.42) 0.7304 (23.60) 2;1 7.0729 (0.03) 8 1
564
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
565
+ ```
566
+
567
+ ### datetime
568
+
569
+ ormsgpack serializes `datetime.datetime` objects to
570
+ [RFC 3339](https://tools.ietf.org/html/rfc3339) format,
571
+ e.g., "1970-01-01T00:00:00+00:00". This is a subset of ISO 8601 and is
572
+ compatible with `isoformat()` in the standard library.
573
+
574
+ ```python
575
+ >>> import ormsgpack, datetime, zoneinfo
576
+ >>> ormsgpack.packb(
577
+ ... datetime.datetime(2018, 12, 1, 2, 3, 4, 9, tzinfo=zoneinfo.ZoneInfo('Australia/Adelaide'))
578
+ ... )
579
+ b'\xd9 2018-12-01T02:03:04.000009+10:30'
580
+ >>> ormsgpack.unpackb(_)
581
+ '2018-12-01T02:03:04.000009+10:30'
582
+ >>> ormsgpack.packb(
583
+ ... datetime.datetime.fromtimestamp(4123518902).replace(tzinfo=datetime.timezone.utc)
584
+ ... )
585
+ b'\xb92100-09-02T00:55:02+00:00'
586
+ >>> ormsgpack.unpackb(_)
587
+ '2100-09-02T00:55:02+00:00'
588
+ >>> ormsgpack.packb(
589
+ ... datetime.datetime.fromtimestamp(4123518902)
590
+ ... )
591
+ b'\xb32100-09-02T00:55:02'
592
+ >>> ormsgpack.unpackb(_)
593
+ '2100-09-02T00:55:02'
594
+ ```
595
+
596
+ `datetime.datetime` supports instances with a `tzinfo` that is `None`,
597
+ `datetime.timezone.utc`, a timezone instance from the python3.9+ `zoneinfo`
598
+ module, or a timezone instance from the third-party `pendulum`, `pytz`, or
599
+ `dateutil`/`arrow` libraries.
600
+
601
+ `datetime.time` objects must not have a `tzinfo`.
602
+
603
+ ```python
604
+ >>> import ormsgpack, datetime
605
+ >>> ormsgpack.packb(datetime.time(12, 0, 15, 290))
606
+ b'\xaf12:00:15.000290'
607
+ >>> ormsgpack.unpackb(_)
608
+ '12:00:15.000290'
609
+ ```
610
+
611
+ `datetime.date` objects will always serialize.
612
+
613
+ ```python
614
+ >>> import ormsgpack, datetime
615
+ >>> ormsgpack.packb(datetime.date(1900, 1, 2))
616
+ b'\xaa1900-01-02'
617
+ >>> ormsgpack.unpackb(_)
618
+ '1900-01-02'
619
+ ```
620
+
621
+ Errors with `tzinfo` result in `MsgpackEncodeError` being raised.
622
+
623
+ To disable serialization of `datetime` objects specify the option
624
+ `ormsgpack.OPT_PASSTHROUGH_DATETIME`.
625
+
626
+ To use "Z" suffix instead of "+00:00" to indicate UTC ("Zulu") time, use the option
627
+ `ormsgpack.OPT_UTC_Z`.
628
+
629
+ To assume datetimes without timezone are UTC, use the option `ormsgpack.OPT_NAIVE_UTC`.
630
+
631
+ ### enum
632
+
633
+ ormsgpack serializes enums natively. Options apply to their values.
634
+
635
+ ```python
636
+ >>> import enum, datetime, ormsgpack
637
+ >>> class DatetimeEnum(enum.Enum):
638
+ ... EPOCH = datetime.datetime(1970, 1, 1, 0, 0, 0)
639
+ ...
640
+ >>> ormsgpack.packb(DatetimeEnum.EPOCH)
641
+ b'\xb31970-01-01T00:00:00'
642
+ >>> ormsgpack.unpackb(_)
643
+ '1970-01-01T00:00:00'
644
+ >>> ormsgpack.packb(DatetimeEnum.EPOCH, option=ormsgpack.OPT_NAIVE_UTC)
645
+ b'\xb91970-01-01T00:00:00+00:00'
646
+ >>> ormsgpack.unpackb(_)
647
+ '1970-01-01T00:00:00+00:00'
648
+ ```
649
+
650
+ Enums with members that are not supported types can be serialized using
651
+ `default`:
652
+
653
+ ```python
654
+ >>> import enum, ormsgpack
655
+ >>> class Custom:
656
+ ... def __init__(self, val):
657
+ ... self.val = val
658
+ ...
659
+ >>> def default(obj):
660
+ ... if isinstance(obj, Custom):
661
+ ... return obj.val
662
+ ... raise TypeError
663
+ ...
664
+ >>> class CustomEnum(enum.Enum):
665
+ ... ONE = Custom(1)
666
+ ...
667
+ >>> ormsgpack.packb(CustomEnum.ONE, default=default)
668
+ b'\x01'
669
+ >>> ormsgpack.unpackb(_)
670
+ 1
671
+ ```
672
+
673
+ ### float
674
+
675
+ ormsgpack serializes and deserializes double precision floats with no loss of
676
+ precision and consistent rounding.
677
+
678
+ ### int
679
+
680
+ ormsgpack serializes and deserializes 64-bit integers by default. The range
681
+ supported is a signed 64-bit integer's minimum (-9223372036854775807) to
682
+ an unsigned 64-bit integer's maximum (18446744073709551615).
683
+
684
+ ### numpy
685
+
686
+ ormsgpack natively serializes `numpy.ndarray` and individual
687
+ `numpy.float64`, `numpy.float32`, `numpy.float16`,
688
+ `numpy.int64`, `numpy.int32`, `numpy.int16`, `numpy.int8`,
689
+ `numpy.uint64`, `numpy.uint32`, `numpy.uint16`, `numpy.uint8`,
690
+ `numpy.uintp`, `numpy.intp`, `numpy.datetime64`, and `numpy.bool`
691
+ instances.
692
+
693
+ `numpy.datetime64` instances are serialized as RFC 3339 strings.
694
+
695
+ ormsgpack is faster than all compared libraries at serializing
696
+ numpy instances. Serializing numpy data requires specifying
697
+ `option=ormsgpack.OPT_SERIALIZE_NUMPY`.
698
+
699
+ ```python
700
+ >>> import ormsgpack, numpy
701
+ >>> ormsgpack.packb(
702
+ ... numpy.array([[1, 2, 3], [4, 5, 6]]),
703
+ ... option=ormsgpack.OPT_SERIALIZE_NUMPY,
704
+ ... )
705
+ b'\x92\x93\x01\x02\x03\x93\x04\x05\x06'
706
+ >>> ormsgpack.unpackb(_)
707
+ [[1, 2, 3], [4, 5, 6]]
708
+ ```
709
+
710
+ The array must be a contiguous C array (`C_CONTIGUOUS`) and one of the
711
+ supported datatypes.
712
+
713
+ If an array is not a contiguous C array or contains an supported datatype,
714
+ ormsgpack falls through to `default`. In `default`, `obj.tolist()` can be
715
+ specified. If an array is malformed, which is not expected,
716
+ `ormsgpack.MsgpackEncodeError` is raised.
717
+
718
+ #### Performance
719
+ ![alt text](doc/numpy_float64.svg "numpy")
720
+ ![alt text](doc/numpy_int8.svg "numpy int8")
721
+ ![alt text](doc/numpy_int32.svg "numpy int32")
722
+ ![alt text](doc/numpy_npbool.svg "numpy npbool")
723
+ ![alt text](doc/numpy_uint8.svg "numpy uint8")
724
+ ```
725
+ ---------------------------------------------------------------------------------- benchmark 'numpy float64': 2 tests ---------------------------------------------------------------------------------
726
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
727
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
728
+ test_numpy_ormsgpack[float64] 77.9625 (1.0) 85.2507 (1.0) 79.0326 (1.0) 1.9043 (1.0) 78.5505 (1.0) 0.7408 (1.0) 1;1 12.6530 (1.0) 13 1
729
+ test_numpy_msgpack[float64] 511.5176 (6.56) 606.9395 (7.12) 559.0017 (7.07) 44.0661 (23.14) 572.5499 (7.29) 81.2972 (109.75) 3;0 1.7889 (0.14) 5 1
730
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
731
+
732
+
733
+ ------------------------------------------------------------------------------------- benchmark 'numpy int32': 2 tests -------------------------------------------------------------------------------------
734
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
735
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
736
+ test_numpy_ormsgpack[int32] 197.8751 (1.0) 210.3111 (1.0) 201.1033 (1.0) 5.1886 (1.0) 198.8518 (1.0) 3.8297 (1.0) 1;1 4.9726 (1.0) 5 1
737
+ test_numpy_msgpack[int32] 1,363.8515 (6.89) 1,505.4747 (7.16) 1,428.2127 (7.10) 53.4176 (10.30) 1,425.3516 (7.17) 72.8064 (19.01) 2;0 0.7002 (0.14) 5 1
738
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
739
+
740
+
741
+ -------------------------------------------------------------------------------- benchmark 'numpy int8': 2 tests ---------------------------------------------------------------------------------
742
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
743
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
744
+ test_numpy_ormsgpack[int8] 107.8013 (1.0) 113.7336 (1.0) 109.0364 (1.0) 1.7805 (1.0) 108.3574 (1.0) 0.4066 (1.0) 1;2 9.1712 (1.0) 10 1
745
+ test_numpy_msgpack[int8] 685.4149 (6.36) 703.2958 (6.18) 693.2396 (6.36) 7.9572 (4.47) 691.5435 (6.38) 14.4142 (35.45) 1;0 1.4425 (0.16) 5 1
746
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
747
+
748
+
749
+ ------------------------------------------------------------------------------------- benchmark 'numpy npbool': 2 tests --------------------------------------------------------------------------------------
750
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
751
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
752
+ test_numpy_ormsgpack[npbool] 87.9005 (1.0) 89.5460 (1.0) 88.7928 (1.0) 0.5098 (1.0) 88.8508 (1.0) 0.6609 (1.0) 4;0 11.2622 (1.0) 12 1
753
+ test_numpy_msgpack[npbool] 1,095.0599 (12.46) 1,176.3442 (13.14) 1,120.5916 (12.62) 32.9993 (64.73) 1,110.4216 (12.50) 38.4189 (58.13) 1;0 0.8924 (0.08) 5 1
754
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
755
+
756
+
757
+ --------------------------------------------------------------------------------- benchmark 'numpy uint8': 2 tests ---------------------------------------------------------------------------------
758
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
759
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
760
+ test_numpy_ormsgpack[uint8] 133.1743 (1.0) 134.7246 (1.0) 134.2793 (1.0) 0.4946 (1.0) 134.3120 (1.0) 0.4492 (1.0) 1;1 7.4472 (1.0) 8 1
761
+ test_numpy_msgpack[uint8] 727.1393 (5.46) 824.8247 (6.12) 775.7032 (5.78) 34.9887 (70.73) 775.9595 (5.78) 36.2824 (80.78) 2;0 1.2892 (0.17) 5 1
762
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
763
+ ```
764
+
765
+ ### uuid
766
+
767
+ ormsgpack serializes `uuid.UUID` instances to
768
+ [RFC 4122](https://tools.ietf.org/html/rfc4122) format, e.g.,
769
+ "f81d4fae-7dec-11d0-a765-00a0c91e6bf6".
770
+
771
+ ```python
772
+ >>> import ormsgpack, uuid
773
+ >>> ormsgpack.packb(uuid.UUID('f81d4fae-7dec-11d0-a765-00a0c91e6bf6'))
774
+ b'\xd9$f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
775
+ >>> ormsgpack.unpackb(_)
776
+ 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
777
+ >>> ormsgpack.packb(uuid.uuid5(uuid.NAMESPACE_DNS, "python.org"))
778
+ b'\xd9$886313e1-3b8a-5372-9b90-0c9aee199e5d'
779
+ >>> ormsgpack.unpackb(_)
780
+ '886313e1-3b8a-5372-9b90-0c9aee199e5d
781
+ ```
782
+
783
+ ### Pydantic
784
+ ormsgpack serializes `pydantic.BaseModel` instances natively, with
785
+ [duck-typing](https://docs.pydantic.dev/2.10/concepts/serialization/#serializing-with-duck-typing).
786
+ This is equivalent to serializing
787
+ `model.model_dump(serialize_as_any=True)` with Pydantic V2 or
788
+ `model.dict()`with Pydantic V1.
789
+
790
+ #### Performance
791
+ ![alt text](doc/pydantic.svg "pydantic")
792
+
793
+ ```
794
+ -------------------------------------------------------------------------------- benchmark 'pydantic': 2 tests ---------------------------------------------------------------------------------
795
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
796
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
797
+ test_pydantic_ormsgpack 4.3918 (1.0) 12.6521 (1.0) 4.8550 (1.0) 1.1455 (3.98) 4.6101 (1.0) 0.0662 (1.0) 11;24 205.9727 (1.0) 204 1
798
+ test_pydantic_msgpack 124.5500 (28.36) 125.5427 (9.92) 125.0582 (25.76) 0.2877 (1.0) 125.0855 (27.13) 0.2543 (3.84) 2;0 7.9963 (0.04) 8 1
799
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
800
+ ```
801
+
802
+ ## Latency
803
+ ### Graphs
804
+ ![alt text](doc/twitter_packb.svg "twitter.json serialization")
805
+ ![alt text](doc/twitter_unpackb.svg "twitter.json deserialization")
806
+ ![alt text](doc/github_packb.svg "github.json serialization")
807
+ ![alt text](doc/github_unpackb.svg "github.json deserialization")
808
+ ![alt text](doc/citm_catalog_packb.svg "citm_catalog.json serialization")
809
+ ![alt text](doc/citm_catalog_unpackb.svg "citm_catalog.json deserialization")
810
+ ![alt text](doc/canada_packb.svg "canada.json serialization")
811
+ ![alt text](doc/canada_unpackb.svg "canada.json deserialization")
812
+ ### Data
813
+ ```
814
+ ----------------------------------------------------------------------------- benchmark 'canada packb': 2 tests ------------------------------------------------------------------------------
815
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
816
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
817
+ test_ormsgpack_packb[canada] 3.5302 (1.0) 3.8939 (1.0) 3.7319 (1.0) 0.0563 (1.0) 3.7395 (1.0) 0.0484 (1.0) 56;22 267.9571 (1.0) 241 1
818
+ test_msgpack_packb[canada] 8.8642 (2.51) 14.0432 (3.61) 9.3660 (2.51) 0.5649 (10.03) 9.2983 (2.49) 0.0982 (2.03) 3;11 106.7691 (0.40) 106 1
819
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
820
+
821
+
822
+ ------------------------------------------------------------------------------- benchmark 'canada unpackb': 2 tests --------------------------------------------------------------------------------
823
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
824
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
825
+ test_msgpack_unpackb[canada] 10.1176 (1.0) 62.0466 (1.18) 33.4806 (1.0) 18.8279 (1.0) 46.6582 (1.0) 38.5921 (1.02) 30;0 29.8680 (1.0) 67 1
826
+ test_ormsgpack_unpackb[canada] 11.3992 (1.13) 52.6587 (1.0) 34.1842 (1.02) 18.9461 (1.01) 47.6456 (1.02) 37.8024 (1.0) 8;0 29.2533 (0.98) 20 1
827
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
828
+
829
+
830
+ ----------------------------------------------------------------------------- benchmark 'citm_catalog packb': 2 tests -----------------------------------------------------------------------------
831
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
832
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
833
+ test_ormsgpack_packb[citm_catalog] 1.8024 (1.0) 2.1259 (1.0) 1.9487 (1.0) 0.0346 (1.0) 1.9525 (1.0) 0.0219 (1.0) 79;60 513.1650 (1.0) 454 1
834
+ test_msgpack_packb[citm_catalog] 3.4195 (1.90) 3.8128 (1.79) 3.6928 (1.90) 0.0535 (1.55) 3.7009 (1.90) 0.0250 (1.14) 47;49 270.7958 (0.53) 257 1
835
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
836
+
837
+
838
+ ------------------------------------------------------------------------------ benchmark 'citm_catalog unpackb': 2 tests ------------------------------------------------------------------------------
839
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
840
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
841
+ test_ormsgpack_unpackb[citm_catalog] 5.6986 (1.0) 46.1843 (1.0) 14.2491 (1.0) 15.9791 (1.0) 6.1051 (1.0) 0.3074 (1.0) 5;5 70.1798 (1.0) 23 1
842
+ test_msgpack_unpackb[citm_catalog] 7.2600 (1.27) 56.6642 (1.23) 16.4095 (1.15) 16.3257 (1.02) 7.7364 (1.27) 0.4944 (1.61) 28;29 60.9404 (0.87) 125 1
843
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
844
+
845
+
846
+ ----------------------------------------------------------------------------------- benchmark 'github packb': 2 tests -----------------------------------------------------------------------------------
847
+ Name (time in us) Min Max Mean StdDev Median IQR Outliers OPS (Kops/s) Rounds Iterations
848
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
849
+ test_ormsgpack_packb[github] 73.0000 (1.0) 215.9000 (1.0) 80.4826 (1.0) 4.8889 (1.0) 80.3000 (1.0) 1.1000 (1.83) 866;1118 12.4250 (1.0) 6196 1
850
+ test_msgpack_packb[github] 103.8000 (1.42) 220.8000 (1.02) 112.8049 (1.40) 4.9686 (1.02) 113.0000 (1.41) 0.6000 (1.0) 1306;1560 8.8649 (0.71) 7028 1
851
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
852
+
853
+
854
+ ----------------------------------------------------------------------------------- benchmark 'github unpackb': 2 tests -----------------------------------------------------------------------------------
855
+ Name (time in us) Min Max Mean StdDev Median IQR Outliers OPS (Kops/s) Rounds Iterations
856
+ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
857
+ test_ormsgpack_unpackb[github] 201.3000 (1.0) 318.5000 (1.0) 219.0861 (1.0) 6.7340 (1.0) 219.1000 (1.0) 1.2000 (1.0) 483;721 4.5644 (1.0) 3488 1
858
+ test_msgpack_unpackb[github] 289.8000 (1.44) 436.0000 (1.37) 314.9631 (1.44) 9.4130 (1.40) 315.1000 (1.44) 2.3000 (1.92) 341;557 3.1750 (0.70) 2477 1
859
+ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
860
+
861
+ --------------------------------------------------------------------------------------- benchmark 'twitter packb': 2 tests ---------------------------------------------------------------------------------------
862
+ Name (time in us) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
863
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
864
+ test_ormsgpack_packb[twitter] 820.7000 (1.0) 2,945.2000 (2.03) 889.3791 (1.0) 78.4139 (2.43) 884.2000 (1.0) 12.5250 (1.0) 4;76 1,124.3799 (1.0) 809 1
865
+ test_msgpack_packb[twitter] 1,209.3000 (1.47) 1,451.2000 (1.0) 1,301.3615 (1.46) 32.2147 (1.0) 1,306.7000 (1.48) 14.1000 (1.13) 118;138 768.4260 (0.68) 592 1
866
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
867
+
868
+
869
+ ------------------------------------------------------------------------------ benchmark 'twitter unpackb': 2 tests -----------------------------------------------------------------------------
870
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
871
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
872
+ test_ormsgpack_unpackb[twitter] 2.7097 (1.0) 41.1530 (1.0) 3.2721 (1.0) 3.5860 (1.03) 2.8868 (1.0) 0.0614 (1.32) 4;38 305.6098 (1.0) 314 1
873
+ test_msgpack_unpackb[twitter] 3.8079 (1.41) 42.0617 (1.02) 4.4459 (1.36) 3.4893 (1.0) 4.1097 (1.42) 0.0465 (1.0) 2;54 224.9267 (0.74) 228 1
874
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
875
+ ```
876
+ ### Reproducing
877
+
878
+ The above was measured using Python 3.7.9 on Azure Linux VM (x86_64) with ormsgpack 0.2.1 and msgpack 1.0.2.
879
+
880
+ The latency results can be reproduced using `./scripts/benchmark.sh` and graphs using
881
+ `pytest --benchmark-histogram benchmarks/bench_*`.
882
+ ## Questions
883
+
884
+ ### Why can't I install it from PyPI?
885
+
886
+ Probably `pip` needs to be upgraded to version 20.3 or later to support
887
+ the latest manylinux_x_y or universal2 wheel formats.
888
+
889
+ ### Will it deserialize to dataclasses, UUIDs, decimals, etc or support object_hook?
890
+
891
+ No. This requires a schema specifying what types are expected and how to
892
+ handle errors etc. This is addressed by data validation libraries a
893
+ level above this.
894
+
895
+ ## Packaging
896
+
897
+ To package ormsgpack requires [Rust](https://www.rust-lang.org/) 1.70
898
+ or newer and the [maturin](https://github.com/PyO3/maturin) build
899
+ tool. The default feature `unstable-simd` enables the usage of SIMD
900
+ operations and requires nightly Rust. The recommended build command
901
+ is:
902
+
903
+ ```sh
904
+ maturin build --release --strip
905
+ ```
906
+
907
+ ormsgpack is tested on Linux/amd64, Linux/aarch64, Linux/armv7, macOS/amd64 and Windows/amd64.
908
+
909
+ There are no runtime dependencies other than libc.
910
+
911
+ ## License
912
+
913
+ orjson was written by ijl <<ijl@mailbox.org>>, copyright 2018 - 2021, licensed
914
+ under both the Apache 2 and MIT licenses.
915
+
916
+ ormsgpack was forked from orjson by Aviram Hassan and is now maintained by Emanuele Giaquinta (@exg), licensed
917
+ same as orjson.
918
+
@@ -0,0 +1,9 @@
1
+ ormsgpack-1.7.0.dist-info/METADATA,sha256=UIb3GG9Z4O4O3xUEFYv8TL3eeeJoLVBSrUM9dGOTe-I,44379
2
+ ormsgpack-1.7.0.dist-info/WHEEL,sha256=_-KsFRIAGXkqA80mFpUSYVZVhiQ0-B7C3YKRIicO45o,96
3
+ ormsgpack-1.7.0.dist-info/licenses/LICENSE-APACHE,sha256=fP1zjFPWHHnwfjSPYiv3cHyQhCNwVNN_vgd4inX1iBw,11048
4
+ ormsgpack-1.7.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.cp312-win_amd64.pyd,sha256=2gt6TUA7OgF5XgXdgam-ctd-0UTpsJEYZxaAxjwPwzk,214528
9
+ ormsgpack-1.7.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.7.8)
3
+ Root-Is-Purelib: false
4
+ Tag: cp312-cp312-win_amd64
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,23 @@
1
+ Permission is hereby granted, free of charge, to any
2
+ person obtaining a copy of this software and associated
3
+ documentation files (the "Software"), to deal in the
4
+ Software without restriction, including without
5
+ limitation the rights to use, copy, modify, merge,
6
+ publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software
8
+ is furnished to do so, subject to the following
9
+ conditions:
10
+
11
+ The above copyright notice and this permission notice
12
+ shall be included in all copies or substantial portions
13
+ of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17
+ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19
+ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
22
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
+ DEALINGS IN THE SOFTWARE.