• Stars
    star
    183
  • Rank 208,898 (Top 5 %)
  • Language
    Python
  • License
    Other
  • Created over 11 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Serialize numpy arrays using msgpack

Numpy Data Type Serialization Using Msgpack

Package Description

This package provides encoding and decoding routines that enable the serialization and deserialization of numerical and array data types provided by numpy using the highly efficient msgpack format. Serialization of Python's native complex data types is also supported.

Latest Version Build Status

Installation

msgpack-numpy requires msgpack-python and numpy. If you have pip installed on your system, run

pip install msgpack-numpy

to install the package and all dependencies. You can also download the source tarball, unpack it, and run

python setup.py install

from within the source directory.

Usage

The easiest way to use msgpack-numpy is to call its monkey patching function after importing the Python msgpack package:

import msgpack
import msgpack_numpy as m
m.patch()

This will automatically force all msgpack serialization and deserialization routines (and other packages that use them) to become numpy-aware. Of course, one can also manually pass the encoder and decoder provided by msgpack-numpy to the msgpack routines:

import msgpack
import msgpack_numpy as m
import numpy as np

x = np.random.rand(5)
x_enc = msgpack.packb(x, default=m.encode)
x_rec = msgpack.unpackb(x_enc, object_hook=m.decode)

msgpack-numpy will try to use the binary (fast) extension in msgpack by default.
If msgpack was not compiled with Cython (or if the MSGPACK_PUREPYTHON variable is set), it will fall back to using the slower pure Python msgpack implementation.

Notes

The primary design goal of msgpack-numpy is ensuring preservation of numerical data types during msgpack serialization and deserialization. Inclusion of type information in the serialized data necessarily incurs some storage overhead; if preservation of type information is not needed, one may be able to avoid some of this overhead by writing a custom encoder/decoder pair that produces more efficient serializations for those specific use cases.

Numpy arrays with a dtype of 'O' are serialized/deserialized using pickle as a fallback solution to enable msgpack-numpy to handle such arrays. As the additional overhead of pickle serialization negates one of the reasons to use msgpack, it may be advisable to either write a custom encoder/decoder to handle the specific use case efficiently or else not bother using msgpack-numpy.

Note that numpy arrays deserialized by msgpack-numpy are read-only and must be copied if they are to be modified.

Development

The latest source code can be obtained from GitHub.

msgpack-numpy maintains compatibility with python versions 2.7 and 3.5+.

Install tox to support testing across multiple python versions in your development environment. If you use conda to install python use tox-conda to automatically manage testing across all supported python versions.

# Using a system python
pip install tox

# Additionally, using a conda-provided python
pip install tox tox-conda

Execute tests across supported python versions:

tox

Authors

See the included AUTHORS.md file for more information.

License

This software is licensed under the BSD License. See the included LICENSE.md file for more information.

More Repositories

1

scikit-cuda

Python interface to GPU-powered libraries
Python
943
star
2

ripdb

Remotely accessible IPython-enabled debugger
Python
28
star
3

nseindia_lob

National Stock Exchange of India Limit Order Book Simulation
Python
27
star
4

tikzumlx

Fork of tikzuml with a few modifications
10
star
5

xxh

Python bindings for xxHash non-cryptographic hash algorithm
C
10
star
6

imshowpair

Compare two images with matplotlib
Python
10
star
7

duster

Reset IPython namespace and reload specified packages
Python
9
star
8

icypher

Cypher access to Neo4J via IPython
Python
8
star
9

cudamps

Python interface to CUDA Multi-Process Service
Python
7
star
10

pgf2img

Script for generating images directly from PGF/TikZ diagrams
Python
5
star
11

fuzzdoc

Fuzzy select topic to view with pydoc
Python
5
star
12

nseindia_reformat

Reformatting and Analysis of Indian National Stock Exchange Equity Order/Trade Data
Python
4
star
13

idisplay

IPython rich display magic functions
Python
4
star
14

iorient

Access OrientDB via IPython
Python
3
star
15

pyoetl

Python interface to OrientDB ETL tool.
Python
3
star
16

chash

Content-based hash
Python
2
star
17

chooser

Choose browser when opening a URI
Python
1
star
18

jupyterlab-chromium

Launch JupyterLab as a Chromium app.
Shell
1
star
19

lebedov.github.io

lebedov.github.io website
HTML
1
star
20

graphviz_conda_recipe

Conda recipe for packaging graphviz.
Shell
1
star
21

markovapplet

M/M/s queue simulator Java applet
Java
1
star
22

dask-ml-on-azure-ml

Using Dask-ML on Azure ML
Python
1
star
23

ipdbkernel

Jupyter kernel for IPython debugger
Python
1
star
24

getprox

Retrieve lists of free HTTP proxies from online sites.
Python
1
star