Skip to main content

Fast python conversion from protobuf to arrow using rust

Project description

ptars

PyPI Version Python Version Github Stars codecov Build Status License Downloads Downloads Code style: black snyk

Protobuf to Arrow, using Rust

Example

Take a protobuf:

message SearchRequest {
  string query = 1;
  int32 page_number = 2;
  int32 result_per_page = 3;
}

And convert serialized messages directly to pyarrow.RecordBatch:

from ptars import HandlerPool


messages = [
    SearchRequest(
        query="protobuf to arrow",
        page_number=0,
        result_per_page=10,
    ),
    SearchRequest(
        query="protobuf to arrow",
        page_number=1,
        result_per_page=10,
    ),
]
payloads = [message.SerializeToString() for message in messages]

pool = HandlerPool()
handler = pool.get_for_message(SearchRequest.DESCRIPTOR)
record_batch = handler.list_to_record_batch(payloads)
query page_number result_per_page
protobuf to arrow 0 10
protobuf to arrow 1 10

You can also convert a pyarrow.RecordBatch back to serialized protobuf messages:

array: pa.BinaryArray = handler.record_batch_to_array(record_batch)
messages_back: list[SearchRequest] = [
    SearchRequest.FromString(s.as_py()) for s in array
]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ptars-0.0.3.tar.gz (85.2 kB view hashes)

Uploaded Source

Built Distributions

ptars-0.0.3-cp310-abi3-win_amd64.whl (2.3 MB view hashes)

Uploaded CPython 3.10+ Windows x86-64

ptars-0.0.3-cp310-abi3-win32.whl (2.1 MB view hashes)

Uploaded CPython 3.10+ Windows x86

ptars-0.0.3-cp310-abi3-musllinux_1_2_x86_64.whl (2.9 MB view hashes)

Uploaded CPython 3.10+ musllinux: musl 1.2+ x86-64

ptars-0.0.3-cp310-abi3-musllinux_1_2_i686.whl (3.0 MB view hashes)

Uploaded CPython 3.10+ musllinux: musl 1.2+ i686

ptars-0.0.3-cp310-abi3-musllinux_1_2_armv7l.whl (3.0 MB view hashes)

Uploaded CPython 3.10+ musllinux: musl 1.2+ ARMv7l

ptars-0.0.3-cp310-abi3-musllinux_1_2_aarch64.whl (2.7 MB view hashes)

Uploaded CPython 3.10+ musllinux: musl 1.2+ ARM64

ptars-0.0.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view hashes)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ x86-64

ptars-0.0.3-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (3.2 MB view hashes)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ s390x

ptars-0.0.3-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.7 MB view hashes)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ppc64le

ptars-0.0.3-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.8 MB view hashes)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ARMv7l

ptars-0.0.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.6 MB view hashes)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ARM64

ptars-0.0.3-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl (3.0 MB view hashes)

Uploaded CPython 3.10+ manylinux: glibc 2.5+ i686

ptars-0.0.3-cp310-abi3-macosx_11_0_arm64.whl (2.2 MB view hashes)

Uploaded CPython 3.10+ macOS 11.0+ ARM64

ptars-0.0.3-cp310-abi3-macosx_10_12_x86_64.whl (2.4 MB view hashes)

Uploaded CPython 3.10+ macOS 10.12+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page