@@ -10,53 +10,6 @@ It lets you exchange data among multiple languages like JSON.
10
10
But it's faster and smaller.
11
11
This package provides CPython bindings for reading and writing MessagePack data.
12
12
13
-
14
- ## Very important notes for existing users
15
-
16
- ### PyPI package name
17
-
18
- Package name on PyPI was changed from ` msgpack-python ` to ` msgpack ` from 0.5.
19
-
20
- When upgrading from msgpack-0.4 or earlier, do ` pip uninstall msgpack-python ` before
21
- ` pip install -U msgpack ` .
22
-
23
-
24
- ### Compatibility with the old format
25
-
26
- You can use ` use_bin_type=False ` option to pack ` bytes `
27
- object into raw type in the old msgpack spec, instead of bin type in new msgpack spec.
28
-
29
- You can unpack old msgpack format using ` raw=True ` option.
30
- It unpacks str (raw) type in msgpack into Python bytes.
31
-
32
- See note below for detail.
33
-
34
-
35
- ### Major breaking changes in msgpack 1.0
36
-
37
- * Python 2
38
-
39
- * The extension module does not support Python 2 anymore.
40
- The pure Python implementation (` msgpack.fallback ` ) is used for Python 2.
41
-
42
- * Packer
43
-
44
- * ` use_bin_type=True ` by default. bytes are encoded in bin type in msgpack.
45
- ** If you are still using Python 2, you must use unicode for all string types.**
46
- You can use ` use_bin_type=False ` to encode into old msgpack format.
47
- * ` encoding ` option is removed. UTF-8 is used always.
48
-
49
- * Unpacker
50
-
51
- * ` raw=False ` by default. It assumes str types are valid UTF-8 string
52
- and decode them to Python str (unicode) object.
53
- * ` encoding ` option is removed. You can use ` raw=True ` to support old format.
54
- * Default value of ` max_buffer_size ` is changed from 0 to 100 MiB.
55
- * Default value of ` strict_map_key ` is changed to True to avoid hashdos.
56
- You need to pass ` strict_map_key=False ` if you have data which contain map keys
57
- which type is not bytes or str.
58
-
59
-
60
13
## Install
61
14
62
15
```
@@ -65,12 +18,9 @@ $ pip install msgpack
65
18
66
19
### Pure Python implementation
67
20
68
- The extension module in msgpack (` msgpack._cmsgpack ` ) does not support
69
- Python 2 and PyPy.
70
-
71
- But msgpack provides a pure Python implementation (` msgpack.fallback ` )
72
- for PyPy and Python 2.
21
+ The extension module in msgpack (` msgpack._cmsgpack ` ) does not support PyPy.
73
22
23
+ But msgpack provides a pure Python implementation (` msgpack.fallback ` ) for PyPy.
74
24
75
25
76
26
### Windows
@@ -82,10 +32,6 @@ Without extension, using pure Python implementation on CPython runs slowly.
82
32
83
33
## How to use
84
34
85
- NOTE: In examples below, I use ` raw=False ` and ` use_bin_type=True ` for users
86
- using msgpack < 1.0. These options are default from msgpack 1.0 so you can omit them.
87
-
88
-
89
35
### One-shot pack & unpack
90
36
91
37
Use ` packb ` for packing and ` unpackb ` for unpacking.
@@ -97,16 +43,16 @@ msgpack provides `dumps` and `loads` as an alias for compatibility with
97
43
98
44
``` pycon
99
45
>>> import msgpack
100
- >>> msgpack.packb([1 , 2 , 3 ], use_bin_type = True )
46
+ >>> msgpack.packb([1 , 2 , 3 ])
101
47
'\x93\x01\x02\x03'
102
- >>> msgpack.unpackb(_, raw = False )
48
+ >>> msgpack.unpackb(_)
103
49
[1, 2, 3]
104
50
```
105
51
106
52
` unpack ` unpacks msgpack's array to Python's list, but can also unpack to tuple:
107
53
108
54
``` pycon
109
- >>> msgpack.unpackb(b ' \x93\x01\x02\x03 ' , use_list = False , raw = False )
55
+ >>> msgpack.unpackb(b ' \x93\x01\x02\x03 ' , use_list = False )
110
56
(1, 2, 3)
111
57
```
112
58
@@ -127,11 +73,11 @@ from io import BytesIO
127
73
128
74
buf = BytesIO()
129
75
for i in range (100 ):
130
- buf.write(msgpack.packb(i, use_bin_type = True ))
76
+ buf.write(msgpack.packb(i))
131
77
132
78
buf.seek(0 )
133
79
134
- unpacker = msgpack.Unpacker(buf, raw = False )
80
+ unpacker = msgpack.Unpacker(buf)
135
81
for unpacked in unpacker:
136
82
print (unpacked)
137
83
```
@@ -162,8 +108,8 @@ def encode_datetime(obj):
162
108
return obj
163
109
164
110
165
- packed_dict = msgpack.packb(useful_dict, default = encode_datetime, use_bin_type = True )
166
- this_dict_again = msgpack.unpackb(packed_dict, object_hook = decode_datetime, raw = False )
111
+ packed_dict = msgpack.packb(useful_dict, default = encode_datetime)
112
+ this_dict_again = msgpack.unpackb(packed_dict, object_hook = decode_datetime)
167
113
```
168
114
169
115
` Unpacker ` 's ` object_hook ` callback receives a dict; the
@@ -191,8 +137,8 @@ It is also possible to pack/unpack custom data types using the **ext** type.
191
137
... return ExtType(code, data)
192
138
...
193
139
>>> data = array.array(' d' , [1.2 , 3.4 ])
194
- >>> packed = msgpack.packb(data, default = default, use_bin_type = True )
195
- >>> unpacked = msgpack.unpackb(packed, ext_hook = ext_hook, raw = False )
140
+ >>> packed = msgpack.packb(data, default = default)
141
+ >>> unpacked = msgpack.unpackb(packed, ext_hook = ext_hook)
196
142
>>> data == unpacked
197
143
True
198
144
```
@@ -210,7 +156,7 @@ in a map, can be unpacked or skipped individually.
210
156
211
157
## Notes
212
158
213
- ### string and binary type
159
+ ### string and binary type in old msgpack spec
214
160
215
161
Early versions of msgpack didn't distinguish string and binary types.
216
162
The type for representing both string and binary types was named ** raw** .
@@ -263,3 +209,41 @@ You can use `gc.disable()` when unpacking large message.
263
209
List is the default sequence type of Python.
264
210
But tuple is lighter than list.
265
211
You can use ` use_list=False ` while unpacking when performance is important.
212
+
213
+
214
+ ## Major breaking changes in the history
215
+
216
+ ### msgpack 0.5
217
+
218
+ Package name on PyPI was changed from ` msgpack-python ` to ` msgpack ` from 0.5.
219
+
220
+ When upgrading from msgpack-0.4 or earlier, do ` pip uninstall msgpack-python ` before
221
+ ` pip install -U msgpack ` .
222
+
223
+
224
+ ### msgpack 1.0
225
+
226
+ * Python 2 support
227
+
228
+ * The extension module does not support Python 2 anymore.
229
+ The pure Python implementation (` msgpack.fallback ` ) is used for Python 2.
230
+
231
+ * msgpack 1.0.6 drops official support of Python 2.7, as pip and
232
+ GitHub Action (setup-python) no longer support Python 2.7.
233
+
234
+ * Packer
235
+
236
+ * Packer uses ` use_bin_type=True ` by default.
237
+ Bytes are encoded in bin type in msgpack.
238
+ * The ` encoding ` option is removed. UTF-8 is used always.
239
+
240
+ * Unpacker
241
+
242
+ * Unpacker uses ` raw=False ` by default. It assumes str types are valid UTF-8 string
243
+ and decode them to Python str (unicode) object.
244
+ * ` encoding ` option is removed. You can use ` raw=True ` to support old format (e.g. unpack into bytes, not str).
245
+ * Default value of ` max_buffer_size ` is changed from 0 to 100 MiB to avoid DoS attack.
246
+ You need to pass ` max_buffer_size=0 ` if you have large but safe data.
247
+ * Default value of ` strict_map_key ` is changed to True to avoid hashdos.
248
+ You need to pass ` strict_map_key=False ` if you have data which contain map keys
249
+ which type is not bytes or str.
0 commit comments