Skip to main content

Fast python conversion from protobuf to arrow using rust

Project description

ptars

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

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
]

Benchmark against protarrow

Ptars is a rust implementation of protarrow, which is implemented in plain python. It is:

  • marginally faster when converting from proto to arrow.
  • About 3 times faster when converting from arrow to proto.
---- benchmark 'to_arrow': 2 tests ----
Name (time in ms)        Mean          
---------------------------------------
protarrow_to_arrow     8.6582 (1.18)   
ptars_to_arrow         7.3336 (1.0)    
---------------------------------------

---- benchmark 'to_proto': 2 tests -----
Name (time in ms)         Mean          
----------------------------------------
ptars_to_proto          6.4088 (1.0)    
protarrow_to_proto     21.5594 (3.36)   
----------------------------------------

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.4.tar.gz (66.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ptars-0.0.4-cp310-abi3-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.10+Windows x86-64

ptars-0.0.4-cp310-abi3-win32.whl (2.2 MB view details)

Uploaded CPython 3.10+Windows x86

ptars-0.0.4-cp310-abi3-musllinux_1_2_x86_64.whl (3.0 MB view details)

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

ptars-0.0.4-cp310-abi3-musllinux_1_2_i686.whl (3.1 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

ptars-0.0.4-cp310-abi3-musllinux_1_2_armv7l.whl (3.1 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARMv7l

ptars-0.0.4-cp310-abi3-musllinux_1_2_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

ptars-0.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

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

ptars-0.0.4-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (3.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ s390x

ptars-0.0.4-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ppc64le

ptars-0.0.4-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARMv7l

ptars-0.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

ptars-0.0.4-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl (3.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.5+ i686

ptars-0.0.4-cp310-abi3-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

ptars-0.0.4-cp310-abi3-macosx_10_12_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file ptars-0.0.4.tar.gz.

File metadata

  • Download URL: ptars-0.0.4.tar.gz
  • Upload date:
  • Size: 66.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.3

File hashes

Hashes for ptars-0.0.4.tar.gz
Algorithm Hash digest
SHA256 547c8c593cf186fbb4617dc5c2cd19664e4d43a0fe4016cf75fcb087321f0f89
MD5 eca4e00b5758fa99cc2b8eca9dd5f42b
BLAKE2b-256 ff06f1979339818907c903cf50f80d183c0c842b22756909ceadbcfaa6e35b68

See more details on using hashes here.

File details

Details for the file ptars-0.0.4-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: ptars-0.0.4-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.3

File hashes

Hashes for ptars-0.0.4-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b8cf3342e3d526a7110db823d4db0d7bac8a6cf2b7b4b91c417d671a49f518de
MD5 8418736be4b014ac8daea8b79a09aefd
BLAKE2b-256 6e8c5fb5a936baef10fd0c12d1cb9c09ea52f5f58355ca2002a67a68242d0faf

See more details on using hashes here.

File details

Details for the file ptars-0.0.4-cp310-abi3-win32.whl.

File metadata

  • Download URL: ptars-0.0.4-cp310-abi3-win32.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.10+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.3

File hashes

Hashes for ptars-0.0.4-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 d3b5b0af57c9cc44cc170a83b0d092b01e323a2a5eb53832479d192879b3151b
MD5 aeec272805c71395a9e6a8d2afff0ef3
BLAKE2b-256 3b1d033688c512bae4baaea0d6820b857d11c396cc6eceeb4f42f423cacba30c

See more details on using hashes here.

File details

Details for the file ptars-0.0.4-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ptars-0.0.4-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4483ba200a769cd9a75b6ef00c9f3ca06f9f69b2dc428c17b3bf1769dd9b66d8
MD5 89ef90a10996b50c6b05d104f821a530
BLAKE2b-256 d445117fa8f78a3109108020eb7ea736be6c5175c30980a532843c000bcd2fae

See more details on using hashes here.

File details

Details for the file ptars-0.0.4-cp310-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for ptars-0.0.4-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 101afa0b3115ce53665687aefee15075333121b0a2359f2c50ae9ef2bb0b9c23
MD5 9757c033306dbe1f10fc112077b70b31
BLAKE2b-256 901bc54273255500f8de3d9efc04c871ea8756e5f475023d04954edf5e3e9767

See more details on using hashes here.

File details

Details for the file ptars-0.0.4-cp310-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for ptars-0.0.4-cp310-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 367eb6728d4a506edc544e381ee1a075a0d93c4985975b9c29729f4d9804343f
MD5 be7f2ab45b96cb505ef410ab46d78338
BLAKE2b-256 892182bd4d99940dff5053dbd77fb2b7c52937705cb3aa7d8c45e17c25c7e251

See more details on using hashes here.

File details

Details for the file ptars-0.0.4-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for ptars-0.0.4-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 bacf5c406b97d962df9730f4cda02e23761e4734f8987b600dc221221f9aa188
MD5 e96e68391806ec5b3fe0274ea7c63014
BLAKE2b-256 3c1b5b458947ca80b3257f7e72770dd9403e7a8140253f01bb076d365d5d06f0

See more details on using hashes here.

File details

Details for the file ptars-0.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ptars-0.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2277f47cac96c5ebf14f201571ccb91ba955102156e1338911af9103170dc280
MD5 156943afa29ad5c99d0fc76780e0452f
BLAKE2b-256 7f6b0491948444f6b2a9e45f21cee6790eb9a76675fb8a44f5f6f1220b5a02ab

See more details on using hashes here.

File details

Details for the file ptars-0.0.4-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for ptars-0.0.4-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 a269463a5da31731200d2fc93c706a37fa06195531a84450179901e315dcc356
MD5 c42c23e568cdaf639e368476fcce78ad
BLAKE2b-256 9db2f19473e11d6f73d9229f433d4470d79bc86c391761a1ed9c22c3c4814f5a

See more details on using hashes here.

File details

Details for the file ptars-0.0.4-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for ptars-0.0.4-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 f895bcdf30d5d783e19b1c0dc6e02a35a3f34c935a8273e4c41a9384049680f4
MD5 29c7896ea92892197e1ee6b7f9a80508
BLAKE2b-256 0d244d2adad7bfc691f52a6e88c1e4facb6bb5ad90381d4e5c7842762a8b02d3

See more details on using hashes here.

File details

Details for the file ptars-0.0.4-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for ptars-0.0.4-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 0e795ae81c2e7ee05f172a88211b988e45ea31ca1d5c4f7efd40c0ae03ebbd0f
MD5 3a97c18f974c861fba9f516d435fe47e
BLAKE2b-256 0d607a6f32232f8cd5042f14f12bd7b4d1106cbd9345d6385dd2c3dd81c1932b

See more details on using hashes here.

File details

Details for the file ptars-0.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ptars-0.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a924ffca7bc2f852c0239af5603a3d2889f94ae23b0828dcfcb4b4c2bcb70772
MD5 f252cfeb00eba46b17eaeef555ff5808
BLAKE2b-256 30c2cdedc1055202ecc1aef05b6a01bf673f2fdd84fa901b8438f62693f86271

See more details on using hashes here.

File details

Details for the file ptars-0.0.4-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for ptars-0.0.4-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 aa9ce44a15013c79bb6d40c58bd1685e2fddc51f80cee3b76c54bed950d99b66
MD5 7eeaf10a116f21cea8669388e36a37fd
BLAKE2b-256 5271aa96005bca602660c454bedae64754b37a2fe44409b0f4748be72bc8fd73

See more details on using hashes here.

File details

Details for the file ptars-0.0.4-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ptars-0.0.4-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8e1ffb50b3fbd8e36d35a6bd0a4d75e2585ed5db196c9192d4d1fbfb901aaf2f
MD5 14280298cc9ea26efb0d27a784110f94
BLAKE2b-256 81d14f85c8d21e9c7e71bc450176c3ce117ce0554f6170e334e19736ffc93add

See more details on using hashes here.

File details

Details for the file ptars-0.0.4-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ptars-0.0.4-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 230bd99ed6b81ff3230de670f930b20ccbaf30301b4b4a9ff9de7ccf379714fa
MD5 f57e6d09c14243cea29f0976972f2465
BLAKE2b-256 67a11e917669f990e8c07e4745c31c36dfc693b91ab9d61e641db0be41c7fb3c

See more details on using hashes here.

Supported by

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