Shill me a Python FFI library

I have a program that I wrote in Python because it benefits a lot from Python libraries like argparse/shutil/tabulate/blessings and most of it doesn't need to run fast. However, there are a few small algorithmic parts that do. I'd like to rewrite them in C and I'm wondering how to do the FFI. I've already rejected pybind11 (because I don't want to use C++) and writing a full C extension (because it's too much complexity for what I want to do, which is pass a few lists of ints/strs to C and get back a bunch of ints, no custom data types or interpreter hacks). I've settled on using either ctypes or cffi, but I can't decide between these two. Could you share your experiences with them and give me a recommendation for which one to choose?
Webm unrelated.

Attached: walking-fish.webm (540x750, 1.45M)

Other urls found in this thread:

github.com/symmetryinvestments/autowrap
twitter.com/NSFWRedditGif

i wishe a fishe

I always used
github.com/symmetryinvestments/autowrap
Just write or generate some D bindings and then let the compiler automatically generate python bindings with templates

strange fish

If you're considering a rewrite, then try Numba/PyPy first. If you can fit them in, then one of these two will most likely be enough.
I've used ctypes and it's pretty good, but it really feels like a way to use already existing C code in Python rather than properly integrating Python and C. But it's retard friendly so I like it.
No clue about cffi.

Sarcopterygians, humans come from that line.

Attached: 1079A558-D42F-472B-9A92-538712FF2964.jpg (1350x700, 119.56K)

Check out Cython. You could make some minimal changes to your existing python code (adding the cython type hints) and have it generate a c extension for you.

wtf is this real???

Attached: dancing-cat-swag.gif (220x220, 396.07K)

Thanks for the answers! How is PyPy and Cython's speed? Is it closer to Python or to hand-optimized C?

PyPy is quite hit or miss, if it hits the performance is comparable to Java or JS. But if it misses it can be worse than CPython.
Cython scales with how much type hinting you provide. Just dropping it in likely won't improve performance much. But if you work for it, it's fast. Not C-fast, because any kind of FFI will still be bottlenecked by CPython. But probably enough. I guess the nice thing about Cython is that it should make porting code to C easier if it turns out you need more.

Thanks!

would fuck that ngl.

He's trying to evolve.
Push him back.

Yeah. Walking fish aren't that common but they do exist in some parts of the world.

There's literally a module called "cffi" in the standard library. Read the fucking manual, user.

Attached: 1657859454828.jpg (500x500, 22.42K)

Actually it's ctypes not cffi but it's a C FFI library so anyways just read ctypes manual. Accessing a shared library function is as easy as opening a file.

I hope it's not a real gun

push it back in.

WE WUZ FISHES

Use Cython.
C bindings are when you need to wrap existing code, if you are doing something from scratch Cython is 100x easier.

Plus you can mix and match C and Python code even within the same function, and you annotate all variables it compiles straight into C code.

Cython is fucking fantastic. Just use the 3.0 branch even thought it is in "alpha".

muh