diff options
| author | INADA Naoki <songofacandy@gmail.com> | 2012-06-27 18:05:35 +0900 |
|---|---|---|
| committer | INADA Naoki <songofacandy@gmail.com> | 2012-06-27 18:05:35 +0900 |
| commit | 288e82029353e3c3256341c0e32d16ca32d33700 (patch) | |
| tree | 2ee99808b7615871f166d6dfec9e500926a01c16 /README.rst | |
| parent | 06ed24a529eba164b23089a7653427f62dfb32e2 (diff) | |
| download | msgpack-python-288e82029353e3c3256341c0e32d16ca32d33700.tar.gz | |
prepare 0.2
Diffstat (limited to 'README.rst')
| -rw-r--r-- | README.rst | 78 |
1 files changed, 64 insertions, 14 deletions
@@ -3,33 +3,83 @@ MessagePack Python Binding =========================== :author: INADA Naoki -:version: 0.1.0 -:date: 2009-07-12 +:version: 0.2.0 +:date: 2012-06-27 HOW TO USE ----------- -You can read document in docstring after `import msgpack` + +one-shot pack & unpack +^^^^^^^^^^^^^^^^^^^^^^ + +Use ``packb`` for packing and ``unpackb`` for unpacking. +msgpack provides ``dumps`` and ``loads`` as alias for compatibility with +``json`` and ``pickle``. + +``pack`` and ``dump`` packs to file-like object. +``unpack`` and ``load`` unpacks from file-like object. + + >>> import msgpack + >>> msgpack.packb([1, 2, 3]) + '\x93\x01\x02\x03' + >>> msgpack.unpackb(_) + (1, 2, 3) + + +``unpack`` unpacks msgpack's array to Python's tuple. +To unpack it to list, Use ``use_list`` option. + + >>> msgpack.unpackb(b'\x93\x01\x02\x03', use_list=True) + [1, 2, 3] + +Read docstring for other options. + + +streaming unpacking +^^^^^^^^^^^^^^^^^^^ + +``Unpacker`` is "streaming unpacker". It unpacks multiple objects from one +stream. + +:: + + import msgpack + from io import BytesIO + + buf = BytesIO() + for i in range(100): + buf.write(msgpack.packb(range(i))) + + buf.seek(0) + + unpacker = msgpack.Unpacker() + while True: + data = buf.read(4) + if not data: + break + unpacker.seed(buf.read(16)) + for unpacked in unpacker: + print unpacked INSTALL --------- -Cython_ is required to build msgpack. +You can use ``pip`` or ``easy_install`` to install msgpack:: -.. _Cython: http://www.cython.org/ + $ easy_install msgpack-python + or + $ pip install msgpack-python -posix -'''''' -You can install msgpack in common way. - - $ python setup.py install Windows '''''''' -MessagePack requires gcc currently. So you need to prepare -MinGW GCC. +msgpack provides some binary distribution for Windows. +You can install msgpack without compiler with them. + +When you can't use binary distribution, you need to install Visual Studio +or Windows SDK on Windows. (NOTE: Visual C++ Express 2010 doesn't support +amd64. Windows SDK is recommanded way to build amd64 msgpack without any fee.) - $ python setup.py build -c mingw32 - $ python setup.py install TEST ---- |
