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 using pickle as a fallback solution. Deserializing them requires unpickling, which executes arbitrary code from the payload, so decoding is disabled by default (CWE-502): decode, unpackb/unpack and Unpacker raise msgpack_numpy.PickleNotAllowed when they encounter an object-dtype array. If you control both ends, opt in explicitly:

x_rec = msgpack.unpackb(x_enc, allow_pickle=True)

Never enable allow_pickle for untrusted input. As the overhead of pickle serialization negates one of the reasons to use msgpack, consider writing a custom encoder/decoder for your specific use case instead.

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. This is the Baseten fork of lebedov/msgpack-numpy; the distribution is named b10-msgpack-numpy and still provides the msgpack_numpy module.

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.

See Also

msgpack-numpy-js by Egil Möller is a JavaScript library that can serialize and deserialize JS typed arrays with msgpack.

msgpack-numpy-rs by Terrence Liu is a Rust crate (mostly) compatible with msgpack-numpy that can serialize and deserialize numpy arrays with msgpack.

Metadata

Release files for b10-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 b10-msgpack-numpy 0.4.8
File Size Uploaded Provenance Actions
b10_msgpack_numpy-0.4.8.tar.gz 11.3 kB Without provenance Details for b10_msgpack_numpy-0.4.8.tar.gz

Built distribution (wheel)

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

Total release size: 19.3 kB

Release files / b10_msgpack_numpy-0.4.8.tar.gz

Download URL b10_msgpack_numpy-0.4.8.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2ad2ad724ac15a3d0c6f72d6d4efd062692e00591223e8a80eeaea75bb7fc0a3
BLAKE2b-256 checksum
How to use checksums
ca940a6b8a2d8167bbfc517a3032035b580bf91873e8dad301bb2768d5b5f601
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

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

Download URL b10_msgpack_numpy-0.4.8-py2.py3-none-any.whl
Size 8.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
cc9d8283cebcb88f49e79664e328c432e2a0398ddf54d27c33121edfc22f8ded
BLAKE2b-256 checksum
How to use checksums
a90c65498f97051caabd5a584f9600dd30f0bd597a881ea431f60acd670850d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for b10-msgpack-numpy 0.4.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4.8 This release

2 release files No provenance

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