pybind11
PyO3
| pybind11 | PyO3 | |
|---|---|---|
| 44 | 161 | |
| 17,892 | 15,762 | |
| 0.4% | 1.0% | |
| 9.2 | 9.7 | |
| 5 days ago | 1 day ago | |
| C++ | Rust | |
| GNU General Public License v3.0 or later | Apache License 2.0 |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
pybind11
-
Show HN: C++26 Reflection for Python Algo Trading
There’s a constant tension in quant dev between speed-to-market (Python) and speed-to-book (C++). We've had bridges like PyBind11 [1] for years, but the manual boilerplate is usually too high a tax to use them for daily work.
With the C++26 Reflection (P2996) [2], that bridge can now be made invisible. That's the new syntax: ^^T and [: x :] .
I built this repo to show how you can use the Bloomberg/Clang P2996 fork [3] to automatically reflect a C++ quant engine into a Python execution loop. I used Merton Jump Diffusion [4] as the shell - it’s a standard model (with no special alpha) - to show the tech in a real-world context. I initially found out this was working from Callum Piper's ACCU talk [5].
I've included a justfile and Docker Clang build so people can experiment with the new reflection syntax without having to battle through the build tedium.
1. https://github.com/pybind/pybind11
- Seamlessly Integrate C++11 with Python Using pybind11
-
Experience using crow as web server
I'm investigating using C++ to build a REST server, and would love to know of people's experiences with Crow-- or whether they would recommend something else as a "medium-level" abstraction C++ web server. As background, I started off experimenting with Python/FastAPI, which is great, but there is too much friction to translate from pybind11-exported C++ objects to the format that FastAPI expects, and, of course, there are inherent performance limitations using Python, which could impact scaling up if the project were to be successful.
- Swig – Connect C/C++ programs with high-level programming languages
-
returning numpy arrays via pybind11
I have a C++ function computing a large tensor which I would like to return to Python as a NumPy array via pybind11.
-
I created smooth_lines python module, great for drawing software
This is based on the Google Ink Stroke Modeler C++ library, and using pybind11 to make it available on python.
-
Facial Landmark Detection with C++
pybind11 makes it easy to call C++ from Python if you want to mix.
-
Python’s Multiprocessing Performance Problem
If you've never used Pybind before these pybind tests[1] and this repo[2] have good examples you can crib to get started (in addition to the docs). Once you handle passing/returning/creating the main data types (list, tuple, dict, set, numpy array) the first time, then it's mostly smooth sailing.
Pybind offers a lot of functionality, but core "good parts" I've found useful are (a) use a numpy array in Python and pass it to a C++ method to work on, (b) pass your python data structure to pybind and then do work on it in C++ (some copy overhead), and (c) Make a class/struct in C++ and expose it to Python (so no copying overhead and you can create nice cache-aware structs, etc.).
[1] https://github.com/pybind/pybind11/blob/master/tests/test_py...
- Making Python Web Application with C++ Backend
-
Using pybind11 with minGW to cross compile pyhton module for Windows
I have a python module for which the logic is written in C++ and I use pybind11 to expose the objects and functions to Python.
PyO3
-
What I learned building a workflow engine from scratch in Rust
Python gets bindings through PyO3. The Rust core handles all orchestration, checkpointing, and task claiming. Python provides task implementations — plain functions stored in a dict, looked up by task ID at runtime. The @task decorator is pure Python sugar that registers a callable; when the engine needs to run a task, it calls back into Python with the deserialized input and gets the output back.
- C Is Best
- Rust Bindings for the Python Interpreter
- Show HN: Robyn – "Batman Inspired" Python Web Framework Built with Rust
-
Ask HN: Python in the NoGIL World
PyO3 0.23.0 was a big release I’ve been tinkering with extensively and support for “free-threaded Python” is a headline feature and I imagine this NoGIL Python will be extremely nice for Rust interoperability so there is definitely interest in that crate. Also could be huge for queueing data for GPUs, api servers, bulk data fetching.
For whatever reason (maybe post 2to3 PTSD), Python community seems not extremely eager to jump on latest versions of Python and it often takes a long time for popular libraries to support the latest and greatest, so I’d recommend patience and baby steps
https://github.com/PyO3/pyo3/releases/tag/v0.23.0
-
How to introduce 🦀 Rust at your company 🏭?
🤖 Unlike the above languages Rust can also be used as a replacement of part of the application. Especially if there is a part that needs some speed-up or needs some memory saving. One could replace part of a Python or Node project by Rust and embed the code using PyO3 or napi respectively. This is also going to be the topic of the presentation of Aviram Hassan called Microdosing Rust to your organization.
-
An interpreter inside an interpreter
The interop shop for Rust and Python is Pyo3. As the only game in town, Pyo3 uses the Foreign Function Interface (FFI) to allow your Rust code to make calls into the CPython binary. This works by agreeing on the Application Binary Interface (ABI), a concept I used during my career at AMD. Core software ftw!
- GraalPy – A high-performance embeddable Python 3 runtime for Java
- Advanced Python: Achieving High Performance with Code Generation
What are some alternatives?
nanobind - nanobind: tiny and efficient C++/Python bindings
rust-cpython - Rust <-> Python bindings
sparsehash - C++ associative containers
uniffi-rs - a multi-language bindings generator for rust
PEGTL - Parsing Expression Grammar Template Library
milksnake - A setuptools/wheel/cffi extension to embed a binary data in wheels