ormsgpack 1.10.0__cp311-cp311-musllinux_1_2_armv7l.whl → 1.11.0__cp311-cp311-musllinux_1_2_armv7l.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/ormsgpack.cpython-311-arm-linux-musleabihf.so +0 -0
- ormsgpack-1.11.0.dist-info/METADATA +27 -0
- {ormsgpack-1.10.0.dist-info → ormsgpack-1.11.0.dist-info}/RECORD +8 -8
- {ormsgpack-1.10.0.dist-info → ormsgpack-1.11.0.dist-info}/WHEEL +1 -1
- ormsgpack.libs/libgcc_s-0366c7ba.so.1 +0 -0
- ormsgpack-1.10.0.dist-info/METADATA +0 -964
- ormsgpack.libs/libgcc_s-5b5488a6.so.1 +0 -0
- {ormsgpack-1.10.0.dist-info → ormsgpack-1.11.0.dist-info}/entry_points.txt +0 -0
- {ormsgpack-1.10.0.dist-info → ormsgpack-1.11.0.dist-info}/licenses/LICENSE-APACHE +0 -0
- {ormsgpack-1.10.0.dist-info → ormsgpack-1.11.0.dist-info}/licenses/LICENSE-MIT +0 -0
|
Binary file
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ormsgpack
|
|
3
|
+
Version: 1.11.0
|
|
4
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
5
|
+
Classifier: Intended Audience :: Developers
|
|
6
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: MacOS
|
|
9
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
19
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
20
|
+
Classifier: Programming Language :: Python
|
|
21
|
+
Classifier: Programming Language :: Rust
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
License-File: LICENSE-APACHE
|
|
24
|
+
License-File: LICENSE-MIT
|
|
25
|
+
Home-Page: https://github.com/aviramha/ormsgpack
|
|
26
|
+
Author-email: Aviram Hassan <aviramyhassan@gmail.com>, Emanuele Giaquinta <emanuele.giaquinta@gmail.com>
|
|
27
|
+
Requires-Python: >=3.9
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
ormsgpack-1.
|
|
2
|
-
ormsgpack-1.
|
|
3
|
-
ormsgpack-1.
|
|
4
|
-
ormsgpack-1.
|
|
5
|
-
ormsgpack-1.
|
|
6
|
-
ormsgpack.libs/libgcc_s-
|
|
1
|
+
ormsgpack-1.11.0.dist-info/METADATA,sha256=x9CvZlb3ntSt1O4D0cPWpFUb5kbpUmTdQ2T4qWc4MjY,1244
|
|
2
|
+
ormsgpack-1.11.0.dist-info/WHEEL,sha256=JivmnAsxr6Nudg0vfQ57h7k2qTcv61BCa0rP4SGxnJE,107
|
|
3
|
+
ormsgpack-1.11.0.dist-info/entry_points.txt,sha256=b4bGmxqo1PPqO42Cjz2A2X4Gy4h1PCoOygCzeS-m22I,63
|
|
4
|
+
ormsgpack-1.11.0.dist-info/licenses/LICENSE-APACHE,sha256=pg7qgXUUUxZo1-AHZXMUSf4U0FnTJJ4LyTs23kX3WfI,10847
|
|
5
|
+
ormsgpack-1.11.0.dist-info/licenses/LICENSE-MIT,sha256=I_GOA9xJ35FiL-KnYXZJdATkbO2KcV2dK2enRGVxzKM,1023
|
|
6
|
+
ormsgpack.libs/libgcc_s-0366c7ba.so.1,sha256=QjFj5R7pVqB-p92h2JTCmlyfd3UKsVGW_Y_l3SqOAaU,2753157
|
|
7
7
|
ormsgpack/__init__.py,sha256=A4pm8xaw6_tIqmMoKn2jAGnqYakE96LWk2boEaB783U,1106
|
|
8
8
|
ormsgpack/__init__.pyi,sha256=8j0Ff1n1lcidp8MqWl7iLtujHbuCKxYNcEFM0eEJR2k,926
|
|
9
9
|
ormsgpack/_pyinstaller/__init__.py,sha256=hcOudyiUz-ny0OE09dNskv7gVZXrsbb5uwg2mScSbG8,133
|
|
10
10
|
ormsgpack/_pyinstaller/hook-ormsgpack.py,sha256=R-YMI5TWEh7mZLFywYSJu2PxG5HeuWrGlSmMbofSyGI,111
|
|
11
|
-
ormsgpack/ormsgpack.cpython-311-arm-linux-musleabihf.so,sha256=
|
|
11
|
+
ormsgpack/ormsgpack.cpython-311-arm-linux-musleabihf.so,sha256=T8vkqEk8ChM5AjHWRZqRzUN_yy1AUj5rKsMdsorNBu0,391285
|
|
12
12
|
ormsgpack/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
-
ormsgpack-1.
|
|
13
|
+
ormsgpack-1.11.0.dist-info/RECORD,,
|
|
Binary file
|
|
@@ -1,964 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: ormsgpack
|
|
3
|
-
Version: 1.10.0
|
|
4
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
5
|
-
Classifier: Intended Audience :: Developers
|
|
6
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
7
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
-
Classifier: Operating System :: MacOS
|
|
9
|
-
Classifier: Operating System :: Microsoft :: Windows
|
|
10
|
-
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
-
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
|
-
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
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.9
|
|
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
|
-
|
|
36
|
-

|
|
37
|
-

