ormsgpack 1.6.0__cp313-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 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,930 @@
1
+ Metadata-Version: 2.3
2
+ Name: ormsgpack
3
+ Version: 1.6.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.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: Implementation :: CPython
19
+ Classifier: Programming Language :: Python
20
+ Classifier: Programming Language :: Rust
21
+ Classifier: Typing :: Typed
22
+ License-File: LICENSE-APACHE
23
+ License-File: LICENSE-MIT
24
+ Summary: Fast, correct Python msgpack library supporting dataclasses, datetimes, and numpy
25
+ Keywords: fast,msgpack,dataclass,dataclasses,datetime
26
+ Home-Page: https://github.com/aviramha/ormsgpack
27
+ Author: Aviram Hassan <aviramyhassan@gmail.com>, Emanuele Giaquinta <emanuele.giaquinta@gmail.com>
28
+ Author-email: Aviram Hassan <aviramyhassan@gmail.com>, Emanuele Giaquinta <emanuele.giaquinta@gmail.com>
29
+ License: Apache-2.0 OR MIT
30
+ Requires-Python: >=3.8
31
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
32
+ Project-URL: Source Code, https://github.com/aviramha/ormsgpack
33
+
34
+ # ormsgpack
35
+ ![PyPI](https://img.shields.io/pypi/v/ormsgpack)
36
+ ![PyPI - Downloads](https://img.shields.io/pypi/dm/ormsgpack)
37
+
38
+ ormsgpack is a fast msgpack library for Python. It is a fork/reboot of [orjson](https://github.com/ijl/orjson)
39
+ It serializes faster than [msgpack-python](https://github.com/msgpack/msgpack-python) and deserializes a bit slower (right now).
40
+ It supports serialization of:
41
+ [dataclass](#dataclass),
42
+ [datetime](#datetime),
43
+ [numpy](#numpy),
44
+ [pydantic](#pydantic) and
45
+ [UUID](#uuid) instances natively.
46
+
47
+ Its features and drawbacks compared to other Python msgpack libraries:
48
+
49
+ * serializes `dataclass` instances natively.
50
+ * serializes `datetime`, `date`, and `time` instances to RFC 3339 format,
51
+ e.g., "1970-01-01T00:00:00+00:00"
52
+ * serializes `numpy.ndarray` instances natively and faster.
53
+ * serializes `pydantic.BaseModel` instances natively
54
+ * serializes arbitrary types using a `default` hook
55
+
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
58
+ versioning and serializing a new object type without an opt-in flag is
59
+ considered a breaking change.
60
+
61
+ ormsgpack is licensed under both the Apache 2.0 and MIT licenses. The
62
+ repository and issue tracker is
63
+ [github.com/aviramha/ormsgpack](https://github.com/aviramha/ormsgpack), and patches may be
64
+ submitted there. There is a
65
+ [CHANGELOG](https://github.com/aviramha/ormsgpack/blob/master/CHANGELOG.md)
66
+ available in the repository.
67
+
68
+ 1. [Usage](#usage)
69
+ 1. [Install](#install)
70
+ 2. [Quickstart](#quickstart)
71
+ 4. [Serialize](#serialize)
72
+ 1. [default](#default)
73
+ 2. [option](#option)
74
+ 5. [Deserialize](#deserialize)
75
+ 2. [Types](#types)
76
+ 1. [dataclass](#dataclass)
77
+ 2. [datetime](#datetime)
78
+ 3. [enum](#enum)
79
+ 4. [float](#float)
80
+ 5. [int](#int)
81
+ 6. [numpy](#numpy)
82
+ 7. [uuid](#uuid)
83
+ 8. [pydantic](#pydantic)
84
+ 3. [Latency](#latency)
85
+ 4. [Questions](#questions)
86
+ 5. [Packaging](#packaging)
87
+ 6. [License](#license)
88
+
89
+ ## Usage
90
+
91
+ ### Install
92
+
93
+ To install a wheel from PyPI:
94
+
95
+ ```sh
96
+ pip install --upgrade "pip>=20.3" # manylinux_x_y, universal2 wheel support
97
+ pip install --upgrade ormsgpack
98
+ ```
99
+
100
+ To build a wheel, see [packaging](#packaging).
101
+
102
+ ### Quickstart
103
+
104
+ This is an example of serializing, with options specified, and deserializing:
105
+
106
+ ```python
107
+ >>> import ormsgpack, datetime, numpy
108
+ >>> data = {
109
+ ... "type": "job",
110
+ ... "created_at": datetime.datetime(1970, 1, 1),
111
+ ... "status": "🆗",
112
+ ... "payload": numpy.array([[1, 2], [3, 4]]),
113
+ ... }
114
+ >>> ormsgpack.packb(data, option=ormsgpack.OPT_NAIVE_UTC | ormsgpack.OPT_SERIALIZE_NUMPY)
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'
116
+ >>> ormsgpack.unpackb(_)
117
+ {'type': 'job', 'created_at': '1970-01-01T00:00:00+00:00', 'status': '🆗', 'payload': [[1, 2], [3, 4]]}
118
+ ```
119
+
120
+ ### Serialize
121
+
122
+ ```python
123
+ def packb(
124
+ __obj: Any,
125
+ default: Optional[Callable[[Any], Any]] = ...,
126
+ option: Optional[int] = ...,
127
+ ) -> bytes: ...
128
+ ```
129
+
130
+ `packb()` serializes Python objects to msgpack.
131
+
132
+ It natively serializes
133
+ `bytes`, `str`, `dict`, `list`, `tuple`, `int`, `float`, `bool`,
134
+ `dataclasses.dataclass`, `typing.TypedDict`, `datetime.datetime`,
135
+ `datetime.date`, `datetime.time`, `uuid.UUID`, `numpy.ndarray`, and
136
+ `None` instances. It supports arbitrary types through `default`. It
137
+ serializes subclasses of `str`, `int`, `dict`, `list`,
138
+ `dataclasses.dataclass`, and `enum.Enum`. It does not serialize subclasses
139
+ of `tuple` to avoid serializing `namedtuple` objects as arrays. To avoid
140
+ serializing subclasses, specify the option `ormsgpack.OPT_PASSTHROUGH_SUBCLASS`.
141
+
142
+ The output is a `bytes` object containing UTF-8.
143
+
144
+ The global interpreter lock (GIL) is held for the duration of the call.
145
+
146
+ It raises `MsgpackEncodeError` on an unsupported type. This exception message
147
+ describes the invalid object with the error message
148
+ `Type is not msgpack serializable: ...`. To fix this, specify
149
+ [default](#default).
150
+
151
+ It raises `MsgpackEncodeError` on a `str` that contains invalid UTF-8.
152
+
153
+ It raises `MsgpackEncodeError` if a `dict` has a key of a type other than `str` or `bytes`,
154
+ unless `OPT_NON_STR_KEYS` is specified.
155
+
156
+ It raises `MsgpackEncodeError` if the output of `default` recurses to handling by
157
+ `default` more than 254 levels deep.
158
+
159
+ It raises `MsgpackEncodeError` on circular references.
160
+
161
+ It raises `MsgpackEncodeError` if a `tzinfo` on a datetime object is
162
+ unsupported.
163
+
164
+ `MsgpackEncodeError` is a subclass of `TypeError`.
165
+
166
+ #### default
167
+
168
+ To serialize a subclass or arbitrary types, specify `default` as a
169
+ callable that returns a supported type. `default` may be a function,
170
+ lambda, or callable class instance. To specify that a type was not
171
+ handled by `default`, raise an exception such as `TypeError`.
172
+
173
+ ```python
174
+ >>> import ormsgpack, decimal
175
+ >>> def default(obj):
176
+ ... if isinstance(obj, decimal.Decimal):
177
+ ... return str(obj)
178
+ ... raise TypeError
179
+ ...
180
+ >>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"))
181
+ TypeError: Type is not msgpack serializable: decimal.Decimal
182
+ >>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"), default=default)
183
+ b'\xb80.0842389659712649442845'
184
+ >>> ormsgpack.packb({1, 2}, default=default)
185
+ TypeError: Type is not msgpack serializable: set
186
+ ```
187
+
188
+ The `default` callable may return an object that itself
189
+ must be handled by `default` up to 254 times before an exception
190
+ is raised.
191
+
192
+ It is important that `default` raise an exception if a type cannot be handled.
193
+ Python otherwise implicitly returns `None`, which appears to the caller
194
+ like a legitimate value and is serialized:
195
+
196
+ ```python
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(_)
205
+ {'set': None}
206
+ ```
207
+
208
+ To serialize a type as a MessagePack extension type, return an
209
+ `ormsgpack.Ext` object. The instantiation arguments are an integer in
210
+ the range `[0, 127]` and a `bytes` object, defining the type and
211
+ value, respectively.
212
+
213
+ ```python
214
+ >>> import ormsgpack, decimal
215
+ >>> def default(obj):
216
+ ... if isinstance(obj, decimal.Decimal):
217
+ ... return ormsgpack.Ext(0, str(obj).encode())
218
+ ... raise TypeError
219
+ ...
220
+ >>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"), default=default)
221
+ b'\xc7\x18\x000.0842389659712649442845'
222
+ ```
223
+
224
+ #### option
225
+
226
+ To modify how data is serialized, specify `option`. Each `option` is an integer
227
+ constant in `ormsgpack`. To specify multiple options, mask them together, e.g.,
228
+ `option=ormsgpack.OPT_NON_STR_KEYS | ormsgpack.OPT_NAIVE_UTC`.
229
+
230
+ ##### OPT_NAIVE_UTC
231
+
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.
235
+
236
+ ```python
237
+ >>> import ormsgpack, datetime
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'
251
+ ```
252
+
253
+ ##### OPT_NON_STR_KEYS
254
+
255
+ Serialize `dict` keys of type other than `str`. This allows `dict` keys
256
+ to be one of `str`, `int`, `float`, `bool`, `None`, `datetime.datetime`,
257
+ `datetime.date`, `datetime.time`, `enum.Enum`, and `uuid.UUID`.
258
+
259
+ ```python
260
+ >>> import ormsgpack, datetime, uuid
261
+ >>> ormsgpack.packb(
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]}
268
+ >>> ormsgpack.packb(
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]}
275
+ ```
276
+
277
+ These types are generally serialized how they would be as
278
+ values, e.g., `datetime.datetime` is still an RFC 3339 string and respects
279
+ options affecting it.
280
+
281
+ This option has the risk of creating duplicate keys. This is because non-`str`
282
+ objects may serialize to the same `str` as an existing key, e.g.,
283
+ `{"1970-01-01T00:00:00+00:00": true, datetime.datetime(1970, 1, 1, 0, 0, 0): false}`.
284
+ The last key to be inserted to the `dict` will be serialized last and a msgpack deserializer will presumably take the last
285
+ occurrence of a key (in the above, `false`). The first value will be lost.
286
+
287
+ This option is not compatible with `ormsgpack.OPT_SORT_KEYS`.
288
+
289
+ ##### OPT_OMIT_MICROSECONDS
290
+
291
+ Do not serialize the microsecond component of `datetime.datetime`,
292
+ `datetime.time` and `numpy.datetime64` instances.
293
+
294
+ ```python
295
+ >>> import ormsgpack, datetime
296
+ >>> ormsgpack.packb(
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'
302
+ >>> ormsgpack.packb(
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'
309
+ ```
310
+
311
+ ##### OPT_PASSTHROUGH_BIG_INT
312
+
313
+ 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.
314
+
315
+ ```python
316
+ >>> import ormsgpack
317
+ >>> ormsgpack.packb(
318
+ ... 2**65,
319
+ ... )
320
+ TypeError: Integer exceeds 64-bit range
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(_)
328
+ {'type': 'bigint', 'value': '36893488147419103232'}
329
+ ```
330
+
331
+ ##### OPT_PASSTHROUGH_DATACLASS
332
+
333
+ Passthrough `dataclasses.dataclass` instances to `default`. This allows
334
+ customizing their output but is much slower.
335
+
336
+
337
+ ```python
338
+ >>> import ormsgpack, dataclasses
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
+ ...
350
+ >>> ormsgpack.packb(User("3b1", "asd", "zxc"))
351
+ b'\x83\xa2id\xa33b1\xa4name\xa3asd\xa8password\xa3zxc'
352
+ >>> ormsgpack.packb(User("3b1", "asd", "zxc"), option=ormsgpack.OPT_PASSTHROUGH_DATACLASS)
353
+ TypeError: Type is not msgpack serializable: User
354
+ >>> ormsgpack.packb(
355
+ ... User("3b1", "asd", "zxc"),
356
+ ... option=ormsgpack.OPT_PASSTHROUGH_DATACLASS,
357
+ ... default=default,
358
+ ... )
359
+ b'\x82\xa2id\xa33b1\xa4name\xa3asd'
360
+ ```
361
+
362
+ ##### OPT_PASSTHROUGH_DATETIME
363
+
364
+ Passthrough `datetime.datetime`, `datetime.date`, and `datetime.time` instances
365
+ to `default`. This allows serializing datetimes to a custom format, e.g.,
366
+ HTTP dates:
367
+
368
+ ```python
369
+ >>> import ormsgpack, datetime
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
+ ...
375
+ >>> ormsgpack.packb({"created_at": datetime.datetime(1970, 1, 1)})
376
+ b'\x81\xaacreated_at\xb31970-01-01T00:00:00'
377
+ >>> ormsgpack.packb({"created_at": datetime.datetime(1970, 1, 1)}, option=ormsgpack.OPT_PASSTHROUGH_DATETIME)
378
+ TypeError: Type is not msgpack serializable: datetime.datetime
379
+ >>> ormsgpack.packb(
380
+ ... {"created_at": datetime.datetime(1970, 1, 1)},
381
+ ... option=ormsgpack.OPT_PASSTHROUGH_DATETIME,
382
+ ... default=default,
383
+ ... )
384
+ b'\x81\xaacreated_at\xbdThu, 01 Jan 1970 00:00:00 GMT'
385
+ ```
386
+
387
+ This does not affect datetimes in `dict` keys if using OPT_NON_STR_KEYS.
388
+
389
+ ##### OPT_PASSTHROUGH_SUBCLASS
390
+
391
+ Passthrough subclasses of builtin types to `default`.
392
+
393
+ ```python
394
+ >>> import ormsgpack
395
+ >>> class Secret(str):
396
+ ... pass
397
+ ...
398
+ >>> def default(obj):
399
+ ... if isinstance(obj, Secret):
400
+ ... return "******"
401
+ ... raise TypeError
402
+ ...
403
+ >>> ormsgpack.packb(Secret("zxc"))
404
+ b'\xa3zxc'
405
+ >>> ormsgpack.packb(Secret("zxc"), option=ormsgpack.OPT_PASSTHROUGH_SUBCLASS)
406
+ TypeError: Type is not msgpack serializable: Secret
407
+ >>> ormsgpack.packb(Secret("zxc"), option=ormsgpack.OPT_PASSTHROUGH_SUBCLASS, default=default)
408
+ b'\xa6******'
409
+ ```
410
+
411
+ This does not affect serializing subclasses as `dict` keys if using
412
+ OPT_NON_STR_KEYS.
413
+
414
+ ##### OPT_PASSTHROUGH_TUPLE
415
+
416
+ Passthrough tuples to `default`.
417
+
418
+ ```python
419
+ >>> import ormsgpack
420
+ >>> ormsgpack.packb(
421
+ ... (9193, "test", 42),
422
+ ... )
423
+ b'\x93\xcd#\xe9\xa4test*'
424
+ >>> ormsgpack.unpackb(_)
425
+ [9193, 'test', 42]
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(_)
433
+ {'type': 'tuple', 'value': [9193, 'test', 42]}
434
+ ```
435
+
436
+ ##### OPT_SERIALIZE_NUMPY
437
+
438
+ Serialize `numpy.ndarray` instances. For more, see
439
+ [numpy](#numpy).
440
+
441
+ ##### OPT_SERIALIZE_PYDANTIC
442
+ Serialize `pydantic.BaseModel` instances.
443
+
444
+ ##### OPT_SORT_KEYS
445
+
446
+ Serialize `dict` keys in sorted order. The default is to serialize in an
447
+ unspecified order.
448
+
449
+ This can be used to ensure the order is deterministic for hashing or tests.
450
+ It has a substantial performance penalty and is not recommended in general.
451
+
452
+ ```python
453
+ >>> import ormsgpack
454
+ >>> ormsgpack.packb({"b": 1, "c": 2, "a": 3})
455
+ b'\x83\xa1b\x01\xa1c\x02\xa1a\x03'
456
+ >>> ormsgpack.packb({"b": 1, "c": 2, "a": 3}, option=ormsgpack.OPT_SORT_KEYS)
457
+ b'\x83\xa1a\x03\xa1b\x01\xa1c\x02'
458
+ ```
459
+
460
+ The sorting is not collation/locale-aware:
461
+
462
+ ```python
463
+ >>> import ormsgpack
464
+ >>> ormsgpack.packb({"a": 1, "ä": 2, "A": 3}, option=ormsgpack.OPT_SORT_KEYS)
465
+ b'\x83\xa1A\x03\xa1a\x01\xa2\xc3\xa4\x02'
466
+ ```
467
+
468
+ `dataclass` also serialize as maps but this has no effect on them.
469
+
470
+ ##### OPT_UTC_Z
471
+
472
+ Serialize a UTC timezone on `datetime.datetime` and `numpy.datetime64` instances
473
+ as `Z` instead of `+00:00`.
474
+
475
+ ```python
476
+ >>> import ormsgpack, datetime
477
+ >>> ormsgpack.packb(
478
+ ... datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc),
479
+ ... )
480
+ b'\xb91970-01-01T00:00:00+00:00'
481
+ >>> ormsgpack.packb(
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'
486
+ ```
487
+
488
+ ### Deserialize
489
+ ```python
490
+ def unpackb(
491
+ __obj: Union[bytes, bytearray, memoryview],
492
+ /,
493
+ ext_hook: Optional[Callable[[int, bytes], Any]] = ...,
494
+ option: Optional[int] = ...,
495
+ ) -> Any: ...
496
+ ```
497
+
498
+ `unpackb()` deserializes msgpack to Python objects. It deserializes to `dict`,
499
+ `list`, `int`, `float`, `str`, `bool`, `bytes` and `None` objects.
500
+
501
+ `bytes`, `bytearray`, `memoryview` input are accepted.
502
+
503
+ ormsgpack maintains a cache of map keys for the duration of the process. This
504
+ causes a net reduction in memory usage by avoiding duplicate strings. The
505
+ keys must be at most 64 bytes to be cached and 512 entries are stored.
506
+
507
+ The global interpreter lock (GIL) is held for the duration of the call.
508
+
509
+ It raises `MsgpackDecodeError` if given an invalid type or invalid
510
+ msgpack.
511
+
512
+ `MsgpackDecodeError` is a subclass of `ValueError`.
513
+
514
+ #### ext_hook
515
+
516
+ To deserialize extension types, specify the optional `ext_hook`
517
+ argument. The value should be a callable and is invoked with the
518
+ extension type and value as arguments.
519
+
520
+ ```python
521
+ >>> import ormsgpack, decimal
522
+ >>> def ext_hook(tag, data):
523
+ ... if tag == 0:
524
+ ... return decimal.Decimal(data.decode())
525
+ ... raise TypeError
526
+ ...
527
+ >>> ormsgpack.packb(
528
+ ... ormsgpack.Ext(0, str(decimal.Decimal("0.0842389659712649442845")).encode())
529
+ ... )
530
+ b'\xc7\x18\x000.0842389659712649442845'
531
+ >>> ormsgpack.unpackb(_, ext_hook=ext_hook)
532
+ Decimal('0.0842389659712649442845'
533
+ ```
534
+
535
+ #### option
536
+ `unpackb()` supports the `OPT_NON_STR_KEYS` option, that is similar to original msgpack's `strict_map_key=False`.
537
+ Be aware that this option is considered unsafe and disabled by default in msgpack due to possibility of HashDoS.
538
+
539
+ ## Types
540
+
541
+ ### dataclass
542
+
543
+ ormsgpack serializes instances of `dataclasses.dataclass` natively. It serializes
544
+ instances 40-50x as fast as other libraries and avoids a severe slowdown seen
545
+ in other libraries compared to serializing `dict`.
546
+
547
+ It is supported to pass all variants of dataclasses, including dataclasses
548
+ using `__slots__`, frozen dataclasses, those with optional or default
549
+ attributes, and subclasses. There is a performance benefit to not
550
+ using `__slots__`.
551
+
552
+ Dataclasses are serialized as maps, with every attribute serialized and in
553
+ the order given on class definition:
554
+
555
+ ```python
556
+ >>> import dataclasses, ormsgpack, typing
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
+ ...
568
+ >>> ormsgpack.packb(Object(1, "a", [Member(1, True), Member(2)]))
569
+ b'\x83\xa2id\x01\xa4name\xa1a\xa7members\x92\x82\xa2id\x01\xa6active\xc3\x82\xa2id\x02\xa6active\xc2'
570
+ ```
571
+ #### Performance
572
+ ![alt text](doc/dataclass.svg "dataclass")
573
+
574
+ ```
575
+ --------------------------------------------------------------------------------- benchmark 'dataclass': 2 tests --------------------------------------------------------------------------------
576
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
577
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
578
+ 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
579
+ 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
580
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
581
+ ```
582
+
583
+ ### datetime
584
+
585
+ ormsgpack serializes `datetime.datetime` objects to
586
+ [RFC 3339](https://tools.ietf.org/html/rfc3339) format,
587
+ e.g., "1970-01-01T00:00:00+00:00". This is a subset of ISO 8601 and is
588
+ compatible with `isoformat()` in the standard library.
589
+
590
+ ```python
591
+ >>> import ormsgpack, datetime, zoneinfo
592
+ >>> ormsgpack.packb(
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'
596
+ >>> ormsgpack.unpackb(_)
597
+ '2018-12-01T02:03:04.000009+10:30'
598
+ >>> ormsgpack.packb(
599
+ ... datetime.datetime.fromtimestamp(4123518902).replace(tzinfo=datetime.timezone.utc)
600
+ ... )
601
+ b'\xb92100-09-02T00:55:02+00:00'
602
+ >>> ormsgpack.unpackb(_)
603
+ '2100-09-02T00:55:02+00:00'
604
+ >>> ormsgpack.packb(
605
+ ... datetime.datetime.fromtimestamp(4123518902)
606
+ ... )
607
+ b'\xb32100-09-02T00:55:02'
608
+ >>> ormsgpack.unpackb(_)
609
+ '2100-09-02T00:55:02'
610
+ ```
611
+
612
+ `datetime.datetime` supports instances with a `tzinfo` that is `None`,
613
+ `datetime.timezone.utc`, a timezone instance from the python3.9+ `zoneinfo`
614
+ module, or a timezone instance from the third-party `pendulum`, `pytz`, or
615
+ `dateutil`/`arrow` libraries.
616
+
617
+ `datetime.time` objects must not have a `tzinfo`.
618
+
619
+ ```python
620
+ >>> import ormsgpack, datetime
621
+ >>> ormsgpack.packb(datetime.time(12, 0, 15, 290))
622
+ b'\xaf12:00:15.000290'
623
+ >>> ormsgpack.unpackb(_)
624
+ '12:00:15.000290'
625
+ ```
626
+
627
+ `datetime.date` objects will always serialize.
628
+
629
+ ```python
630
+ >>> import ormsgpack, datetime
631
+ >>> ormsgpack.packb(datetime.date(1900, 1, 2))
632
+ b'\xaa1900-01-02'
633
+ >>> ormsgpack.unpackb(_)
634
+ '1900-01-02'
635
+ ```
636
+
637
+ Errors with `tzinfo` result in `MsgpackEncodeError` being raised.
638
+
639
+ To disable serialization of `datetime` objects specify the option
640
+ `ormsgpack.OPT_PASSTHROUGH_DATETIME`.
641
+
642
+ To use "Z" suffix instead of "+00:00" to indicate UTC ("Zulu") time, use the option
643
+ `ormsgpack.OPT_UTC_Z`.
644
+
645
+ To assume datetimes without timezone are UTC, use the option `ormsgpack.OPT_NAIVE_UTC`.
646
+
647
+ ### enum
648
+
649
+ ormsgpack serializes enums natively. Options apply to their values.
650
+
651
+ ```python
652
+ >>> import enum, datetime, ormsgpack
653
+ >>> class DatetimeEnum(enum.Enum):
654
+ ... EPOCH = datetime.datetime(1970, 1, 1, 0, 0, 0)
655
+ ...
656
+ >>> ormsgpack.packb(DatetimeEnum.EPOCH)
657
+ b'\xb31970-01-01T00:00:00'
658
+ >>> ormsgpack.unpackb(_)
659
+ '1970-01-01T00:00:00'
660
+ >>> ormsgpack.packb(DatetimeEnum.EPOCH, option=ormsgpack.OPT_NAIVE_UTC)
661
+ b'\xb91970-01-01T00:00:00+00:00'
662
+ >>> ormsgpack.unpackb(_)
663
+ '1970-01-01T00:00:00+00:00'
664
+ ```
665
+
666
+ Enums with members that are not supported types can be serialized using
667
+ `default`:
668
+
669
+ ```python
670
+ >>> import enum, ormsgpack
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
+ ...
683
+ >>> ormsgpack.packb(CustomEnum.ONE, default=default)
684
+ b'\x01'
685
+ >>> ormsgpack.unpackb(_)
686
+ 1
687
+ ```
688
+
689
+ ### float
690
+
691
+ ormsgpack serializes and deserializes double precision floats with no loss of
692
+ precision and consistent rounding.
693
+
694
+ ### int
695
+
696
+ ormsgpack serializes and deserializes 64-bit integers by default. The range
697
+ supported is a signed 64-bit integer's minimum (-9223372036854775807) to
698
+ an unsigned 64-bit integer's maximum (18446744073709551615).
699
+
700
+ ### numpy
701
+
702
+ ormsgpack natively serializes `numpy.ndarray` and individual
703
+ `numpy.float64`, `numpy.float32`, `numpy.float16`,
704
+ `numpy.int64`, `numpy.int32`, `numpy.int16`, `numpy.int8`,
705
+ `numpy.uint64`, `numpy.uint32`, `numpy.uint16`, `numpy.uint8`,
706
+ `numpy.uintp`, `numpy.intp`, `numpy.datetime64`, and `numpy.bool`
707
+ instances.
708
+
709
+ `numpy.datetime64` instances are serialized as RFC 3339 strings.
710
+
711
+ ormsgpack is faster than all compared libraries at serializing
712
+ numpy instances. Serializing numpy data requires specifying
713
+ `option=ormsgpack.OPT_SERIALIZE_NUMPY`.
714
+
715
+ ```python
716
+ >>> import ormsgpack, numpy
717
+ >>> ormsgpack.packb(
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'
722
+ >>> ormsgpack.unpackb(_)
723
+ [[1, 2, 3], [4, 5, 6]]
724
+ ```
725
+
726
+ The array must be a contiguous C array (`C_CONTIGUOUS`) and one of the
727
+ supported datatypes.
728
+
729
+ If an array is not a contiguous C array or contains an supported datatype,
730
+ ormsgpack falls through to `default`. In `default`, `obj.tolist()` can be
731
+ specified. If an array is malformed, which is not expected,
732
+ `ormsgpack.MsgpackEncodeError` is raised.
733
+
734
+ #### Performance
735
+ ![alt text](doc/numpy_float64.svg "numpy")
736
+ ![alt text](doc/numpy_int8.svg "numpy int8")
737
+ ![alt text](doc/numpy_int32.svg "numpy int32")
738
+ ![alt text](doc/numpy_npbool.svg "numpy npbool")
739
+ ![alt text](doc/numpy_uint8.svg "numpy uint8")
740
+ ```
741
+ ---------------------------------------------------------------------------------- benchmark 'numpy float64': 2 tests ---------------------------------------------------------------------------------
742
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
743
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
744
+ 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
745
+ 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
746
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
747
+
748
+
749
+ ------------------------------------------------------------------------------------- benchmark 'numpy int32': 2 tests -------------------------------------------------------------------------------------
750
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
751
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
752
+ 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
753
+ 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
754
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
755
+
756
+
757
+ -------------------------------------------------------------------------------- benchmark 'numpy int8': 2 tests ---------------------------------------------------------------------------------
758
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
759
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
760
+ 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
761
+ 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
762
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
763
+
764
+
765
+ ------------------------------------------------------------------------------------- benchmark 'numpy npbool': 2 tests --------------------------------------------------------------------------------------
766
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
767
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
768
+ 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
769
+ 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
770
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
771
+
772
+
773
+ --------------------------------------------------------------------------------- benchmark 'numpy uint8': 2 tests ---------------------------------------------------------------------------------
774
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
775
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
776
+ 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
777
+ 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
778
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
779
+ ```
780
+
781
+ ### uuid
782
+
783
+ ormsgpack serializes `uuid.UUID` instances to
784
+ [RFC 4122](https://tools.ietf.org/html/rfc4122) format, e.g.,
785
+ "f81d4fae-7dec-11d0-a765-00a0c91e6bf6".
786
+
787
+ ```python
788
+ >>> import ormsgpack, uuid
789
+ >>> ormsgpack.packb(uuid.UUID('f81d4fae-7dec-11d0-a765-00a0c91e6bf6'))
790
+ b'\xd9$f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
791
+ >>> ormsgpack.unpackb(_)
792
+ 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
793
+ >>> ormsgpack.packb(uuid.uuid5(uuid.NAMESPACE_DNS, "python.org"))
794
+ b'\xd9$886313e1-3b8a-5372-9b90-0c9aee199e5d'
795
+ >>> ormsgpack.unpackb(_)
796
+ '886313e1-3b8a-5372-9b90-0c9aee199e5d
797
+ ```
798
+
799
+ ### Pydantic
800
+ ormsgpack serializes `pydantic.BaseModel` instances natively.
801
+
802
+ #### Performance
803
+ ![alt text](doc/pydantic.svg "pydantic")
804
+
805
+ ```
806
+ -------------------------------------------------------------------------------- benchmark 'pydantic': 2 tests ---------------------------------------------------------------------------------
807
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
808
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
809
+ 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
810
+ 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
811
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
812
+ ```
813
+
814
+ ## Latency
815
+ ### Graphs
816
+ ![alt text](doc/twitter_packb.svg "twitter.json serialization")
817
+ ![alt text](doc/twitter_unpackb.svg "twitter.json deserialization")
818
+ ![alt text](doc/github_packb.svg "github.json serialization")
819
+ ![alt text](doc/github_unpackb.svg "github.json deserialization")
820
+ ![alt text](doc/citm_catalog_packb.svg "citm_catalog.json serialization")
821
+ ![alt text](doc/citm_catalog_unpackb.svg "citm_catalog.json deserialization")
822
+ ![alt text](doc/canada_packb.svg "canada.json serialization")
823
+ ![alt text](doc/canada_unpackb.svg "canada.json deserialization")
824
+ ### Data
825
+ ```
826
+ ----------------------------------------------------------------------------- benchmark 'canada packb': 2 tests ------------------------------------------------------------------------------
827
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
828
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
829
+ 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
830
+ 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
831
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
832
+
833
+
834
+ ------------------------------------------------------------------------------- benchmark 'canada unpackb': 2 tests --------------------------------------------------------------------------------
835
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
836
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
837
+ 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
838
+ 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
839
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
840
+
841
+
842
+ ----------------------------------------------------------------------------- benchmark 'citm_catalog packb': 2 tests -----------------------------------------------------------------------------
843
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
844
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
845
+ 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
846
+ 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
847
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
848
+
849
+
850
+ ------------------------------------------------------------------------------ benchmark 'citm_catalog unpackb': 2 tests ------------------------------------------------------------------------------
851
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
852
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
853
+ 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
854
+ 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
855
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
856
+
857
+
858
+ ----------------------------------------------------------------------------------- benchmark 'github packb': 2 tests -----------------------------------------------------------------------------------
859
+ Name (time in us) Min Max Mean StdDev Median IQR Outliers OPS (Kops/s) Rounds Iterations
860
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
861
+ 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
862
+ 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
863
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
864
+
865
+
866
+ ----------------------------------------------------------------------------------- benchmark 'github unpackb': 2 tests -----------------------------------------------------------------------------------
867
+ Name (time in us) Min Max Mean StdDev Median IQR Outliers OPS (Kops/s) Rounds Iterations
868
+ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
869
+ 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
870
+ 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
871
+ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
872
+
873
+ --------------------------------------------------------------------------------------- benchmark 'twitter packb': 2 tests ---------------------------------------------------------------------------------------
874
+ Name (time in us) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
875
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
876
+ 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
877
+ 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
878
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
879
+
880
+
881
+ ------------------------------------------------------------------------------ benchmark 'twitter unpackb': 2 tests -----------------------------------------------------------------------------
882
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
883
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
884
+ 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
885
+ 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
886
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
887
+ ```
888
+ ### Reproducing
889
+
890
+ 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.
891
+
892
+ The latency results can be reproduced using `./scripts/benchmark.sh` and graphs using
893
+ `pytest --benchmark-histogram benchmarks/bench_*`.
894
+ ## Questions
895
+
896
+ ### Why can't I install it from PyPI?
897
+
898
+ Probably `pip` needs to be upgraded to version 20.3 or later to support
899
+ the latest manylinux_x_y or universal2 wheel formats.
900
+
901
+ ### Will it deserialize to dataclasses, UUIDs, decimals, etc or support object_hook?
902
+
903
+ No. This requires a schema specifying what types are expected and how to
904
+ handle errors etc. This is addressed by data validation libraries a
905
+ level above this.
906
+
907
+ ## Packaging
908
+
909
+ To package ormsgpack requires [Rust](https://www.rust-lang.org/) 1.65
910
+ or newer and the [maturin](https://github.com/PyO3/maturin) build
911
+ tool. The default feature `unstable-simd` enables the usage of SIMD
912
+ operations and requires nightly Rust. The recommended build command
913
+ is:
914
+
915
+ ```sh
916
+ maturin build --release --strip
917
+ ```
918
+
919
+ ormsgpack is tested on Linux/amd64, Linux/aarch64, Linux/armv7, macOS/amd64 and Windows/amd64.
920
+
921
+ There are no runtime dependencies other than libc.
922
+
923
+ ## License
924
+
925
+ orjson was written by ijl <<ijl@mailbox.org>>, copyright 2018 - 2021, licensed
926
+ under both the Apache 2 and MIT licenses.
927
+
928
+ ormsgpack was forked from orjson by Aviram Hassan and is now maintained by Emanuele Giaquinta (@exg), licensed
929
+ same as orjson.
930
+
@@ -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=1ZpRl7NI5FUTGBGfAoLBw2DqQx_-H3hwfjZ2VbdjU5g,95
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.cp313-win_amd64.pyd,sha256=B5k8TIZfCGgUx9MInbIKJhzvKZN0QGoGk2quTHOQ7NQ,292352
9
+ ormsgpack-1.6.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.7.4)
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-none-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.