2 ms·
https://cffi.readthedocs.io/en/latest/ https://cffi.readthedocs.io/en/latest/ & https://docs.python.org/3/extending/extending.html https://docs.python.org/3/ext
by lykr0n 8y ago
https://cffi.readthedocs.io/en/latest/ https://cffi.readthedocs.io/en/latest/ & https://docs.python.org/3/extending/extending.html https://docs.python.org/3/extending/extending.html
There also is https://github.com/rochacbruno/rust-python-example https://github.com/rochacbruno/rust-python-example which is something I want to look into.
As for an example, I'm using Snappy right now, so here you go: https://github.com/andrix/python-snappy/blob/master/snappy/snappy_cffi_builder.py https://github.com/andrix/python-snappy/blob/master/snappy/s... & https://github.com/andrix/python-snappy/blob/master/snappy/snappy_cffi.py https://github.com/andrix/python-snappy/blob/master/snappy/s...
It still requires you to compile the C part- which is why sometimes you need GCC when you're doing a pip install.
- stochastic_monk 8y agoI’ve done a lot of interfacing with C and C++. pybind11 [0] has been the easiest and most effective for me to use. It targets C++, but it’s easy enough to wrap C code with it. Cython brings along a lot more bookkeeping code and overhead in my experience. cffi isn’t bad, but it’s not as flexible/expressive. [0] https://github.com/pybind/pybind11 https://github.com/pybind/pybind11
- filmor 8y agoCFFI has the huge advantage that you don't need to link against libpython, which in turn allows you to have a single wheel for multiple Python versions.