|
|
38
|
-
|
|
39
|
-
ormsgpack is a fast msgpack serialization library for Python derived
|
|
40
|
-
from [orjson](https://github.com/ijl/orjson), with native support for
|
|
41
|
-
various Python types.
|
|
42
|
-
|
|
43
|
-
ormsgpack supports the following Python implementations:
|
|
44
|
-
|
|
45
|
-
- CPython 3.9, 3.10, 3.11, 3.12 and 3.13
|
|
46
|
-
- PyPy 3.11
|
|
47
|
-
- GraalPy 3.11
|
|
48
|
-
|
|
49
|
-
Releases follow semantic versioning and serializing a new object type
|
|
50
|
-
without an opt-in flag is considered a breaking change.
|
|
51
|
-
|
|
52
|
-
ormsgpack is licensed under both the Apache 2.0 and MIT licenses. The
|
|
53
|
-
repository and issue tracker is
|
|
54
|
-
[github.com/aviramha/ormsgpack](https://github.com/aviramha/ormsgpack), and patches may be
|
|
55
|
-
submitted there. There is a
|
|
56
|
-
[CHANGELOG](https://github.com/aviramha/ormsgpack/blob/master/CHANGELOG.md)
|
|
57
|
-
available in the repository.
|
|
58
|
-
|
|
59
|
-
1. [Usage](#usage)
|
|
60
|
-
1. [Install](#install)
|
|
61
|
-
2. [Quickstart](#quickstart)
|
|
62
|
-
3. [Serialize](#serialize)
|
|
63
|
-
1. [default](#default)
|
|
64
|
-
2. [option](#option)
|
|
65
|
-
4. [Deserialize](#deserialize)
|
|
66
|
-
2. [Types](#types)
|
|
67
|
-
- [none](#none)
|
|
68
|
-
- [bool](#bool)
|
|
69
|
-
- [int](#int)
|
|
70
|
-
- [float](#float)
|
|
71
|
-
- [str](#str)
|
|
72
|
-
- [bytes](#bytes)
|
|
73
|
-
- [list](#list)
|
|
74
|
-
- [tuple](#tuple)
|
|
75
|
-
- [dict](#dict)
|
|
76
|
-
- [dataclass](#dataclass)
|
|
77
|
-
- [date](#date)
|
|
78
|
-
- [time](#time)
|
|
79
|
-
- [datetime](#datetime)
|
|
80
|
-
- [enum](#enum)
|
|
81
|
-
- [uuid](#uuid)
|
|
82
|
-
- [numpy](#numpy)
|
|
83
|
-
- [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
|
-
It natively serializes various Python [types](#Types) and supports
|
|
132
|
-
arbitrary types through the [default](#default) argument.
|
|
133
|
-
The output is a `bytes` object.
|
|
134
|
-
|
|
135
|
-
The global interpreter lock (GIL) is held for the duration of the call.
|
|
136
|
-
|
|
137
|
-
It raises `MsgpackEncodeError` on an unsupported type. This exception
|
|
138
|
-
describes the invalid object with the error message `Type is not
|
|
139
|
-
msgpack serializable: ...`.
|
|
140
|
-
|
|
141
|
-
It raises `MsgpackEncodeError` if a `str` contains invalid UTF-8.
|
|
142
|
-
|
|
143
|
-
It raises `MsgpackEncodeError` if a `dict` has a key of a type other than `str` or `bytes`,
|
|
144
|
-
unless [`OPT_NON_STR_KEYS`](#OPT_NON_STR_KEYS) is specified.
|
|
145
|
-
|
|
146
|
-
It raises `MsgpackEncodeError` if the output of `default` recurses to handling by
|
|
147
|
-
`default` more than 254 levels deep.
|
|
148
|
-
|
|
149
|
-
It raises `MsgpackEncodeError` on circular references.
|
|
150
|
-
|
|
151
|
-
It raises `MsgpackEncodeError` if a `tzinfo` on a datetime object is
|
|
152
|
-
unsupported.
|
|
153
|
-
|
|
154
|
-
`MsgpackEncodeError` is a subclass of `TypeError`.
|
|
155
|
-
|
|
156
|
-
#### default
|
|
157
|
-
|
|
158
|
-
To serialize a subclass or arbitrary types, specify `default` as a
|
|
159
|
-
callable that returns a supported type. `default` may be a function,
|
|
160
|
-
lambda, or callable class instance. To specify that a type was not
|
|
161
|
-
handled by `default`, raise an exception such as `TypeError`.
|
|
162
|
-
|
|
163
|
-
```python
|
|
164
|
-
>>> import ormsgpack, decimal
|
|
165
|
-
>>> def default(obj):
|
|
166
|
-
... if isinstance(obj, decimal.Decimal):
|
|
167
|
-
... return str(obj)
|
|
168
|
-
... raise TypeError
|
|
169
|
-
...
|
|
170
|
-
>>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"))
|
|
171
|
-
TypeError: Type is not msgpack serializable: decimal.Decimal
|
|
172
|
-
>>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"), default=default)
|
|
173
|
-
b'\xb80.0842389659712649442845'
|
|
174
|
-
>>> ormsgpack.packb({1, 2}, default=default)
|
|
175
|
-
TypeError: Type is not msgpack serializable: set
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
The `default` callable may return an object that itself
|
|
179
|
-
must be handled by `default` up to 254 times before an exception
|
|
180
|
-
is raised.
|
|
181
|
-
|
|
182
|
-
It is important that `default` raise an exception if a type cannot be handled.
|
|
183
|
-
Python otherwise implicitly returns `None`, which appears to the caller
|
|
184
|
-
like a legitimate value and is serialized:
|
|
185
|
-
|
|
186
|
-
```python
|
|
187
|
-
>>> import ormsgpack, decimal
|
|
188
|
-
>>> def default(obj):
|
|
189
|
-
... if isinstance(obj, decimal.Decimal):
|
|
190
|
-
... return str(obj)
|
|
191
|
-
...
|
|
192
|
-
>>> ormsgpack.packb({"set":{1, 2}}, default=default)
|
|
193
|
-
b'\x81\xa3set\xc0'
|
|
194
|
-
>>> ormsgpack.unpackb(_)
|
|
195
|
-
{'set': None}
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
To serialize a type as a MessagePack extension type, return an
|
|
199
|
-
`ormsgpack.Ext` object. The instantiation arguments are an integer in
|
|
200
|
-
the range `[0, 127]` and a `bytes` object, defining the type and
|
|
201
|
-
value, respectively.
|
|
202
|
-
|
|
203
|
-
```python
|
|
204
|
-
>>> import ormsgpack, decimal
|
|
205
|
-
>>> def default(obj):
|
|
206
|
-
... if isinstance(obj, decimal.Decimal):
|
|
207
|
-
... return ormsgpack.Ext(0, str(obj).encode())
|
|
208
|
-
... raise TypeError
|
|
209
|
-
...
|
|
210
|
-
>>> ormsgpack.packb(decimal.Decimal("0.0842389659712649442845"), default=default)
|
|
211
|
-
b'\xc7\x18\x000.0842389659712649442845'
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
`default` can also be used to serialize some supported types to a custom
|
|
215
|
-
format by enabling the corresponding passthrough options.
|
|
216
|
-
|
|
217
|
-
#### option
|
|
218
|
-
|
|
219
|
-
To modify how data is serialized, specify `option`. Each `option` is an integer
|
|
220
|
-
constant in `ormsgpack`. To specify multiple options, mask them together, e.g.,
|
|
221
|
-
`option=ormsgpack.OPT_NON_STR_KEYS | ormsgpack.OPT_NAIVE_UTC`.
|
|
222
|
-
|
|
223
|
-
##### `OPT_DATETIME_AS_TIMESTAMP_EXT`
|
|
224
|
-
|
|
225
|
-
Serialize aware `datetime.datetime` instances as timestamp extension objects.
|
|
226
|
-
|
|
227
|
-
##### `OPT_NAIVE_UTC`
|
|
228
|
-
|
|
229
|
-
Serialize naive `datetime.datetime` objects and `numpy.datetime64`
|
|
230
|
-
objects as UTC. This has no effect on aware `datetime.datetime`
|
|
231
|
-
objects.
|
|
232
|
-
|
|
233
|
-
```python
|
|
234
|
-
>>> import ormsgpack, datetime
|
|
235
|
-
>>> ormsgpack.packb(
|
|
236
|
-
... datetime.datetime(1970, 1, 1, 0, 0, 0),
|
|
237
|
-
... )
|
|
238
|
-
b'\xb31970-01-01T00:00:00'
|
|
239
|
-
>>> ormsgpack.unpackb(_)
|
|
240
|
-
'1970-01-01T00:00:00'
|
|
241
|
-
>>> ormsgpack.packb(
|
|
242
|
-
... datetime.datetime(1970, 1, 1, 0, 0, 0),
|
|
243
|
-
... option=ormsgpack.OPT_NAIVE_UTC,
|
|
244
|
-
... )
|
|
245
|
-
b'\xb91970-01-01T00:00:00+00:00'
|
|
246
|
-
>>> ormsgpack.unpackb(_)
|
|
247
|
-
'1970-01-01T00:00:00+00:00'
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
##### `OPT_NON_STR_KEYS`
|
|
251
|
-
|
|
252
|
-
Serialize `dict` keys of type other than `str`. This allows `dict` keys
|
|
253
|
-
to be one of `str`, `int`, `float`, `bool`, `None`, `datetime.datetime`,
|
|
254
|
-
`datetime.date`, `datetime.time`, `enum.Enum`, and `uuid.UUID`.
|
|
255
|
-
All options other than the passthrough ones are supported.
|
|
256
|
-
`dict` keys of unsupported types are not handled using `default` and
|
|
257
|
-
result in `MsgpackEncodeError` being raised.
|
|
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
|
-
Be aware that, when using this option, a serialized map may contain
|
|
278
|
-
elements with the same key, as different `dict` keys may be serialized
|
|
279
|
-
to the same object. In such a case, a msgpack deserializer will
|
|
280
|
-
presumably keep only one element for any given key. For example,
|
|
281
|
-
|
|
282
|
-
```python
|
|
283
|
-
>>> import ormsgpack, datetime
|
|
284
|
-
>>> ormsgpack.packb(
|
|
285
|
-
... {"1970-01-01T00:00:00": True, datetime.datetime(1970, 1, 1, 0, 0, 0): False},
|
|
286
|
-
... option=ormsgpack.OPT_NON_STR_KEYS,
|
|
287
|
-
... )
|
|
288
|
-
b'\x82\xb31970-01-01T00:00:00\xc3\xb31970-01-01T00:00:00\xc2'
|
|
289
|
-
>>> ormsgpack.unpackb(_)
|
|
290
|
-
{'1970-01-01T00:00:00': False}
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
This option is not compatible with `ormsgpack.OPT_SORT_KEYS`.
|
|
294
|
-
|
|
295
|
-
##### `OPT_OMIT_MICROSECONDS`
|
|
296
|
-
|
|
297
|
-
Do not serialize the microsecond component of `datetime.datetime`,
|
|
298
|
-
`datetime.time` and `numpy.datetime64` instances.
|
|
299
|
-
|
|
300
|
-
```python
|
|
301
|
-
>>> import ormsgpack, datetime
|
|
302
|
-
>>> ormsgpack.packb(
|
|
303
|
-
... datetime.datetime(1970, 1, 1, 0, 0, 0, 1),
|
|
304
|
-
... )
|
|
305
|
-
b'\xba1970-01-01T00:00:00.000001'
|
|
306
|
-
>>> ormsgpack.unpackb(_)
|
|
307
|
-
'1970-01-01T00:00:00.000001'
|
|
308
|
-
>>> ormsgpack.packb(
|
|
309
|
-
... datetime.datetime(1970, 1, 1, 0, 0, 0, 1),
|
|
310
|
-
... option=ormsgpack.OPT_OMIT_MICROSECONDS,
|
|
311
|
-
... )
|
|
312
|
-
b'\xb31970-01-01T00:00:00'
|
|
313
|
-
>>> ormsgpack.unpackb(_)
|
|
314
|
-
'1970-01-01T00:00:00'
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
##### `OPT_PASSTHROUGH_BIG_INT`
|
|
318
|
-
|
|
319
|
-
Enable passthrough of `int` instances smaller than -9223372036854775807 or
|
|
320
|
-
larger than 18446744073709551615 to `default`.
|
|
321
|
-
|
|
322
|
-
```python
|
|
323
|
-
>>> import ormsgpack
|
|
324
|
-
>>> ormsgpack.packb(
|
|
325
|
-
... 2**65,
|
|
326
|
-
... )
|
|
327
|
-
TypeError: Integer exceeds 64-bit range
|
|
328
|
-
>>> ormsgpack.packb(
|
|
329
|
-
... 2**65,
|
|
330
|
-
... option=ormsgpack.OPT_PASSTHROUGH_BIG_INT,
|
|
331
|
-
... default=lambda _: {"type": "bigint", "value": str(_) }
|
|
332
|
-
... )
|
|
333
|
-
b'\x82\xa4type\xa6bigint\xa5value\xb436893488147419103232'
|
|
334
|
-
>>> ormsgpack.unpackb(_)
|
|
335
|
-
{'type': 'bigint', 'value': '36893488147419103232'}
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
##### `OPT_PASSTHROUGH_DATACLASS`
|
|
339
|
-
|
|
340
|
-
Enable passthrough of dataclasses to `default`.
|
|
341
|
-
|
|
342
|
-
```python
|
|
343
|
-
>>> import ormsgpack, dataclasses
|
|
344
|
-
>>> @dataclasses.dataclass
|
|
345
|
-
... class User:
|
|
346
|
-
... id: str
|
|
347
|
-
... name: str
|
|
348
|
-
... password: str
|
|
349
|
-
...
|
|
350
|
-
>>> def default(obj):
|
|
351
|
-
... if isinstance(obj, User):
|
|
352
|
-
... return {"id": obj.id, "name": obj.name}
|
|
353
|
-
... raise TypeError
|
|
354
|
-
...
|
|
355
|
-
>>> ormsgpack.packb(User("3b1", "asd", "zxc"))
|
|
356
|
-
b'\x83\xa2id\xa33b1\xa4name\xa3asd\xa8password\xa3zxc'
|
|
357
|
-
>>> ormsgpack.packb(User("3b1", "asd", "zxc"), option=ormsgpack.OPT_PASSTHROUGH_DATACLASS)
|
|
358
|
-
TypeError: Type is not msgpack serializable: User
|
|
359
|
-
>>> ormsgpack.packb(
|
|
360
|
-
... User("3b1", "asd", "zxc"),
|
|
361
|
-
... option=ormsgpack.OPT_PASSTHROUGH_DATACLASS,
|
|
362
|
-
... default=default,
|
|
363
|
-
... )
|
|
364
|
-
b'\x82\xa2id\xa33b1\xa4name\xa3asd'
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
##### `OPT_PASSTHROUGH_DATETIME`
|
|
368
|
-
|
|
369
|
-
Enable passthrough of `datetime.datetime`, `datetime.date`, and
|
|
370
|
-
`datetime.time` instances to `default`.
|
|
371
|
-
|
|
372
|
-
```python
|
|
373
|
-
>>> import ormsgpack, datetime
|
|
374
|
-
>>> def default(obj):
|
|
375
|
-
... if isinstance(obj, datetime.datetime):
|
|
376
|
-
... return obj.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
|
377
|
-
... raise TypeError
|
|
378
|
-
...
|
|
379
|
-
>>> ormsgpack.packb({"created_at": datetime.datetime(1970, 1, 1)})
|
|
380
|
-
b'\x81\xaacreated_at\xb31970-01-01T00:00:00'
|
|
381
|
-
>>> ormsgpack.packb({"created_at": datetime.datetime(1970, 1, 1)}, option=ormsgpack.OPT_PASSTHROUGH_DATETIME)
|
|
382
|
-
TypeError: Type is not msgpack serializable: datetime.datetime
|
|
383
|
-
>>> ormsgpack.packb(
|
|
384
|
-
... {"created_at": datetime.datetime(1970, 1, 1)},
|
|
385
|
-
... option=ormsgpack.OPT_PASSTHROUGH_DATETIME,
|
|
386
|
-
... default=default,
|
|
387
|
-
... )
|
|
388
|
-
b'\x81\xaacreated_at\xbdThu, 01 Jan 1970 00:00:00 GMT'
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
##### `OPT_PASSTHROUGH_ENUM`
|
|
392
|
-
|
|
393
|
-
Enable passthrough of enum members to `default`.
|
|
394
|
-
|
|
395
|
-
##### `OPT_PASSTHROUGH_SUBCLASS`
|
|
396
|
-
|
|
397
|
-
Enable passthrough of subclasses of `str`, `int`, `dict` and `list` to
|
|
398
|
-
`default`.
|
|
399
|
-
|
|
400
|
-
```python
|
|
401
|
-
>>> import ormsgpack
|
|
402
|
-
>>> class Secret(str):
|
|
403
|
-
... pass
|
|
404
|
-
...
|
|
405
|
-
>>> def default(obj):
|
|
406
|
-
... if isinstance(obj, Secret):
|
|
407
|
-
... return "******"
|
|
408
|
-
... raise TypeError
|
|
409
|
-
...
|
|
410
|
-
>>> ormsgpack.packb(Secret("zxc"))
|
|
411
|
-
b'\xa3zxc'
|
|
412
|
-
>>> ormsgpack.packb(Secret("zxc"), option=ormsgpack.OPT_PASSTHROUGH_SUBCLASS)
|
|
413
|
-
TypeError: Type is not msgpack serializable: Secret
|
|
414
|
-
>>> ormsgpack.packb(Secret("zxc"), option=ormsgpack.OPT_PASSTHROUGH_SUBCLASS, default=default)
|
|
415
|
-
b'\xa6******'
|
|
416
|
-
```
|
|
417
|
-
|
|
418
|
-
##### `OPT_PASSTHROUGH_TUPLE`
|
|
419
|
-
|
|
420
|
-
Enable passthrough of `tuple` instances to `default`.
|
|
421
|
-
|
|
422
|
-
```python
|
|
423
|
-
>>> import ormsgpack
|
|
424
|
-
>>> ormsgpack.packb(
|
|
425
|
-
... (9193, "test", 42),
|
|
426
|
-
... )
|
|
427
|
-
b'\x93\xcd#\xe9\xa4test*'
|
|
428
|
-
>>> ormsgpack.unpackb(_)
|
|
429
|
-
[9193, 'test', 42]
|
|
430
|
-
>>> ormsgpack.packb(
|
|
431
|
-
... (9193, "test", 42),
|
|
432
|
-
... option=ormsgpack.OPT_PASSTHROUGH_TUPLE,
|
|
433
|
-
... default=lambda _: {"type": "tuple", "value": list(_)}
|
|
434
|
-
... )
|
|
435
|
-
b'\x82\xa4type\xa5tuple\xa5value\x93\xcd#\xe9\xa4test*'
|
|
436
|
-
>>> ormsgpack.unpackb(_)
|
|
437
|
-
{'type': 'tuple', 'value': [9193, 'test', 42]}
|
|
438
|
-
```
|
|
439
|
-
|
|
440
|
-
##### `OPT_PASSTHROUGH_UUID`
|
|
441
|
-
|
|
442
|
-
Enable passthrough of `uuid.UUID` instances to `default`.
|
|
443
|
-
|
|
444
|
-
##### `OPT_SERIALIZE_NUMPY`
|
|
445
|
-
|
|
446
|
-
Serialize instances of numpy types.
|
|
447
|
-
|
|
448
|
-
##### `OPT_SERIALIZE_PYDANTIC`
|
|
449
|
-
|
|
450
|
-
Serialize `pydantic.BaseModel` instances.
|
|
451
|
-
|
|
452
|
-
##### `OPT_SORT_KEYS`
|
|
453
|
-
|
|
454
|
-
Serialize `dict` keys and pydantic model fields in sorted order. The default
|
|
455
|
-
is to serialize in an unspecified order.
|
|
456
|
-
|
|
457
|
-
This can be used to ensure the order is deterministic for hashing or tests.
|
|
458
|
-
It has a substantial performance penalty and is not recommended in general.
|
|
459
|
-
|
|
460
|
-
```python
|
|
461
|
-
>>> import ormsgpack
|
|
462
|
-
>>> ormsgpack.packb({"b": 1, "c": 2, "a": 3})
|
|
463
|
-
b'\x83\xa1b\x01\xa1c\x02\xa1a\x03'
|
|
464
|
-
>>> ormsgpack.packb({"b": 1, "c": 2, "a": 3}, option=ormsgpack.OPT_SORT_KEYS)
|
|
465
|
-
b'\x83\xa1a\x03\xa1b\x01\xa1c\x02'
|
|
466
|
-
```
|
|
467
|
-
|
|
468
|
-
The sorting is not collation/locale-aware:
|
|
469
|
-
|
|
470
|
-
```python
|
|
471
|
-
>>> import ormsgpack
|
|
472
|
-
>>> ormsgpack.packb({"a": 1, "ä": 2, "A": 3}, option=ormsgpack.OPT_SORT_KEYS)
|
|
473
|
-
b'\x83\xa1A\x03\xa1a\x01\xa2\xc3\xa4\x02'
|
|
474
|
-
```
|
|
475
|
-
|
|
476
|
-
`dataclass` also serialize as maps but this has no effect on them.
|
|
477
|
-
|
|
478
|
-
##### `OPT_UTC_Z`
|
|
479
|
-
|
|
480
|
-
Serialize a UTC timezone on `datetime.datetime` and `numpy.datetime64` instances
|
|
481
|
-
as `Z` instead of `+00:00`.
|
|
482
|
-
|
|
483
|
-
```python
|
|
484
|
-
>>> import ormsgpack, datetime
|
|
485
|
-
>>> ormsgpack.packb(
|
|
486
|
-
... datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc),
|
|
487
|
-
... )
|
|
488
|
-
b'\xb91970-01-01T00:00:00+00:00'
|
|
489
|
-
>>> ormsgpack.packb(
|
|
490
|
-
... datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc),
|
|
491
|
-
... option=ormsgpack.OPT_UTC_Z
|
|
492
|
-
... )
|
|
493
|
-
b'\xb41970-01-01T00:00:00Z'
|
|
494
|
-
```
|
|
495
|
-
|
|
496
|
-
### Deserialize
|
|
497
|
-
|
|
498
|
-
```python
|
|
499
|
-
def unpackb(
|
|
500
|
-
__obj: Union[bytes, bytearray, memoryview],
|
|
501
|
-
/,
|
|
502
|
-
ext_hook: Optional[Callable[[int, bytes], Any]] = ...,
|
|
503
|
-
option: Optional[int] = ...,
|
|
504
|
-
) -> Any: ...
|
|
505
|
-
```
|
|
506
|
-
|
|
507
|
-
`unpackb()` deserializes msgpack to Python objects. It deserializes to `dict`,
|
|
508
|
-
`list`, `int`, `float`, `str`, `bool`, `bytes` and `None` objects.
|
|
509
|
-
|
|
510
|
-
`bytes`, `bytearray`, `memoryview` input are accepted.
|
|
511
|
-
|
|
512
|
-
ormsgpack maintains a cache of map keys for the duration of the process. This
|
|
513
|
-
causes a net reduction in memory usage by avoiding duplicate strings. The
|
|
514
|
-
keys must be at most 64 bytes to be cached and 512 entries are stored.
|
|
515
|
-
|
|
516
|
-
The global interpreter lock (GIL) is held for the duration of the call.
|
|
517
|
-
|
|
518
|
-
It raises `MsgpackDecodeError` if given an invalid type or invalid
|
|
519
|
-
msgpack.
|
|
520
|
-
|
|
521
|
-
`MsgpackDecodeError` is a subclass of `ValueError`.
|
|
522
|
-
|
|
523
|
-
#### ext_hook
|
|
524
|
-
|
|
525
|
-
To deserialize extension types, specify the optional `ext_hook`
|
|
526
|
-
argument. The value should be a callable and is invoked with the
|
|
527
|
-
extension type and value as arguments.
|
|
528
|
-
|
|
529
|
-
```python
|
|
530
|
-
>>> import ormsgpack, decimal
|
|
531
|
-
>>> def ext_hook(tag, data):
|
|
532
|
-
... if tag == 0:
|
|
533
|
-
... return decimal.Decimal(data.decode())
|
|
534
|
-
... raise TypeError
|
|
535
|
-
...
|
|
536
|
-
>>> ormsgpack.packb(
|
|
537
|
-
... ormsgpack.Ext(0, str(decimal.Decimal("0.0842389659712649442845")).encode())
|
|
538
|
-
... )
|
|
539
|
-
b'\xc7\x18\x000.0842389659712649442845'
|
|
540
|
-
>>> ormsgpack.unpackb(_, ext_hook=ext_hook)
|
|
541
|
-
Decimal('0.0842389659712649442845'
|
|
542
|
-
```
|
|
543
|
-
|
|
544
|
-
#### option
|
|
545
|
-
|
|
546
|
-
##### `OPT_DATETIME_AS_TIMESTAMP_EXT`
|
|
547
|
-
|
|
548
|
-
Deserialize timestamp extension objects to UTC `datetime.datetime` instances.
|
|
549
|
-
|
|
550
|
-
##### `OPT_NON_STR_KEYS`
|
|
551
|
-
|
|
552
|
-
Deserialize map keys of type other than string.
|
|
553
|
-
Be aware that this option is considered unsafe and disabled by default in msgpack due to possibility of HashDoS.
|
|
554
|
-
|
|
555
|
-
## Types
|
|
556
|
-
|
|
557
|
-
### none
|
|
558
|
-
|
|
559
|
-
The `None` object is serialized as nil.
|
|
560
|
-
|
|
561
|
-
### bool
|
|
562
|
-
|
|
563
|
-
`bool` instances are serialized as booleans.
|
|
564
|
-
|
|
565
|
-
### int
|
|
566
|
-
|
|
567
|
-
Instances of `int` and of subclasses of `int` are serialized as
|
|
568
|
-
integers. The minimum and maximum representable values are
|
|
569
|
-
-9223372036854775807 and 18446744073709551615, respectively.
|
|
570
|
-
|
|
571
|
-
### float
|
|
572
|
-
|
|
573
|
-
`float` instances are serialized as IEEE 754 double precision floating point numbers.
|
|
574
|
-
|
|
575
|
-
### str
|
|
576
|
-
|
|
577
|
-
Instances of `str` and of subclasses of `str` are serialized as strings.
|
|
578
|
-
|
|
579
|
-
### bytes
|
|
580
|
-
|
|
581
|
-
`bytes`, `bytearray` and `memoryview` instances are serialized as binary objects.
|
|
582
|
-
|
|
583
|
-
### list
|
|
584
|
-
|
|
585
|
-
Instances of `list` and of subclasses of `list` are serialized as arrays.
|
|
586
|
-
|
|
587
|
-
### tuple
|
|
588
|
-
|
|
589
|
-
`tuple` instances are serialized as arrays.
|
|
590
|
-
|
|
591
|
-
### dict
|
|
592
|
-
|
|
593
|
-
Instances of `dict` and of subclasses of `dict` are serialized as maps.
|
|
594
|
-
|
|
595
|
-
### dataclass
|
|
596
|
-
|
|
597
|
-
Dataclasses are serialized as maps. The fields are serialized in the
|
|
598
|
-
order they are defined in the class. All variants of dataclasses are
|
|
599
|
-
supported, including dataclasses with `__slots__`, frozen dataclasses
|
|
600
|
-
and dataclasses with descriptor-typed fields.
|
|
601
|
-
|
|
602
|
-
```python
|
|
603
|
-
>>> import dataclasses, ormsgpack, typing
|
|
604
|
-
>>> @dataclasses.dataclass
|
|
605
|
-
... class Member:
|
|
606
|
-
... id: int
|
|
607
|
-
... active: bool = dataclasses.field(default=False)
|
|
608
|
-
...
|
|
609
|
-
>>> @dataclasses.dataclass
|
|
610
|
-
... class Object:
|
|
611
|
-
... id: int
|
|
612
|
-
... name: str
|
|
613
|
-
... members: typing.List[Member]
|
|
614
|
-
...
|
|
615
|
-
>>> ormsgpack.packb(Object(1, "a", [Member(1, True), Member(2)]))
|
|
616
|
-
b'\x83\xa2id\x01\xa4name\xa1a\xa7members\x92\x82\xa2id\x01\xa6active\xc3\x82\xa2id\x02\xa6active\xc2'
|
|
617
|
-
```
|
|
618
|
-
|
|
619
|
-
### date
|
|
620
|
-
|
|
621
|
-
`datetime.date` instances are serialized as [RFC 3339](https://tools.ietf.org/html/rfc3339) strings.
|
|
622
|
-
|
|
623
|
-
```python
|
|
624
|
-
>>> import ormsgpack, datetime
|
|
625
|
-
>>> ormsgpack.packb(datetime.date(1900, 1, 2))
|
|
626
|
-
b'\xaa1900-01-02'
|
|
627
|
-
>>> ormsgpack.unpackb(_)
|
|
628
|
-
'1900-01-02'
|
|
629
|
-
```
|
|
630
|
-
|
|
631
|
-
### time
|
|
632
|
-
|
|
633
|
-
Naive `datetime.time` instances are serialized as [RFC 3339](https://tools.ietf.org/html/rfc3339) strings.
|
|
634
|
-
Aware `datetime.time` instances are not supported.
|
|
635
|
-
|
|
636
|
-
```python
|
|
637
|
-
>>> import ormsgpack, datetime
|
|
638
|
-
>>> ormsgpack.packb(datetime.time(12, 0, 15, 290))
|
|
639
|
-
b'\xaf12:00:15.000290'
|
|
640
|
-
>>> ormsgpack.unpackb(_)
|
|
641
|
-
'12:00:15.000290'
|
|
642
|
-
```
|
|
643
|
-
|
|
644
|
-
### datetime
|
|
645
|
-
|
|
646
|
-
Naive `datetime.datetime` instances are serialized as [RFC 3339](https://tools.ietf.org/html/rfc3339) strings.
|
|
647
|
-
Aware `datetime.datetime` instances are serialized as [RFC 3339](https://tools.ietf.org/html/rfc3339) strings
|
|
648
|
-
or alternatively as MessagePack timestamp extension objects, by using the
|
|
649
|
-
[`OPT_DATETIME_AS_TIMESTAMP_EXT`](#OPT_DATETIME_AS_TIMESTAMP_EXT) option.
|
|
650
|
-
|
|
651
|
-
```python
|
|
652
|
-
>>> import ormsgpack, datetime, zoneinfo
|
|
653
|
-
>>> ormsgpack.packb(
|
|
654
|
-
... datetime.datetime(2018, 12, 1, 2, 3, 4, 9, tzinfo=zoneinfo.ZoneInfo('Australia/Adelaide'))
|
|
655
|
-
... )
|
|
656
|
-
b'\xd9 2018-12-01T02:03:04.000009+10:30'
|
|
657
|
-
>>> ormsgpack.unpackb(_)
|
|
658
|
-
'2018-12-01T02:03:04.000009+10:30'
|
|
659
|
-
>>> ormsgpack.packb(
|
|
660
|
-
... datetime.datetime.fromtimestamp(4123518902).replace(tzinfo=datetime.timezone.utc)
|
|
661
|
-
... )
|
|
662
|
-
b'\xb92100-09-02T00:55:02+00:00'
|
|
663
|
-
>>> ormsgpack.unpackb(_)
|
|
664
|
-
'2100-09-02T00:55:02+00:00'
|
|
665
|
-
>>> ormsgpack.packb(
|
|
666
|
-
... datetime.datetime.fromtimestamp(4123518902)
|
|
667
|
-
... )
|
|
668
|
-
b'\xb32100-09-02T00:55:02'
|
|
669
|
-
>>> ormsgpack.unpackb(_)
|
|
670
|
-
'2100-09-02T00:55:02'
|
|
671
|
-
```
|
|
672
|
-
|
|
673
|
-
Errors with `tzinfo` result in `MsgpackEncodeError` being raised.
|
|
674
|
-
|
|
675
|
-
The serialization can be customized using the
|
|
676
|
-
[`OPT_NAIVE_UTC`](#OPT_NAIVE_UTC),
|
|
677
|
-
[`OPT_OMIT_MICROSECONDS`](#OPT_OMIT_MICROSECONDS), and
|
|
678
|
-
[`OPT_UTC_Z`](#OPT_UTC_Z) options.
|
|
679
|
-
|
|
680
|
-
### enum
|
|
681
|
-
|
|
682
|
-
Enum members are serialized as their values. Options apply to their
|
|
683
|
-
values. All subclasses of `enum.EnumType` are supported.
|
|
684
|
-
|
|
685
|
-
```python
|
|
686
|
-
>>> import enum, datetime, ormsgpack
|
|
687
|
-
>>> class DatetimeEnum(enum.Enum):
|
|
688
|
-
... EPOCH = datetime.datetime(1970, 1, 1, 0, 0, 0)
|
|
689
|
-
...
|
|
690
|
-
>>> ormsgpack.packb(DatetimeEnum.EPOCH)
|
|
691
|
-
b'\xb31970-01-01T00:00:00'
|
|
692
|
-
>>> ormsgpack.unpackb(_)
|
|
693
|
-
'1970-01-01T00:00:00'
|
|
694
|
-
>>> ormsgpack.packb(DatetimeEnum.EPOCH, option=ormsgpack.OPT_NAIVE_UTC)
|
|
695
|
-
b'\xb91970-01-01T00:00:00+00:00'
|
|
696
|
-
>>> ormsgpack.unpackb(_)
|
|
697
|
-
'1970-01-01T00:00:00+00:00'
|
|
698
|
-
```
|
|
699
|
-
|
|
700
|
-
Enum members whose value is not a supported type can be serialized using
|
|
701
|
-
`default`:
|
|
702
|
-
|
|
703
|
-
```python
|
|
704
|
-
>>> import enum, ormsgpack
|
|
705
|
-
>>> class Custom:
|
|
706
|
-
... def __init__(self, val):
|
|
707
|
-
... self.val = val
|
|
708
|
-
...
|
|
709
|
-
>>> def default(obj):
|
|
710
|
-
... if isinstance(obj, Custom):
|
|
711
|
-
... return obj.val
|
|
712
|
-
... raise TypeError
|
|
713
|
-
...
|
|
714
|
-
>>> class CustomEnum(enum.Enum):
|
|
715
|
-
... ONE = Custom(1)
|
|
716
|
-
...
|
|
717
|
-
>>> ormsgpack.packb(CustomEnum.ONE, default=default)
|
|
718
|
-
b'\x01'
|
|
719
|
-
>>> ormsgpack.unpackb(_)
|
|
720
|
-
1
|
|
721
|
-
```
|
|
722
|
-
|
|
723
|
-
### uuid
|
|
724
|
-
|
|
725
|
-
`uuid.UUID` instances are serialized as [RFC 4122](https://tools.ietf.org/html/rfc4122) strings.
|
|
726
|
-
|
|
727
|
-
```python
|
|
728
|
-
>>> import ormsgpack, uuid
|
|
729
|
-
>>> ormsgpack.packb(uuid.UUID('f81d4fae-7dec-11d0-a765-00a0c91e6bf6'))
|
|
730
|
-
b'\xd9$f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
|
|
731
|
-
>>> ormsgpack.unpackb(_)
|
|
732
|
-
'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
|
|
733
|
-
>>> ormsgpack.packb(uuid.uuid5(uuid.NAMESPACE_DNS, "python.org"))
|
|
734
|
-
b'\xd9$886313e1-3b8a-5372-9b90-0c9aee199e5d'
|
|
735
|
-
>>> ormsgpack.unpackb(_)
|
|
736
|
-
'886313e1-3b8a-5372-9b90-0c9aee199e5d
|
|
737
|
-
```
|
|
738
|
-
|
|
739
|
-
### numpy
|
|
740
|
-
|
|
741
|
-
`numpy.bool`, `numpy.float16`, `numpy.float32`, `numpy.float64`,
|
|
742
|
-
`numpy.int8`, `numpy.int16`, `numpy.int32`, `numpy.int64`, `numpy.intp`,
|
|
743
|
-
`numpy.uint8`, `numpy.uint16`, `numpy.uint32`, `numpy.uint64`, `numpy.uintp`
|
|
744
|
-
instances are serialized as the corresponding builtin types.
|
|
745
|
-
|
|
746
|
-
`numpy.datetime64` instances are serialized as [RFC 3339](https://tools.ietf.org/html/rfc3339) strings.
|
|
747
|
-
The serialization can be customized using the
|
|
748
|
-
[`OPT_NAIVE_UTC`](#OPT_NAIVE_UTC),
|
|
749
|
-
[`OPT_OMIT_MICROSECONDS`](#OPT_OMIT_MICROSECONDS), and
|
|
750
|
-
[`OPT_UTC_Z`](#OPT_UTC_Z) options.
|
|
751
|
-
|
|
752
|
-
`numpy.ndarray` instances are serialized as arrays. The array must be
|
|
753
|
-
a C-contiguous array (`C_CONTIGUOUS`) and of a supported data type.
|
|
754
|
-
Unsupported arrays can be serialized using [default](#default), by
|
|
755
|
-
converting the array to a list with the `numpy.ndarray.tolist` method.
|
|
756
|
-
|
|
757
|
-
The serialization of numpy types is disabled by default and can be
|
|
758
|
-
enabled by using the [`OPT_SERIALIZE_NUMPY`](#OPT_SERIALIZE_NUMPY) option.
|
|
759
|
-
|
|
760
|
-
```python
|
|
761
|
-
>>> import ormsgpack, numpy
|
|
762
|
-
>>> ormsgpack.packb(
|
|
763
|
-
... numpy.array([[1, 2, 3], [4, 5, 6]]),
|
|
764
|
-
... option=ormsgpack.OPT_SERIALIZE_NUMPY,
|
|
765
|
-
... )
|
|
766
|
-
b'\x92\x93\x01\x02\x03\x93\x04\x05\x06'
|
|
767
|
-
>>> ormsgpack.unpackb(_)
|
|
768
|
-
[[1, 2, 3], [4, 5, 6]]
|
|
769
|
-
```
|
|
770
|
-
|
|
771
|
-
### Pydantic
|
|
772
|
-
|
|
773
|
-
`pydantic.BaseModel` instances are serialized as maps, with
|
|
774
|
-
[duck-typing](https://docs.pydantic.dev/2.10/concepts/serialization/#serializing-with-duck-typing).
|
|
775
|
-
This is equivalent to serializing
|
|
776
|
-
`model.model_dump(serialize_as_any=True)` with Pydantic V2 or
|
|
777
|
-
`model.dict()`with Pydantic V1.
|
|
778
|
-
|
|
779
|
-
The serialization of pydantic models is disabled by default and can be
|
|
780
|
-
enabled by using the [`OPT_SERIALIZE_PYDANTIC`](#OPT_SERIALIZE_PYDANTIC) option.
|
|
781
|
-
|
|
782
|
-
## Latency
|
|
783
|
-
|
|
784
|
-
### Graphs
|
|
785
|
-
|
|
786
|
-

|
|
787
|
-

|
|
788
|
-

|
|
789
|
-

|
|
790
|
-

|
|
791
|
-

|
|
792
|
-

|
|
793
|
-

|
|
794
|
-

|
|
795
|
-

|
|
796
|
-

|
|
797
|
-

|
|
798
|
-

|
|
799
|
-

|
|
800
|
-

|
|
801
|
-
|
|
802
|
-
### Data
|
|
803
|
-
|
|
804
|
-
```
|
|
805
|
-
----------------------------------------------------------------------------- benchmark 'canada packb': 2 tests ------------------------------------------------------------------------------
|
|
806
|
-
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
|
|
807
|
-
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
808
|
-
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
|
|
809
|
-
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
|
|
810
|
-
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
------------------------------------------------------------------------------- benchmark 'canada unpackb': 2 tests --------------------------------------------------------------------------------
|
|
814
|
-
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
|
|
815
|
-
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
816
|
-
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
|
|
817
|
-
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
|
|
818
|
-
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
----------------------------------------------------------------------------- benchmark 'citm_catalog packb': 2 tests -----------------------------------------------------------------------------
|
|
822
|
-
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
|
|
823
|
-
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
824
|
-
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
|
|
825
|
-
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
|
|
826
|
-
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
------------------------------------------------------------------------------ benchmark 'citm_catalog unpackb': 2 tests ------------------------------------------------------------------------------
|
|
830
|
-
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
|
|
831
|
-
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
832
|
-
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
|
|
833
|
-
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
|
|
834
|
-
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
----------------------------------------------------------------------------------- benchmark 'github packb': 2 tests -----------------------------------------------------------------------------------
|
|
838
|
-
Name (time in us) Min Max Mean StdDev Median IQR Outliers OPS (Kops/s) Rounds Iterations
|
|
839
|
-
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
840
|
-
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
|
|
841
|
-
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
|
|
842
|
-
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
----------------------------------------------------------------------------------- benchmark 'github unpackb': 2 tests -----------------------------------------------------------------------------------
|
|
846
|
-
Name (time in us) Min Max Mean StdDev Median IQR Outliers OPS (Kops/s) Rounds Iterations
|
|
847
|
-
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
848
|
-
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
|
|
849
|
-
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
|
|
850
|
-
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
851
|
-
|
|
852
|
-
--------------------------------------------------------------------------------------- benchmark 'twitter packb': 2 tests ---------------------------------------------------------------------------------------
|
|
853
|
-
Name (time in us) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
|
|
854
|
-
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
855
|
-
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
|
|
856
|
-
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
|
|
857
|
-
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
------------------------------------------------------------------------------ benchmark 'twitter unpackb': 2 tests -----------------------------------------------------------------------------
|
|
861
|
-
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
|
|
862
|
-
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
863
|
-
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
|
|
864
|
-
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
|
|
865
|
-
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
--------------------------------------------------------------------------------- benchmark 'dataclass': 2 tests --------------------------------------------------------------------------------
|
|
869
|
-
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
|
|
870
|
-
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
871
|
-
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
|
|
872
|
-
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
|
|
873
|
-
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
---------------------------------------------------------------------------------- benchmark 'numpy float64': 2 tests ---------------------------------------------------------------------------------
|
|
877
|
-
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
|
|
878
|
-
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
879
|
-
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
|
|
880
|
-
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
|
|
881
|
-
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
------------------------------------------------------------------------------------- benchmark 'numpy int32': 2 tests -------------------------------------------------------------------------------------
|
|
885
|
-
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
|
|
886
|
-
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
887
|
-
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
|
|
888
|
-
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
|
|
889
|
-
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
-------------------------------------------------------------------------------- benchmark 'numpy int8': 2 tests ---------------------------------------------------------------------------------
|
|
893
|
-
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
|
|
894
|
-
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
895
|
-
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
|
|
896
|
-
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
|
|
897
|
-
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
------------------------------------------------------------------------------------- benchmark 'numpy npbool': 2 tests --------------------------------------------------------------------------------------
|
|
901
|
-
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
|
|
902
|
-
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
903
|
-
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
|
|
904
|
-
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
|
|
905
|
-
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
--------------------------------------------------------------------------------- benchmark 'numpy uint8': 2 tests ---------------------------------------------------------------------------------
|
|
909
|
-
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
|
|
910
|
-
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
911
|
-
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
|
|
912
|
-
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
|
|
913
|
-
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
-------------------------------------------------------------------------------- benchmark 'pydantic': 2 tests ---------------------------------------------------------------------------------
|
|
917
|
-
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
|
|
918
|
-
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
919
|
-
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
|
|
920
|
-
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
|
|
921
|
-
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
922
|
-
```
|
|
923
|
-
|
|
924
|
-
### Reproducing
|
|
925
|
-
|
|
926
|
-
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.
|
|
927
|
-
|
|
928
|
-
The latency results can be reproduced using `uv run pytest benchmarks/bench_*`.
|
|
929
|
-
|
|
930
|
-
## Questions
|
|
931
|
-
|
|
932
|
-
### Why can't I install it from PyPI?
|
|
933
|
-
|
|
934
|
-
Probably `pip` needs to be upgraded to version 20.3 or later to support
|
|
935
|
-
the latest manylinux_x_y or universal2 wheel formats.
|
|
936
|
-
|
|
937
|
-
### Will it deserialize to dataclasses, UUIDs, decimals, etc or support object_hook?
|
|
938
|
-
|
|
939
|
-
No. This requires a schema specifying what types are expected and how to
|
|
940
|
-
handle errors etc. This is addressed by data validation libraries a
|
|
941
|
-
level above this.
|
|
942
|
-
|
|
943
|
-
## Packaging
|
|
944
|
-
|
|
945
|
-
To package ormsgpack requires [Rust](https://www.rust-lang.org/) 1.81
|
|
946
|
-
or newer and the [maturin](https://github.com/PyO3/maturin) build
|
|
947
|
-
tool. The recommended build command is:
|
|
948
|
-
|
|
949
|
-
```sh
|
|
950
|
-
maturin build --release
|
|
951
|
-
```
|
|
952
|
-
|
|
953
|
-
ormsgpack is tested on Linux/amd64, Linux/aarch64, Linux/armv7, macOS/aarch64 and Windows/amd64.
|
|
954
|
-
|
|
955
|
-
There are no runtime dependencies other than libc.
|
|
956
|
-
|
|
957
|
-
## License
|
|
958
|
-
|
|
959
|
-
orjson was written by ijl <<ijl@mailbox.org>>, copyright 2018 - 2021, licensed
|
|
960
|
-
under both the Apache 2 and MIT licenses.
|
|
961
|
-
|
|
962
|
-
ormsgpack was forked from orjson by Aviram Hassan and is now maintained by Emanuele Giaquinta (@exg), licensed
|
|
963
|
-
same as orjson.
|
|
964
|
-
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|