ormsgpack 1.9.1__cp310-cp310-musllinux_1_2_armv7l.whl → 1.10.0__cp310-cp310-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/__init__.py CHANGED
@@ -1,6 +1,7 @@
1
1
  # SPDX-License-Identifier: (Apache-2.0 OR MIT)
2
2
 
3
3
  from .ormsgpack import (
4
+ OPT_DATETIME_AS_TIMESTAMP_EXT,
4
5
  OPT_NAIVE_UTC,
5
6
  OPT_NON_STR_KEYS,
6
7
  OPT_OMIT_MICROSECONDS,
@@ -30,6 +31,7 @@ __all__ = (
30
31
  "Ext",
31
32
  "MsgpackDecodeError",
32
33
  "MsgpackEncodeError",
34
+ "OPT_DATETIME_AS_TIMESTAMP_EXT",
33
35
  "OPT_NAIVE_UTC",
34
36
  "OPT_NON_STR_KEYS",
35
37
  "OPT_OMIT_MICROSECONDS",
ormsgpack/__init__.pyi CHANGED
@@ -4,11 +4,14 @@ __version__: str
4
4
 
5
5
  def packb(
6
6
  obj: Any,
7
+ /,
7
8
  default: Optional[Callable[[Any], Any]] = ...,
8
9
  option: Optional[int] = None,
9
10
  ) -> bytes: ...
10
11
  def unpackb(
11
12
  obj: Union[bytes, bytearray, memoryview],
13
+ /,
14
+ *,
12
15
  ext_hook: Optional[Callable[[int, bytes], Any]] = ...,
13
16
  option: Optional[int] = ...,
14
17
  ) -> Any: ...
@@ -19,6 +22,7 @@ class MsgpackEncodeError(TypeError): ...
19
22
  class Ext:
20
23
  def __init__(self, tag: int, data: bytes) -> None: ...
21
24
 
25
+ OPT_DATETIME_AS_TIMESTAMP_EXT: int
22
26
  OPT_NAIVE_UTC: int
23
27
  OPT_OMIT_MICROSECONDS: int
24
28
  OPT_PASSTHROUGH_BIG_INT: int
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ormsgpack
3
- Version: 1.9.1
3
+ Version: 1.10.0
4
4
  Classifier: Development Status :: 5 - Production/Stable
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: License :: OSI Approved :: Apache Software License
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
16
  Classifier: Programming Language :: Python :: 3.13
17
17
  Classifier: Programming Language :: Python :: Implementation :: CPython
18
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
18
19
  Classifier: Programming Language :: Python
19
20
  Classifier: Programming Language :: Rust
20
21
  Classifier: Typing :: Typed
@@ -31,6 +32,7 @@ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
31
32
  Project-URL: Source Code, https://github.com/aviramha/ormsgpack
32
33
 
33
34
  # ormsgpack
35
+
34
36
  ![PyPI](https://img.shields.io/pypi/v/ormsgpack)
35
37
  ![PyPI - Downloads](https://img.shields.io/pypi/dm/ormsgpack)
36
38
 
@@ -38,9 +40,14 @@ ormsgpack is a fast msgpack serialization library for Python derived
38
40
  from [orjson](https://github.com/ijl/orjson), with native support for
39
41
  various Python types.
40
42
 
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.
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.
44
51
 
45
52
  ormsgpack is licensed under both the Apache 2.0 and MIT licenses. The
46
53
  repository and issue tracker is
@@ -52,19 +59,28 @@ available in the repository.
52
59
  1. [Usage](#usage)
53
60
  1. [Install](#install)
54
61
  2. [Quickstart](#quickstart)
55
- 4. [Serialize](#serialize)
62
+ 3. [Serialize](#serialize)
56
63
  1. [default](#default)
57
64
  2. [option](#option)
58
- 5. [Deserialize](#deserialize)
65
+ 4. [Deserialize](#deserialize)
59
66
  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)
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)
68
84
  3. [Latency](#latency)
69
85
  4. [Questions](#questions)
70
86
  5. [Packaging](#packaging)
@@ -112,29 +128,20 @@ def packb(
112
128
  ```
113
129
 
114
130
  `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
-
131
+ It natively serializes various Python [types](#Types) and supports
132
+ arbitrary types through the [default](#default) argument.
125
133
  The output is a `bytes` object.
126
134
 
127
135
  The global interpreter lock (GIL) is held for the duration of the call.
128
136
 
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).
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: ...`.
133
140
 
134
- It raises `MsgpackEncodeError` on a `str` that contains invalid UTF-8.
141
+ It raises `MsgpackEncodeError` if a `str` contains invalid UTF-8.
135
142
 
136
143
  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.
144
+ unless [`OPT_NON_STR_KEYS`](#OPT_NON_STR_KEYS) is specified.
138
145
 
139
146
  It raises `MsgpackEncodeError` if the output of `default` recurses to handling by
140
147
  `default` more than 254 levels deep.
@@ -213,11 +220,15 @@ To modify how data is serialized, specify `option`. Each `option` is an integer
213
220
  constant in `ormsgpack`. To specify multiple options, mask them together, e.g.,
214
221
  `option=ormsgpack.OPT_NON_STR_KEYS | ormsgpack.OPT_NAIVE_UTC`.
215
222
 
223
+ ##### `OPT_DATETIME_AS_TIMESTAMP_EXT`
224
+
225
+ Serialize aware `datetime.datetime` instances as timestamp extension objects.
226
+
216
227
  ##### `OPT_NAIVE_UTC`
217
228
 
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.
229
+ Serialize naive `datetime.datetime` objects and `numpy.datetime64`
230
+ objects as UTC. This has no effect on aware `datetime.datetime`
231
+ objects.
221
232
 
222
233
  ```python
223
234
  >>> import ormsgpack, datetime
@@ -241,6 +252,7 @@ b'\xb91970-01-01T00:00:00+00:00'
241
252
  Serialize `dict` keys of type other than `str`. This allows `dict` keys
242
253
  to be one of `str`, `int`, `float`, `bool`, `None`, `datetime.datetime`,
243
254
  `datetime.date`, `datetime.time`, `enum.Enum`, and `uuid.UUID`.
255
+ All options other than the passthrough ones are supported.
244
256
  `dict` keys of unsupported types are not handled using `default` and
245
257
  result in `MsgpackEncodeError` being raised.
246
258
 
@@ -262,15 +274,21 @@ b'\x81\xb91970-01-01T00:00:00+00:00\x93\x01\x02\x03'
262
274
  {'1970-01-01T00:00:00+00:00': [1, 2, 3]}
263
275
  ```
264
276
 
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.
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,
268
281
 
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.
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
+ ```
274
292
 
275
293
  This option is not compatible with `ormsgpack.OPT_SORT_KEYS`.
276
294
 
@@ -319,8 +337,7 @@ b'\x82\xa4type\xa6bigint\xa5value\xb436893488147419103232'
319
337
 
320
338
  ##### `OPT_PASSTHROUGH_DATACLASS`
321
339
 
322
- Enable passthrough of `dataclasses.dataclass` instances to `default`.
323
-
340
+ Enable passthrough of dataclasses to `default`.
324
341
 
325
342
  ```python
326
343
  >>> import ormsgpack, dataclasses
@@ -373,7 +390,7 @@ b'\x81\xaacreated_at\xbdThu, 01 Jan 1970 00:00:00 GMT'
373
390
 
374
391
  ##### `OPT_PASSTHROUGH_ENUM`
375
392
 
376
- Enable passthrough of `enum.Enum` instances to `default`.
393
+ Enable passthrough of enum members to `default`.
377
394
 
378
395
  ##### `OPT_PASSTHROUGH_SUBCLASS`
379
396
 
@@ -426,10 +443,10 @@ Enable passthrough of `uuid.UUID` instances to `default`.
426
443
 
427
444
  ##### `OPT_SERIALIZE_NUMPY`
428
445
 
429
- Serialize `numpy.ndarray` instances. For more, see
430
- [numpy](#numpy).
446
+ Serialize instances of numpy types.
431
447
 
432
448
  ##### `OPT_SERIALIZE_PYDANTIC`
449
+
433
450
  Serialize `pydantic.BaseModel` instances.
434
451
 
435
452
  ##### `OPT_SORT_KEYS`
@@ -477,6 +494,7 @@ b'\xb41970-01-01T00:00:00Z'
477
494
  ```
478
495
 
479
496
  ### Deserialize
497
+
480
498
  ```python
481
499
  def unpackb(
482
500
  __obj: Union[bytes, bytearray, memoryview],
@@ -524,24 +542,62 @@ Decimal('0.0842389659712649442845'
524
542
  ```
525
543
 
526
544
  #### option
527
- `unpackb()` supports the `OPT_NON_STR_KEYS` option, that is similar to original msgpack's `strict_map_key=False`.
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.
528
553
  Be aware that this option is considered unsafe and disabled by default in msgpack due to possibility of HashDoS.
529
554
 
530
555
  ## Types
531
556
 
532
- ### dataclass
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
533
572
 
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`.
573
+ `float` instances are serialized as IEEE 754 double precision floating point numbers.
537
574
 
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__`.
575
+ ### str
542
576
 
543
- Dataclasses are serialized as maps, with every attribute serialized and in
544
- the order given on class definition:
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.
545
601
 
546
602
  ```python
547
603
  >>> import dataclasses, ormsgpack, typing
@@ -559,24 +615,38 @@ the order given on class definition:
559
615
  >>> ormsgpack.packb(Object(1, "a", [Member(1, True), Member(2)]))
560
616
  b'\x83\xa2id\x01\xa4name\xa1a\xa7members\x92\x82\xa2id\x01\xa6active\xc3\x82\xa2id\x02\xa6active\xc2'
561
617
  ```
562
- #### Performance
563
- ![alt text](doc/dataclass.svg "dataclass")
564
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'
565
629
  ```
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
- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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'
572
642
  ```
573
643
 
574
644
  ### datetime
575
645
 
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.
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.
580
650
 
581
651
  ```python
582
652
  >>> import ormsgpack, datetime, zoneinfo
@@ -600,41 +670,17 @@ b'\xb32100-09-02T00:55:02'
600
670
  '2100-09-02T00:55:02'
601
671
  ```
602
672
 
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
673
  Errors with `tzinfo` result in `MsgpackEncodeError` being raised.
629
674
 
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`.
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.
634
679
 
635
680
  ### enum
636
681
 
637
- ormsgpack serializes enums natively. Options apply to their values.
682
+ Enum members are serialized as their values. Options apply to their
683
+ values. All subclasses of `enum.EnumType` are supported.
638
684
 
639
685
  ```python
640
686
  >>> import enum, datetime, ormsgpack
@@ -651,7 +697,7 @@ b'\xb91970-01-01T00:00:00+00:00'
651
697
  '1970-01-01T00:00:00+00:00'
652
698
  ```
653
699
 
654
- Enums with members that are not supported types can be serialized using
700
+ Enum members whose value is not a supported type can be serialized using
655
701
  `default`:
656
702
 
657
703
  ```python
@@ -674,31 +720,42 @@ b'\x01'
674
720
  1
675
721
  ```
676
722
 
677
- ### float
678
-
679
- ormsgpack serializes and deserializes double precision floats with no loss of
680
- precision and consistent rounding.
723
+ ### uuid
681
724
 
682
- ### int
725
+ `uuid.UUID` instances are serialized as [RFC 4122](https://tools.ietf.org/html/rfc4122) strings.
683
726
 
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).
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
+ ```
687
738
 
688
739
  ### numpy
689
740
 
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.
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.
696
745
 
697
- `numpy.datetime64` instances are serialized as RFC 3339 strings.
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.
698
751
 
699
- ormsgpack is faster than all compared libraries at serializing
700
- numpy instances. Serializing numpy data requires specifying
701
- `option=ormsgpack.OPT_SERIALIZE_NUMPY`.
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.
702
759
 
703
760
  ```python
704
761
  >>> import ormsgpack, numpy
@@ -711,100 +768,21 @@ b'\x92\x93\x01\x02\x03\x93\x04\x05\x06'
711
768
  [[1, 2, 3], [4, 5, 6]]
712
769
  ```
713
770
 
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
771
  ### Pydantic
788
- ormsgpack serializes `pydantic.BaseModel` instances natively, with
772
+
773
+ `pydantic.BaseModel` instances are serialized as maps, with
789
774
  [duck-typing](https://docs.pydantic.dev/2.10/concepts/serialization/#serializing-with-duck-typing).
790
775
  This is equivalent to serializing
791
776
  `model.model_dump(serialize_as_any=True)` with Pydantic V2 or
792
777
  `model.dict()`with Pydantic V1.
793
778
 
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
- ```
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.
805
781
 
806
782
  ## Latency
783
+
807
784
  ### Graphs
785
+
808
786
  ![alt text](doc/twitter_packb.svg "twitter.json serialization")
809
787
  ![alt text](doc/twitter_unpackb.svg "twitter.json deserialization")
810
788
  ![alt text](doc/github_packb.svg "github.json serialization")
@@ -813,7 +791,16 @@ test_pydantic_msgpack 124.5500 (28.36) 125.5427 (9.92) 125.0582 (25
813
791
  ![alt text](doc/citm_catalog_unpackb.svg "citm_catalog.json deserialization")
814
792
  ![alt text](doc/canada_packb.svg "canada.json serialization")
815
793
  ![alt text](doc/canada_unpackb.svg "canada.json deserialization")
794
+ ![alt text](doc/dataclass.svg "dataclass")
795
+ ![alt text](doc/numpy_float64.svg "numpy")
796
+ ![alt text](doc/numpy_int32.svg "numpy int32")
797
+ ![alt text](doc/numpy_int8.svg "numpy int8")
798
+ ![alt text](doc/numpy_npbool.svg "numpy npbool")
799
+ ![alt text](doc/numpy_uint8.svg "numpy uint8")
800
+ ![alt text](doc/pydantic.svg "pydantic")
801
+
816
802
  ### Data
803
+
817
804
  ```
818
805
  ----------------------------------------------------------------------------- benchmark 'canada packb': 2 tests ------------------------------------------------------------------------------
819
806
  Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
@@ -876,13 +863,70 @@ Name (time in ms) Min Max Mean
876
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
877
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
878
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
+ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
879
922
  ```
923
+
880
924
  ### Reproducing
881
925
 
882
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.
883
927
 
884
- The latency results can be reproduced using `./scripts/benchmark.sh` and graphs using
885
- `pytest --benchmark-histogram benchmarks/bench_*`.
928
+ The latency results can be reproduced using `uv run pytest benchmarks/bench_*`.
929
+
886
930
  ## Questions
887
931
 
888
932
  ### Why can't I install it from PyPI?
@@ -900,15 +944,13 @@ level above this.
900
944
 
901
945
  To package ormsgpack requires [Rust](https://www.rust-lang.org/) 1.81
902
946
  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:
947
+ tool. The recommended build command is:
906
948
 
907
949
  ```sh
908
- maturin build --release --strip
950
+ maturin build --release
909
951
  ```
910
952
 
911
- ormsgpack is tested on Linux/amd64, Linux/aarch64, Linux/armv7, macOS/amd64 and Windows/amd64.
953
+ ormsgpack is tested on Linux/amd64, Linux/aarch64, Linux/armv7, macOS/aarch64 and Windows/amd64.
912
954
 
913
955
  There are no runtime dependencies other than libc.
914
956
 
@@ -0,0 +1,13 @@
1
+ ormsgpack-1.10.0.dist-info/METADATA,sha256=9x2lIjFUAWAeptZrApdhf0WigK_Cd8AQrJHRH9iH8Xk,43743
2
+ ormsgpack-1.10.0.dist-info/WHEEL,sha256=j0CzeBTXvFA5zxItlWefBqXQ57yFW2cj-DPgtzd1Ask,107
3
+ ormsgpack-1.10.0.dist-info/entry_points.txt,sha256=b4bGmxqo1PPqO42Cjz2A2X4Gy4h1PCoOygCzeS-m22I,63
4
+ ormsgpack-1.10.0.dist-info/licenses/LICENSE-APACHE,sha256=pg7qgXUUUxZo1-AHZXMUSf4U0FnTJJ4LyTs23kX3WfI,10847
5
+ ormsgpack-1.10.0.dist-info/licenses/LICENSE-MIT,sha256=I_GOA9xJ35FiL-KnYXZJdATkbO2KcV2dK2enRGVxzKM,1023
6
+ ormsgpack.libs/libgcc_s-5b5488a6.so.1,sha256=HGKUsVmTeNAxEdSy7Ua5Vh_I9FN3RCbPWzvZ7H_TrwE,2749061
7
+ ormsgpack/__init__.py,sha256=A4pm8xaw6_tIqmMoKn2jAGnqYakE96LWk2boEaB783U,1106
8
+ ormsgpack/__init__.pyi,sha256=8j0Ff1n1lcidp8MqWl7iLtujHbuCKxYNcEFM0eEJR2k,926
9
+ ormsgpack/_pyinstaller/__init__.py,sha256=hcOudyiUz-ny0OE09dNskv7gVZXrsbb5uwg2mScSbG8,133
10
+ ormsgpack/_pyinstaller/hook-ormsgpack.py,sha256=R-YMI5TWEh7mZLFywYSJu2PxG5HeuWrGlSmMbofSyGI,111
11
+ ormsgpack/ormsgpack.cpython-310-arm-linux-gnueabihf.so,sha256=T5_X_SNicuhw8DN3w2UIQTLGGuJrxY6RddG3gwLOI5E,391257
12
+ ormsgpack/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ ormsgpack-1.10.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: maturin (1.8.3)
2
+ Generator: maturin (1.8.6)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp310-cp310-musllinux_1_2_armv7l
@@ -1,13 +0,0 @@
1
- ormsgpack-1.9.1.dist-info/METADATA,sha256=N3FqJyfKD6Yuf0MXMGUYFr0yYjKJZ6nOFjVfQ9uGROs,43472
2
- ormsgpack-1.9.1.dist-info/WHEEL,sha256=_OfFnMP11eNMYzu-gPAmNrX5yeEPbDV28xs7JLWUNT0,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-5b5488a6.so.1,sha256=HGKUsVmTeNAxEdSy7Ua5Vh_I9FN3RCbPWzvZ7H_TrwE,2749061
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-310-arm-linux-gnueabihf.so,sha256=oFFjc4ahL4dCzPjDuD5mryyCIJxJ4a1sAK3X-jLZKdY,395353
13
- ormsgpack-1.9.1.dist-info/RECORD,,