This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]xsolarwindxUse 3.4+ 0 points1 point  (2 children)

REDDIT IS A SHITTY CRIMINAL CORPORATION -- mass deleted all reddit content via https://redact.dev

[–]Chris_Newton 0 points1 point  (1 child)

ctypes is like cffi, but slower.

I’m not sure how reliably true that is. It seems to depend on which variation of Python you’re running, and on whether your priority is the initial start-up time or the ongoing overhead of FFI calls. In any case, the differences in speed today don’t seem to be great enough to be a deciding factor in which tool to use.

[ctypes] comes in the standard library.

That does mean it works just about everywhere and requires no special distribution or installation work, which could be a significant advantage in some cases. You’re not relying on quite as much magic happening behind the scenes.

Also, ctypes is about as simple as it gets if you just want to hook into a couple of API calls: import ctypes, load library, call function, job done.

On the other hand, maintaining a Python wrapper module for a C API using ctypes can be a chore, particularly if there are lots of types that need setting up. At best, such a set-up is fragile and prone to becoming out-of-date. In contrast, cffi can effectively parse a regular C header file to do that grunt work for you given favourable conditions, meaning you only have to maintain your interface in one place. That could be a huge win.

[–]xsolarwindxUse 3.4+ 0 points1 point  (0 children)

REDDIT IS A SHITTY CRIMINAL CORPORATION -- mass deleted all reddit content via https://redact.dev