Skip to content

elbaro/pyo3-prost

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastproto

fastproto exposes Rust protobuf structs (generated by prost) to Python.

Both Rust and Python code share the same memory layout. Python code accessing a field [123, 456, 789] will get a reference to Vec instead of copying them to PyList.

Docs

# decoding (secs)
2021                             2023
Python:  14.008996680990094      Python:  0.3742136040236801
Rust  :  0.5708326659951126      Rust  :  0.47216512804152444

# encoding (secs)
2021                             2023
Python:  8.68384731200058        Python:  0.26067180099198595
Rust  :  0.3029898940003477      Rust  :  0.23681609996128827

===========
PythonTweet
===========
b'\n\x11Hi this is a text\x10\xfb\x99K"\x1b\n\x03Who\x12\x14https://example.com/*\x06@trump*\x06@obama'
===========
  RustTweet
===========
b'\n\x11Hi this is a text\x10\xfb\x99K"\x1b\n\x03Who\x12\x14https://example.com/*\x06@trump*\x06@obama'

All you need is adding a single line

.type_attribute(".", "#[::pyo3_prost::pyclass_for_prost_struct]")

to your prost or tonic build.

Example

  1. Go to examples/proto-gen and cargo run. This will generate examples/rupy_proto/src/app.rs.
  2. Go to examples/rupy_proto and cargo build --release.
  3. Move examples/rupy_proto/target/release/librupy_proto.so to examples/rupy_proto/rupy_proto.so.
  4. Run the bench cd examples/rupy_proto && PYTHONPATH=. python bench_{decode, encode}.py.

TODO

  • rename pyo3-prost
  • oneof fields
  • enum

About

Use Rust protobuf structs in Python.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages