@@ -10,53 +10,6 @@ It lets you exchange data among multiple languages like JSON.
1010But it's faster and smaller.
1111This package provides CPython bindings for reading and writing MessagePack data.
1212
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-
6013## Install
6114
6215```
@@ -65,12 +18,9 @@ $ pip install msgpack
6518
6619### Pure Python implementation
6720
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.
7322
23+ But msgpack provides a pure Python implementation (` msgpack.fallback ` ) for PyPy.
7424
7525
7626### Windows
@@ -82,10 +32,6 @@ Without extension, using pure Python implementation on CPython runs slowly.
8232
8333## How to use
8434
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-
8935### One-shot pack & unpack
9036
9137Use ` packb ` for packing and ` unpackb ` for unpacking.
@@ -97,16 +43,16 @@ msgpack provides `dumps` and `loads` as an alias for compatibility with
9743
9844``` pycon
9945>>> import msgpack
100- >>> msgpack.packb([1 , 2 , 3 ], use_bin_type = True )
46+ >>> msgpack.packb([1 , 2 , 3 ])
10147'\x93\x01\x02\x03'
102- >>> msgpack.unpackb(_, raw = False )
48+ >>> msgpack.unpackb(_)
10349[1, 2, 3]
10450```
10551
10652` unpack ` unpacks msgpack's array to Python's list, but can also unpack to tuple:
10753
10854``` 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 )
11056(1, 2, 3)
11157```
11258
@@ -127,11 +73,11 @@ from io import BytesIO
12773
12874buf = BytesIO()
12975for i in range (100 ):
130- buf.write(msgpack.packb(i, use_bin_type = True ))
76+ buf.write(msgpack.packb(i))
13177
13278buf.seek(0 )
13379
134- unpacker = msgpack.Unpacker(buf, raw = False )
80+ unpacker = msgpack.Unpacker(buf)
13581for unpacked in unpacker:
13682 print (unpacked)
13783```
@@ -162,8 +108,8 @@ def encode_datetime(obj):
162108 return obj
163109
164110
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)
167113```
168114
169115` 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.
191137... return ExtType(code, data)
192138...
193139>>> 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)
196142>>> data == unpacked
197143True
198144```
@@ -210,7 +156,7 @@ in a map, can be unpacked or skipped individually.
210156
211157## Notes
212158
213- ### string and binary type
159+ ### string and binary type in old msgpack spec
214160
215161Early versions of msgpack didn't distinguish string and binary types.
216162The type for representing both string and binary types was named ** raw** .
@@ -263,3 +209,41 @@ You can use `gc.disable()` when unpacking large message.
263209List is the default sequence type of Python.
264210But tuple is lighter than list.
265211You 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