NumProto
NumProto is a simple python3.6+ library to serialize and deserialize numpy arrays into and from protobuf messages.
Installation
You can install NumProto from the PyPI package:
$ pip install numproto
Usage
NumProto serializes a numpy array into an NDArray message as specified in
ndarray.proto:
syntax = "proto3";
package numproto.protobuf;
message NDArray {
bytes ndarray = 1;
}
This library provides two methods: one for serialization ndarray_to_proto and
one for deserialization proto_to_ndarray.
import numpy as np
from numproto import ndarray_to_proto, proto_to_ndarray
nda = np.arange(10)
serialized_nda = ndarray_to_proto(nda)
deserialized_nda = proto_to_ndarray(serialized_nda)
assert np.array_equal(nda, deserialized_nda)
Re-using the proto files in another project
Re-distributing *.proto files is notoriously difficult. In order to make this
easier the
ndarray.proto
file is installed together with the python package.
This allows us to simply pass the site-packages path as an import path to
protoc.
To get the correct path of
site-packagescheck the Location key when runningpip show numproto.
For example let's say we want to create a new proto file and import NDArray
to use within one of our defined messages:
syntax = "proto3";
import "numproto/protobuf/ndarray.proto";
message MyMessage {
numproto.protobuf.NDArray my_array = 1;
}
And to compile using grpcio-tools simply do:
$ python -m grpc_tools.protoc -I/usr/lib/python3.6/site-packages/ -I./ --python_out=. --grpc_python_out=. my_proto.proto
(you may need to adjust the location of site-packages)
Tests
To run the tests first install the numproto package from source in development
mode and then run the tests using pytest:
$ git clone https://github.com/xainag/numproto.git
$ cd numproto
$ pip install -e .[dev]
$ pytest
Metadata
Release files for numproto 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| numproto-0.3.0.tar.gz | 4.6 kB | Without provenance | Details for numproto-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| numproto-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for numproto-0.3.0-py3-none-any.whl |
Total release size: 14.3 kB
Release files / numproto-0.3.0.tar.gz
| Download URL | numproto-0.3.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2fdfbae3edd75676dbd0b95e6d0450ae4871d6fe238de4ad9af42cf12d2e06a8
|
|
BLAKE2b-256 checksum How to use checksums |
e79305b5004b1b5fb39e47af7b34127f755d86b9e6cf48b3f507d29f1a2ff73d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.4
|
Release files / numproto-0.3.0-py3-none-any.whl
| Download URL | numproto-0.3.0-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eacf704e806953ec1aea15a156f5e56d9d4205d393fa48e66eba1a0b2350dc99
|
|
BLAKE2b-256 checksum How to use checksums |
1db40a9b6bcbc33b7652a59d8d99e1652bd097cb1544e218f1162884ff40ecde
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.4
|
Security for numproto 0.3.0
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.