Numpy data serialization using msgpack
Project description
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.
Installation
msgpack-numpy requires msgpack-python and numpy.
To install the package and all dependencies. You can 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file msgpack-numpy-opentensor-0.5.0.tar.gz
.
File metadata
- Download URL: msgpack-numpy-opentensor-0.5.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 213232c20e2efd528ec8a9882b605e8ad87cfc35b57dfcfefe05d33aaaabe574 |
|
MD5 | d194dd6e097908c7afb7e0e6f1d074d7 |
|
BLAKE2b-256 | b2692a6af13c3be6934a9ba149120a78bf63cf1455ddb1d11ec2cc5e5d6f8186 |
File details
Details for the file msgpack_numpy_opentensor-0.5.0-py2.py3-none-any.whl
.
File metadata
- Download URL: msgpack_numpy_opentensor-0.5.0-py2.py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a61c597a976425a87094d8e89846aa9528eb1f037e97ff1428fe3cd61a238e7 |
|
MD5 | 844ccaf66057322da320600141457db0 |
|
BLAKE2b-256 | cd22590508afb85d5c27ebcb2837410413f4613eebdda6e4e02997fe08ba78e4 |