Skip to main content

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.

Metadata

Release files for msgpack-numpy 0.4.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for msgpack-numpy 0.4.8
File Size Uploaded
msgpack-numpy-0.4.8.tar.gz 10.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for msgpack-numpy 0.4.8
File Interpreter ABI Platform
msgpack_numpy-0.4.8-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 17.8 kB

Release files / msgpack-numpy-0.4.8.tar.gz

Download URL msgpack-numpy-0.4.8.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c667d3180513422f9c7545be5eec5d296dcbb357e06f72ed39cc683797556e69
BLAKE2b-256 checksum
How to use checksums
089461e8aee142733ebfdc400a05bdac6e1763c4514bba3b42743d223f388450
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/0.0.0 CPython/3.8.13

Release files / msgpack_numpy-0.4.8-py2.py3-none-any.whl

Download URL msgpack_numpy-0.4.8-py2.py3-none-any.whl
Size 6.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
773c19d4dfbae1b3c7b791083e2caf66983bb19b40901646f61d8731554ae3da
BLAKE2b-256 checksum
How to use checksums
9b5df25ac7d4fb77cbd53ddc6d05d833c6bf52b12770a44fa9a447eed470ca9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/0.0.0 CPython/3.8.13

Release history Release notifications | RSS feed

This release

0.4.8 This release

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

1 release file

0.3.9

2 release files

0.3.8

1 release file

0.3.7

1 release file

0.3.6

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page