Foreign Function Interface for Python calling C code. The aim of this project is to provide a convinient and reliable way of calling C code from Python. The interface is based on luajit FFI and follows a few principles:
Keep all the python-related logic in Python instead of C (unlike CPython native C extensions)
Be complete and work on the level of API (unlike ctypes)
>>> from cffi import FFI >>> ffi = FFI() >>> ffi.cdef(""" ... int printf(const char *format, ...); // copy-pasted from the man page ... """) >>> C = ffi.dlopen(None) # loads the entire C namespace >>> arg = ffi.new("char", "world") # equivalent to C code: char arg = "world"; >>> C.printf("hi there, %s!\n", arg); # call printf hi there, world! >>>
See More docs for examples and supported features.