ormsgpack 1.9.1__cp313-cp313-musllinux_1_2_x86_64.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,47 @@
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_ENUM,
11
+ OPT_PASSTHROUGH_SUBCLASS,
12
+ OPT_PASSTHROUGH_TUPLE,
13
+ OPT_PASSTHROUGH_UUID,
14
+ OPT_SERIALIZE_NUMPY,
15
+ OPT_SERIALIZE_PYDANTIC,
16
+ OPT_SORT_KEYS,
17
+ OPT_UTC_Z,
18
+ Ext,
19
+ MsgpackDecodeError,
20
+ MsgpackEncodeError,
21
+ __version__,
22
+ packb,
23
+ unpackb,
24
+ )
25
+
26
+ __all__ = (
27
+ "__version__",
28
+ "packb",
29
+ "unpackb",
30
+ "Ext",
31
+ "MsgpackDecodeError",
32
+ "MsgpackEncodeError",
33
+ "OPT_NAIVE_UTC",
34
+ "OPT_NON_STR_KEYS",
35
+ "OPT_OMIT_MICROSECONDS",
36
+ "OPT_PASSTHROUGH_BIG_INT",
37
+ "OPT_PASSTHROUGH_DATACLASS",
38
+ "OPT_PASSTHROUGH_DATETIME",
39
+ "OPT_PASSTHROUGH_ENUM",
40
+ "OPT_PASSTHROUGH_SUBCLASS",
41
+ "OPT_PASSTHROUGH_TUPLE",
42
+ "OPT_PASSTHROUGH_UUID",
43
+ "OPT_SERIALIZE_NUMPY",
44
+ "OPT_SERIALIZE_PYDANTIC",
45
+ "OPT_SORT_KEYS",
46
+ "OPT_UTC_Z",
47
+ )
ormsgpack/__init__.pyi ADDED
@@ -0,0 +1,35 @@
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_ENUM: int
28
+ OPT_PASSTHROUGH_SUBCLASS: int
29
+ OPT_PASSTHROUGH_TUPLE: int
30
+ OPT_PASSTHROUGH_UUID: int
31
+ OPT_SERIALIZE_NUMPY: int
32
+ OPT_SERIALIZE_PYDANTIC: int
33
+ OPT_NON_STR_KEYS: int
34
+ OPT_SORT_KEYS: int
35
+ OPT_UTC_Z: int
@@ -0,0 +1,7 @@
1
+ # SPDX-License-Identifier: (Apache-2.0 OR MIT)
2
+
3
+ import os
4
+
5
+
6
+ def get_hook_dirs() -> list[str]:
7
+ return [os.path.dirname(__file__)]
@@ -0,0 +1,7 @@
1
+ # SPDX-License-Identifier: (Apache-2.0 OR MIT)
2
+
3
+ hiddenimports = [
4
+ "dataclasses",
5
+ "enum",
6
+ "uuid",
7
+ ]
ormsgpack/py.typed ADDED
File without changes
@@ -0,0 +1,922 @@
1
+ Metadata-Version: 2.4
2
+ Name: ormsgpack
3
+ Version: 1.9.1
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.
124
+
125
+ The output is a `bytes` object.
126
+
127
+ The global interpreter lock (GIL) is held for the duration of the call.
128
+
129
+ It raises `MsgpackEncodeError` on an unsupported type. This exception message
130
+ describes the invalid object with the error message
131
+ `Type is not msgpack serializable: ...`. To fix this, specify
132
+ [default](#default).
133
+
134
+ It raises `MsgpackEncodeError` on a `str` that contains invalid UTF-8.
135
+
136
+ It raises `MsgpackEncodeError` if a `dict` has a key of a type other than `str` or `bytes`,
137
+ unless `OPT_NON_STR_KEYS` is specified.
138
+
139
+ It raises `MsgpackEncodeError` if the output of `default` recurses to handling by
140
+ `default` more than 254 levels deep.
141
+
142
+ It raises `MsgpackEncodeError` on circular references.
143
+
144
+ It raises `MsgpackEncodeError` if a `tzinfo` on a datetime object is
145
+ unsupported.
146
+
147
+ `MsgpackEncodeError` is a subclass of `TypeError`.
148
+
149
+ #### default
150
+
151
+ To serialize a subclass or arbitrary types, specify `default` as a
152
+ callable that returns a supported type. `default` may be a function,
153
+ lambda, or callable class instance. To specify that a type was not
154
+ handled by `default`, raise an exception such as `TypeError`.
155
+
156
+ ```python
157
+ >>> import ormsgpack, decimal
158
+ >>> def default(obj):
159
+ ... if isinstance(obj, decimal.Decimal):
160
+ ... return str(obj)
161
+ ... raise TypeError
162
+ ...
163
+ >>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"))
164
+ TypeError: Type is not msgpack serializable: decimal.Decimal
165
+ >>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"), default=default)
166
+ b'\xb80.0842389659712649442845'
167
+ >>> ormsgpack.packb({1, 2}, default=default)
168
+ TypeError: Type is not msgpack serializable: set
169
+ ```
170
+
171
+ The `default` callable may return an object that itself
172
+ must be handled by `default` up to 254 times before an exception
173
+ is raised.
174
+
175
+ It is important that `default` raise an exception if a type cannot be handled.
176
+ Python otherwise implicitly returns `None`, which appears to the caller
177
+ like a legitimate value and is serialized:
178
+
179
+ ```python
180
+ >>> import ormsgpack, decimal
181
+ >>> def default(obj):
182
+ ... if isinstance(obj, decimal.Decimal):
183
+ ... return str(obj)
184
+ ...
185
+ >>> ormsgpack.packb({"set":{1, 2}}, default=default)
186
+ b'\x81\xa3set\xc0'
187
+ >>> ormsgpack.unpackb(_)
188
+ {'set': None}
189
+ ```
190
+
191
+ To serialize a type as a MessagePack extension type, return an
192
+ `ormsgpack.Ext` object. The instantiation arguments are an integer in
193
+ the range `[0, 127]` and a `bytes` object, defining the type and
194
+ value, respectively.
195
+
196
+ ```python
197
+ >>> import ormsgpack, decimal
198
+ >>> def default(obj):
199
+ ... if isinstance(obj, decimal.Decimal):
200
+ ... return ormsgpack.Ext(0, str(obj).encode())
201
+ ... raise TypeError
202
+ ...
203
+ >>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"), default=default)
204
+ b'\xc7\x18\x000.0842389659712649442845'
205
+ ```
206
+
207
+ `default` can also be used to serialize some supported types to a custom
208
+ format by enabling the corresponding passthrough options.
209
+
210
+ #### option
211
+
212
+ To modify how data is serialized, specify `option`. Each `option` is an integer
213
+ constant in `ormsgpack`. To specify multiple options, mask them together, e.g.,
214
+ `option=ormsgpack.OPT_NON_STR_KEYS | ormsgpack.OPT_NAIVE_UTC`.
215
+
216
+ ##### `OPT_NAIVE_UTC`
217
+
218
+ Serialize `datetime.datetime` objects without a `tzinfo` and `numpy.datetime64`
219
+ objects as UTC. This has no effect on `datetime.datetime` objects that have
220
+ `tzinfo` set.
221
+
222
+ ```python
223
+ >>> import ormsgpack, datetime
224
+ >>> ormsgpack.packb(
225
+ ... datetime.datetime(1970, 1, 1, 0, 0, 0),
226
+ ... )
227
+ b'\xb31970-01-01T00:00:00'
228
+ >>> ormsgpack.unpackb(_)
229
+ '1970-01-01T00:00:00'
230
+ >>> ormsgpack.packb(
231
+ ... datetime.datetime(1970, 1, 1, 0, 0, 0),
232
+ ... option=ormsgpack.OPT_NAIVE_UTC,
233
+ ... )
234
+ b'\xb91970-01-01T00:00:00+00:00'
235
+ >>> ormsgpack.unpackb(_)
236
+ '1970-01-01T00:00:00+00:00'
237
+ ```
238
+
239
+ ##### `OPT_NON_STR_KEYS`
240
+
241
+ Serialize `dict` keys of type other than `str`. This allows `dict` keys
242
+ to be one of `str`, `int`, `float`, `bool`, `None`, `datetime.datetime`,
243
+ `datetime.date`, `datetime.time`, `enum.Enum`, and `uuid.UUID`.
244
+ `dict` keys of unsupported types are not handled using `default` and
245
+ result in `MsgpackEncodeError` being raised.
246
+
247
+ ```python
248
+ >>> import ormsgpack, datetime, uuid
249
+ >>> ormsgpack.packb(
250
+ ... {uuid.UUID("7202d115-7ff3-4c81-a7c1-2a1f067b1ece"): [1, 2, 3]},
251
+ ... option=ormsgpack.OPT_NON_STR_KEYS,
252
+ ... )
253
+ b'\x81\xd9$7202d115-7ff3-4c81-a7c1-2a1f067b1ece\x93\x01\x02\x03'
254
+ >>> ormsgpack.unpackb(_)
255
+ {'7202d115-7ff3-4c81-a7c1-2a1f067b1ece': [1, 2, 3]}
256
+ >>> ormsgpack.packb(
257
+ ... {datetime.datetime(1970, 1, 1, 0, 0, 0): [1, 2, 3]},
258
+ ... option=ormsgpack.OPT_NON_STR_KEYS | ormsgpack.OPT_NAIVE_UTC,
259
+ ... )
260
+ b'\x81\xb91970-01-01T00:00:00+00:00\x93\x01\x02\x03'
261
+ >>> ormsgpack.unpackb(_)
262
+ {'1970-01-01T00:00:00+00:00': [1, 2, 3]}
263
+ ```
264
+
265
+ These types are generally serialized how they would be as
266
+ values, e.g., `datetime.datetime` is still an RFC 3339 string and respects
267
+ options affecting it.
268
+
269
+ This option has the risk of creating duplicate keys. This is because non-`str`
270
+ objects may serialize to the same `str` as an existing key, e.g.,
271
+ `{"1970-01-01T00:00:00+00:00": true, datetime.datetime(1970, 1, 1, 0, 0, 0): false}`.
272
+ The last key to be inserted to the `dict` will be serialized last and a msgpack deserializer will presumably take the last
273
+ occurrence of a key (in the above, `false`). The first value will be lost.
274
+
275
+ This option is not compatible with `ormsgpack.OPT_SORT_KEYS`.
276
+
277
+ ##### `OPT_OMIT_MICROSECONDS`
278
+
279
+ Do not serialize the microsecond component of `datetime.datetime`,
280
+ `datetime.time` and `numpy.datetime64` instances.
281
+
282
+ ```python
283
+ >>> import ormsgpack, datetime
284
+ >>> ormsgpack.packb(
285
+ ... datetime.datetime(1970, 1, 1, 0, 0, 0, 1),
286
+ ... )
287
+ b'\xba1970-01-01T00:00:00.000001'
288
+ >>> ormsgpack.unpackb(_)
289
+ '1970-01-01T00:00:00.000001'
290
+ >>> ormsgpack.packb(
291
+ ... datetime.datetime(1970, 1, 1, 0, 0, 0, 1),
292
+ ... option=ormsgpack.OPT_OMIT_MICROSECONDS,
293
+ ... )
294
+ b'\xb31970-01-01T00:00:00'
295
+ >>> ormsgpack.unpackb(_)
296
+ '1970-01-01T00:00:00'
297
+ ```
298
+
299
+ ##### `OPT_PASSTHROUGH_BIG_INT`
300
+
301
+ Enable passthrough of `int` instances smaller than -9223372036854775807 or
302
+ larger than 18446744073709551615 to `default`.
303
+
304
+ ```python
305
+ >>> import ormsgpack
306
+ >>> ormsgpack.packb(
307
+ ... 2**65,
308
+ ... )
309
+ TypeError: Integer exceeds 64-bit range
310
+ >>> ormsgpack.packb(
311
+ ... 2**65,
312
+ ... option=ormsgpack.OPT_PASSTHROUGH_BIG_INT,
313
+ ... default=lambda _: {"type": "bigint", "value": str(_) }
314
+ ... )
315
+ b'\x82\xa4type\xa6bigint\xa5value\xb436893488147419103232'
316
+ >>> ormsgpack.unpackb(_)
317
+ {'type': 'bigint', 'value': '36893488147419103232'}
318
+ ```
319
+
320
+ ##### `OPT_PASSTHROUGH_DATACLASS`
321
+
322
+ Enable passthrough of `dataclasses.dataclass` instances to `default`.
323
+
324
+
325
+ ```python
326
+ >>> import ormsgpack, dataclasses
327
+ >>> @dataclasses.dataclass
328
+ ... class User:
329
+ ... id: str
330
+ ... name: str
331
+ ... password: str
332
+ ...
333
+ >>> def default(obj):
334
+ ... if isinstance(obj, User):
335
+ ... return {"id": obj.id, "name": obj.name}
336
+ ... raise TypeError
337
+ ...
338
+ >>> ormsgpack.packb(User("3b1", "asd", "zxc"))
339
+ b'\x83\xa2id\xa33b1\xa4name\xa3asd\xa8password\xa3zxc'
340
+ >>> ormsgpack.packb(User("3b1", "asd", "zxc"), option=ormsgpack.OPT_PASSTHROUGH_DATACLASS)
341
+ TypeError: Type is not msgpack serializable: User
342
+ >>> ormsgpack.packb(
343
+ ... User("3b1", "asd", "zxc"),
344
+ ... option=ormsgpack.OPT_PASSTHROUGH_DATACLASS,
345
+ ... default=default,
346
+ ... )
347
+ b'\x82\xa2id\xa33b1\xa4name\xa3asd'
348
+ ```
349
+
350
+ ##### `OPT_PASSTHROUGH_DATETIME`
351
+
352
+ Enable passthrough of `datetime.datetime`, `datetime.date`, and
353
+ `datetime.time` instances to `default`.
354
+
355
+ ```python
356
+ >>> import ormsgpack, datetime
357
+ >>> def default(obj):
358
+ ... if isinstance(obj, datetime.datetime):
359
+ ... return obj.strftime("%a, %d %b %Y %H:%M:%S GMT")
360
+ ... raise TypeError
361
+ ...
362
+ >>> ormsgpack.packb({"created_at": datetime.datetime(1970, 1, 1)})
363
+ b'\x81\xaacreated_at\xb31970-01-01T00:00:00'
364
+ >>> ormsgpack.packb({"created_at": datetime.datetime(1970, 1, 1)}, option=ormsgpack.OPT_PASSTHROUGH_DATETIME)
365
+ TypeError: Type is not msgpack serializable: datetime.datetime
366
+ >>> ormsgpack.packb(
367
+ ... {"created_at": datetime.datetime(1970, 1, 1)},
368
+ ... option=ormsgpack.OPT_PASSTHROUGH_DATETIME,
369
+ ... default=default,
370
+ ... )
371
+ b'\x81\xaacreated_at\xbdThu, 01 Jan 1970 00:00:00 GMT'
372
+ ```
373
+
374
+ ##### `OPT_PASSTHROUGH_ENUM`
375
+
376
+ Enable passthrough of `enum.Enum` instances to `default`.
377
+
378
+ ##### `OPT_PASSTHROUGH_SUBCLASS`
379
+
380
+ Enable passthrough of subclasses of `str`, `int`, `dict` and `list` to
381
+ `default`.
382
+
383
+ ```python
384
+ >>> import ormsgpack
385
+ >>> class Secret(str):
386
+ ... pass
387
+ ...
388
+ >>> def default(obj):
389
+ ... if isinstance(obj, Secret):
390
+ ... return "******"
391
+ ... raise TypeError
392
+ ...
393
+ >>> ormsgpack.packb(Secret("zxc"))
394
+ b'\xa3zxc'
395
+ >>> ormsgpack.packb(Secret("zxc"), option=ormsgpack.OPT_PASSTHROUGH_SUBCLASS)
396
+ TypeError: Type is not msgpack serializable: Secret
397
+ >>> ormsgpack.packb(Secret("zxc"), option=ormsgpack.OPT_PASSTHROUGH_SUBCLASS, default=default)
398
+ b'\xa6******'
399
+ ```
400
+
401
+ ##### `OPT_PASSTHROUGH_TUPLE`
402
+
403
+ Enable passthrough of `tuple` instances to `default`.
404
+
405
+ ```python
406
+ >>> import ormsgpack
407
+ >>> ormsgpack.packb(
408
+ ... (9193, "test", 42),
409
+ ... )
410
+ b'\x93\xcd#\xe9\xa4test*'
411
+ >>> ormsgpack.unpackb(_)
412
+ [9193, 'test', 42]
413
+ >>> ormsgpack.packb(
414
+ ... (9193, "test", 42),
415
+ ... option=ormsgpack.OPT_PASSTHROUGH_TUPLE,
416
+ ... default=lambda _: {"type": "tuple", "value": list(_)}
417
+ ... )
418
+ b'\x82\xa4type\xa5tuple\xa5value\x93\xcd#\xe9\xa4test*'
419
+ >>> ormsgpack.unpackb(_)
420
+ {'type': 'tuple', 'value': [9193, 'test', 42]}
421
+ ```
422
+
423
+ ##### `OPT_PASSTHROUGH_UUID`
424
+
425
+ Enable passthrough of `uuid.UUID` instances to `default`.
426
+
427
+ ##### `OPT_SERIALIZE_NUMPY`
428
+
429
+ Serialize `numpy.ndarray` instances. For more, see
430
+ [numpy](#numpy).
431
+
432
+ ##### `OPT_SERIALIZE_PYDANTIC`
433
+ Serialize `pydantic.BaseModel` instances.
434
+
435
+ ##### `OPT_SORT_KEYS`
436
+
437
+ Serialize `dict` keys and pydantic model fields in sorted order. The default
438
+ is to serialize in an unspecified order.
439
+
440
+ This can be used to ensure the order is deterministic for hashing or tests.
441
+ It has a substantial performance penalty and is not recommended in general.
442
+
443
+ ```python
444
+ >>> import ormsgpack
445
+ >>> ormsgpack.packb({"b": 1, "c": 2, "a": 3})
446
+ b'\x83\xa1b\x01\xa1c\x02\xa1a\x03'
447
+ >>> ormsgpack.packb({"b": 1, "c": 2, "a": 3}, option=ormsgpack.OPT_SORT_KEYS)
448
+ b'\x83\xa1a\x03\xa1b\x01\xa1c\x02'
449
+ ```
450
+
451
+ The sorting is not collation/locale-aware:
452
+
453
+ ```python
454
+ >>> import ormsgpack
455
+ >>> ormsgpack.packb({"a": 1, "ä": 2, "A": 3}, option=ormsgpack.OPT_SORT_KEYS)
456
+ b'\x83\xa1A\x03\xa1a\x01\xa2\xc3\xa4\x02'
457
+ ```
458
+
459
+ `dataclass` also serialize as maps but this has no effect on them.
460
+
461
+ ##### `OPT_UTC_Z`
462
+
463
+ Serialize a UTC timezone on `datetime.datetime` and `numpy.datetime64` instances
464
+ as `Z` instead of `+00:00`.
465
+
466
+ ```python
467
+ >>> import ormsgpack, datetime
468
+ >>> ormsgpack.packb(
469
+ ... datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc),
470
+ ... )
471
+ b'\xb91970-01-01T00:00:00+00:00'
472
+ >>> ormsgpack.packb(
473
+ ... datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc),
474
+ ... option=ormsgpack.OPT_UTC_Z
475
+ ... )
476
+ b'\xb41970-01-01T00:00:00Z'
477
+ ```
478
+
479
+ ### Deserialize
480
+ ```python
481
+ def unpackb(
482
+ __obj: Union[bytes, bytearray, memoryview],
483
+ /,
484
+ ext_hook: Optional[Callable[[int, bytes], Any]] = ...,
485
+ option: Optional[int] = ...,
486
+ ) -> Any: ...
487
+ ```
488
+
489
+ `unpackb()` deserializes msgpack to Python objects. It deserializes to `dict`,
490
+ `list`, `int`, `float`, `str`, `bool`, `bytes` and `None` objects.
491
+
492
+ `bytes`, `bytearray`, `memoryview` input are accepted.
493
+
494
+ ormsgpack maintains a cache of map keys for the duration of the process. This
495
+ causes a net reduction in memory usage by avoiding duplicate strings. The
496
+ keys must be at most 64 bytes to be cached and 512 entries are stored.
497
+
498
+ The global interpreter lock (GIL) is held for the duration of the call.
499
+
500
+ It raises `MsgpackDecodeError` if given an invalid type or invalid
501
+ msgpack.
502
+
503
+ `MsgpackDecodeError` is a subclass of `ValueError`.
504
+
505
+ #### ext_hook
506
+
507
+ To deserialize extension types, specify the optional `ext_hook`
508
+ argument. The value should be a callable and is invoked with the
509
+ extension type and value as arguments.
510
+
511
+ ```python
512
+ >>> import ormsgpack, decimal
513
+ >>> def ext_hook(tag, data):
514
+ ... if tag == 0:
515
+ ... return decimal.Decimal(data.decode())
516
+ ... raise TypeError
517
+ ...
518
+ >>> ormsgpack.packb(
519
+ ... ormsgpack.Ext(0, str(decimal.Decimal("0.0842389659712649442845")).encode())
520
+ ... )
521
+ b'\xc7\x18\x000.0842389659712649442845'
522
+ >>> ormsgpack.unpackb(_, ext_hook=ext_hook)
523
+ Decimal('0.0842389659712649442845'
524
+ ```
525
+
526
+ #### option
527
+ `unpackb()` supports the `OPT_NON_STR_KEYS` option, that is similar to original msgpack's `strict_map_key=False`.
528
+ Be aware that this option is considered unsafe and disabled by default in msgpack due to possibility of HashDoS.
529
+
530
+ ## Types
531
+
532
+ ### dataclass
533
+
534
+ ormsgpack serializes instances of `dataclasses.dataclass` natively. It serializes
535
+ instances 40-50x as fast as other libraries and avoids a severe slowdown seen
536
+ in other libraries compared to serializing `dict`.
537
+
538
+ It is supported to pass all variants of dataclasses, including dataclasses
539
+ using `__slots__`, frozen dataclasses, those with optional or default
540
+ attributes, and subclasses. There is a performance benefit to not
541
+ using `__slots__`.
542
+
543
+ Dataclasses are serialized as maps, with every attribute serialized and in
544
+ the order given on class definition:
545
+
546
+ ```python
547
+ >>> import dataclasses, ormsgpack, typing
548
+ >>> @dataclasses.dataclass
549
+ ... class Member:
550
+ ... id: int
551
+ ... active: bool = dataclasses.field(default=False)
552
+ ...
553
+ >>> @dataclasses.dataclass
554
+ ... class Object:
555
+ ... id: int
556
+ ... name: str
557
+ ... members: typing.List[Member]
558
+ ...
559
+ >>> ormsgpack.packb(Object(1, "a", [Member(1, True), Member(2)]))
560
+ b'\x83\xa2id\x01\xa4name\xa1a\xa7members\x92\x82\xa2id\x01\xa6active\xc3\x82\xa2id\x02\xa6active\xc2'
561
+ ```
562
+ #### Performance
563
+ ![alt text](doc/dataclass.svg "dataclass")
564
+
565
+ ```
566
+ --------------------------------------------------------------------------------- benchmark 'dataclass': 2 tests --------------------------------------------------------------------------------
567
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
568
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
569
+ 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
570
+ 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
571
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
572
+ ```
573
+
574
+ ### datetime
575
+
576
+ ormsgpack serializes `datetime.datetime` objects to
577
+ [RFC 3339](https://tools.ietf.org/html/rfc3339) format,
578
+ e.g., "1970-01-01T00:00:00+00:00". This is a subset of ISO 8601 and is
579
+ compatible with `isoformat()` in the standard library.
580
+
581
+ ```python
582
+ >>> import ormsgpack, datetime, zoneinfo
583
+ >>> ormsgpack.packb(
584
+ ... datetime.datetime(2018, 12, 1, 2, 3, 4, 9, tzinfo=zoneinfo.ZoneInfo('Australia/Adelaide'))
585
+ ... )
586
+ b'\xd9 2018-12-01T02:03:04.000009+10:30'
587
+ >>> ormsgpack.unpackb(_)
588
+ '2018-12-01T02:03:04.000009+10:30'
589
+ >>> ormsgpack.packb(
590
+ ... datetime.datetime.fromtimestamp(4123518902).replace(tzinfo=datetime.timezone.utc)
591
+ ... )
592
+ b'\xb92100-09-02T00:55:02+00:00'
593
+ >>> ormsgpack.unpackb(_)
594
+ '2100-09-02T00:55:02+00:00'
595
+ >>> ormsgpack.packb(
596
+ ... datetime.datetime.fromtimestamp(4123518902)
597
+ ... )
598
+ b'\xb32100-09-02T00:55:02'
599
+ >>> ormsgpack.unpackb(_)
600
+ '2100-09-02T00:55:02'
601
+ ```
602
+
603
+ `datetime.datetime` supports instances with a `tzinfo` that is `None`,
604
+ `datetime.timezone.utc`, a timezone instance from the python3.9+ `zoneinfo`
605
+ module, or a timezone instance from the third-party `pendulum`, `pytz`, or
606
+ `dateutil`/`arrow` libraries.
607
+
608
+ `datetime.time` objects must not have a `tzinfo`.
609
+
610
+ ```python
611
+ >>> import ormsgpack, datetime
612
+ >>> ormsgpack.packb(datetime.time(12, 0, 15, 290))
613
+ b'\xaf12:00:15.000290'
614
+ >>> ormsgpack.unpackb(_)
615
+ '12:00:15.000290'
616
+ ```
617
+
618
+ `datetime.date` objects will always serialize.
619
+
620
+ ```python
621
+ >>> import ormsgpack, datetime
622
+ >>> ormsgpack.packb(datetime.date(1900, 1, 2))
623
+ b'\xaa1900-01-02'
624
+ >>> ormsgpack.unpackb(_)
625
+ '1900-01-02'
626
+ ```
627
+
628
+ Errors with `tzinfo` result in `MsgpackEncodeError` being raised.
629
+
630
+ To use "Z" suffix instead of "+00:00" to indicate UTC ("Zulu") time, use the option
631
+ `ormsgpack.OPT_UTC_Z`.
632
+
633
+ To assume datetimes without timezone are UTC, use the option `ormsgpack.OPT_NAIVE_UTC`.
634
+
635
+ ### enum
636
+
637
+ ormsgpack serializes enums natively. Options apply to their values.
638
+
639
+ ```python
640
+ >>> import enum, datetime, ormsgpack
641
+ >>> class DatetimeEnum(enum.Enum):
642
+ ... EPOCH = datetime.datetime(1970, 1, 1, 0, 0, 0)
643
+ ...
644
+ >>> ormsgpack.packb(DatetimeEnum.EPOCH)
645
+ b'\xb31970-01-01T00:00:00'
646
+ >>> ormsgpack.unpackb(_)
647
+ '1970-01-01T00:00:00'
648
+ >>> ormsgpack.packb(DatetimeEnum.EPOCH, option=ormsgpack.OPT_NAIVE_UTC)
649
+ b'\xb91970-01-01T00:00:00+00:00'
650
+ >>> ormsgpack.unpackb(_)
651
+ '1970-01-01T00:00:00+00:00'
652
+ ```
653
+
654
+ Enums with members that are not supported types can be serialized using
655
+ `default`:
656
+
657
+ ```python
658
+ >>> import enum, ormsgpack
659
+ >>> class Custom:
660
+ ... def __init__(self, val):
661
+ ... self.val = val
662
+ ...
663
+ >>> def default(obj):
664
+ ... if isinstance(obj, Custom):
665
+ ... return obj.val
666
+ ... raise TypeError
667
+ ...
668
+ >>> class CustomEnum(enum.Enum):
669
+ ... ONE = Custom(1)
670
+ ...
671
+ >>> ormsgpack.packb(CustomEnum.ONE, default=default)
672
+ b'\x01'
673
+ >>> ormsgpack.unpackb(_)
674
+ 1
675
+ ```
676
+
677
+ ### float
678
+
679
+ ormsgpack serializes and deserializes double precision floats with no loss of
680
+ precision and consistent rounding.
681
+
682
+ ### int
683
+
684
+ ormsgpack serializes and deserializes 64-bit integers by default. The range
685
+ supported is a signed 64-bit integer's minimum (-9223372036854775807) to
686
+ an unsigned 64-bit integer's maximum (18446744073709551615).
687
+
688
+ ### numpy
689
+
690
+ ormsgpack natively serializes `numpy.ndarray` and individual
691
+ `numpy.float64`, `numpy.float32`, `numpy.float16`,
692
+ `numpy.int64`, `numpy.int32`, `numpy.int16`, `numpy.int8`,
693
+ `numpy.uint64`, `numpy.uint32`, `numpy.uint16`, `numpy.uint8`,
694
+ `numpy.uintp`, `numpy.intp`, `numpy.datetime64`, and `numpy.bool`
695
+ instances.
696
+
697
+ `numpy.datetime64` instances are serialized as RFC 3339 strings.
698
+
699
+ ormsgpack is faster than all compared libraries at serializing
700
+ numpy instances. Serializing numpy data requires specifying
701
+ `option=ormsgpack.OPT_SERIALIZE_NUMPY`.
702
+
703
+ ```python
704
+ >>> import ormsgpack, numpy
705
+ >>> ormsgpack.packb(
706
+ ... numpy.array([[1, 2, 3], [4, 5, 6]]),
707
+ ... option=ormsgpack.OPT_SERIALIZE_NUMPY,
708
+ ... )
709
+ b'\x92\x93\x01\x02\x03\x93\x04\x05\x06'
710
+ >>> ormsgpack.unpackb(_)
711
+ [[1, 2, 3], [4, 5, 6]]
712
+ ```
713
+
714
+ The array must be a contiguous C array (`C_CONTIGUOUS`) and one of the
715
+ supported datatypes.
716
+
717
+ If an array is not a contiguous C array or contains an supported datatype,
718
+ ormsgpack falls through to `default`. In `default`, `obj.tolist()` can be
719
+ specified. If an array is malformed, which is not expected,
720
+ `ormsgpack.MsgpackEncodeError` is raised.
721
+
722
+ #### Performance
723
+ ![alt text](doc/numpy_float64.svg "numpy")
724
+ ![alt text](doc/numpy_int8.svg "numpy int8")
725
+ ![alt text](doc/numpy_int32.svg "numpy int32")
726
+ ![alt text](doc/numpy_npbool.svg "numpy npbool")
727
+ ![alt text](doc/numpy_uint8.svg "numpy uint8")
728
+ ```
729
+ ---------------------------------------------------------------------------------- benchmark 'numpy float64': 2 tests ---------------------------------------------------------------------------------
730
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
731
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
732
+ 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
733
+ 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
734
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
735
+
736
+
737
+ ------------------------------------------------------------------------------------- benchmark 'numpy int32': 2 tests -------------------------------------------------------------------------------------
738
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
739
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
740
+ 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
741
+ 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
742
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
743
+
744
+
745
+ -------------------------------------------------------------------------------- benchmark 'numpy int8': 2 tests ---------------------------------------------------------------------------------
746
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
747
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
748
+ 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
749
+ 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
750
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
751
+
752
+
753
+ ------------------------------------------------------------------------------------- benchmark 'numpy npbool': 2 tests --------------------------------------------------------------------------------------
754
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
755
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
756
+ 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
757
+ 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
758
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
759
+
760
+
761
+ --------------------------------------------------------------------------------- benchmark 'numpy uint8': 2 tests ---------------------------------------------------------------------------------
762
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
763
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
764
+ 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
765
+ 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
766
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
767
+ ```
768
+
769
+ ### uuid
770
+
771
+ ormsgpack serializes `uuid.UUID` instances to
772
+ [RFC 4122](https://tools.ietf.org/html/rfc4122) format, e.g.,
773
+ "f81d4fae-7dec-11d0-a765-00a0c91e6bf6".
774
+
775
+ ```python
776
+ >>> import ormsgpack, uuid
777
+ >>> ormsgpack.packb(uuid.UUID('f81d4fae-7dec-11d0-a765-00a0c91e6bf6'))
778
+ b'\xd9$f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
779
+ >>> ormsgpack.unpackb(_)
780
+ 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
781
+ >>> ormsgpack.packb(uuid.uuid5(uuid.NAMESPACE_DNS, "python.org"))
782
+ b'\xd9$886313e1-3b8a-5372-9b90-0c9aee199e5d'
783
+ >>> ormsgpack.unpackb(_)
784
+ '886313e1-3b8a-5372-9b90-0c9aee199e5d
785
+ ```
786
+
787
+ ### Pydantic
788
+ ormsgpack serializes `pydantic.BaseModel` instances natively, with
789
+ [duck-typing](https://docs.pydantic.dev/2.10/concepts/serialization/#serializing-with-duck-typing).
790
+ This is equivalent to serializing
791
+ `model.model_dump(serialize_as_any=True)` with Pydantic V2 or
792
+ `model.dict()`with Pydantic V1.
793
+
794
+ #### Performance
795
+ ![alt text](doc/pydantic.svg "pydantic")
796
+
797
+ ```
798
+ -------------------------------------------------------------------------------- benchmark 'pydantic': 2 tests ---------------------------------------------------------------------------------
799
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
800
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
801
+ 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
802
+ 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
803
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
804
+ ```
805
+
806
+ ## Latency
807
+ ### Graphs
808
+ ![alt text](doc/twitter_packb.svg "twitter.json serialization")
809
+ ![alt text](doc/twitter_unpackb.svg "twitter.json deserialization")
810
+ ![alt text](doc/github_packb.svg "github.json serialization")
811
+ ![alt text](doc/github_unpackb.svg "github.json deserialization")
812
+ ![alt text](doc/citm_catalog_packb.svg "citm_catalog.json serialization")
813
+ ![alt text](doc/citm_catalog_unpackb.svg "citm_catalog.json deserialization")
814
+ ![alt text](doc/canada_packb.svg "canada.json serialization")
815
+ ![alt text](doc/canada_unpackb.svg "canada.json deserialization")
816
+ ### Data
817
+ ```
818
+ ----------------------------------------------------------------------------- benchmark 'canada packb': 2 tests ------------------------------------------------------------------------------
819
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
820
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
821
+ 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
822
+ 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
823
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
824
+
825
+
826
+ ------------------------------------------------------------------------------- benchmark 'canada unpackb': 2 tests --------------------------------------------------------------------------------
827
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
828
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
829
+ 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
830
+ 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
831
+ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
832
+
833
+
834
+ ----------------------------------------------------------------------------- benchmark 'citm_catalog packb': 2 tests -----------------------------------------------------------------------------
835
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
836
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
837
+ 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
838
+ 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
839
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
840
+
841
+
842
+ ------------------------------------------------------------------------------ benchmark 'citm_catalog unpackb': 2 tests ------------------------------------------------------------------------------
843
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
844
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
845
+ 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
846
+ 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
847
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
848
+
849
+
850
+ ----------------------------------------------------------------------------------- benchmark 'github packb': 2 tests -----------------------------------------------------------------------------------
851
+ Name (time in us) Min Max Mean StdDev Median IQR Outliers OPS (Kops/s) Rounds Iterations
852
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
853
+ 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
854
+ 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
855
+ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
856
+
857
+
858
+ ----------------------------------------------------------------------------------- benchmark 'github unpackb': 2 tests -----------------------------------------------------------------------------------
859
+ Name (time in us) Min Max Mean StdDev Median IQR Outliers OPS (Kops/s) Rounds Iterations
860
+ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
861
+ 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
862
+ 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
863
+ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
864
+
865
+ --------------------------------------------------------------------------------------- benchmark 'twitter packb': 2 tests ---------------------------------------------------------------------------------------
866
+ Name (time in us) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
867
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
868
+ 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
869
+ 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
870
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
871
+
872
+
873
+ ------------------------------------------------------------------------------ benchmark 'twitter unpackb': 2 tests -----------------------------------------------------------------------------
874
+ Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
875
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
876
+ 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
877
+ 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
878
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
879
+ ```
880
+ ### Reproducing
881
+
882
+ 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.
883
+
884
+ The latency results can be reproduced using `./scripts/benchmark.sh` and graphs using
885
+ `pytest --benchmark-histogram benchmarks/bench_*`.
886
+ ## Questions
887
+
888
+ ### Why can't I install it from PyPI?
889
+
890
+ Probably `pip` needs to be upgraded to version 20.3 or later to support
891
+ the latest manylinux_x_y or universal2 wheel formats.
892
+
893
+ ### Will it deserialize to dataclasses, UUIDs, decimals, etc or support object_hook?
894
+
895
+ No. This requires a schema specifying what types are expected and how to
896
+ handle errors etc. This is addressed by data validation libraries a
897
+ level above this.
898
+
899
+ ## Packaging
900
+
901
+ To package ormsgpack requires [Rust](https://www.rust-lang.org/) 1.81
902
+ or newer and the [maturin](https://github.com/PyO3/maturin) build
903
+ tool. The default feature `unstable-simd` enables the usage of SIMD
904
+ operations and requires nightly Rust. The recommended build command
905
+ is:
906
+
907
+ ```sh
908
+ maturin build --release --strip
909
+ ```
910
+
911
+ ormsgpack is tested on Linux/amd64, Linux/aarch64, Linux/armv7, macOS/amd64 and Windows/amd64.
912
+
913
+ There are no runtime dependencies other than libc.
914
+
915
+ ## License
916
+
917
+ orjson was written by ijl <<ijl@mailbox.org>>, copyright 2018 - 2021, licensed
918
+ under both the Apache 2 and MIT licenses.
919
+
920
+ ormsgpack was forked from orjson by Aviram Hassan and is now maintained by Emanuele Giaquinta (@exg), licensed
921
+ same as orjson.
922
+
@@ -0,0 +1,13 @@
1
+ ormsgpack-1.9.1.dist-info/METADATA,sha256=N3FqJyfKD6Yuf0MXMGUYFr0yYjKJZ6nOFjVfQ9uGROs,43472
2
+ ormsgpack-1.9.1.dist-info/WHEEL,sha256=FhhfBGxpw7lUS1vCU0xMKSc8xZ-17phLfvnaRtwemzY,107
3
+ ormsgpack-1.9.1.dist-info/entry_points.txt,sha256=b4bGmxqo1PPqO42Cjz2A2X4Gy4h1PCoOygCzeS-m22I,63
4
+ ormsgpack-1.9.1.dist-info/licenses/LICENSE-APACHE,sha256=pg7qgXUUUxZo1-AHZXMUSf4U0FnTJJ4LyTs23kX3WfI,10847
5
+ ormsgpack-1.9.1.dist-info/licenses/LICENSE-MIT,sha256=I_GOA9xJ35FiL-KnYXZJdATkbO2KcV2dK2enRGVxzKM,1023
6
+ ormsgpack.libs/libgcc_s-1e52349c.so.1,sha256=Ani0u_W_tB8ESsFePO4D2mn2lrgWLhyFdw6RETxBTYM,437537
7
+ ormsgpack/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ ormsgpack/__init__.py,sha256=b8h6Xdy3d26CtlF4EMCUqZl9cPvBT2R5_DQyqFCYgng,1034
9
+ ormsgpack/_pyinstaller/__init__.py,sha256=hcOudyiUz-ny0OE09dNskv7gVZXrsbb5uwg2mScSbG8,133
10
+ ormsgpack/_pyinstaller/hook-ormsgpack.py,sha256=R-YMI5TWEh7mZLFywYSJu2PxG5HeuWrGlSmMbofSyGI,111
11
+ ormsgpack/__init__.pyi,sha256=ZbSQqWnNWV-2cYDTJQRHgBV-W8ZKAU6ymn0j5XtV81Q,870
12
+ ormsgpack/ormsgpack.cpython-313-x86_64-linux-musl.so,sha256=YTLGa0uQhEBVSiBdc8BjXJTpj3-jCefMmKOi6dXRSWo,452937
13
+ ormsgpack-1.9.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.8.3)
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313-musllinux_1_2_x86_64
@@ -0,0 +1,2 @@
1
+ [pyinstaller40]
2
+ hook-dirs=ormsgpack._pyinstaller:get_hook_dirs
@@ -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.
Binary file