blob: 8ae81b672a405e750f2899bb9191bd154d894621 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
cffi
====
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](http://luajit.org/ext_ffi.html) and follows a few principles:
* You want to use C code from Python code, so you should be able to do so
without needing to learn a 3rd language
(unlike [Cython](http://www.cython.org) or [SWIG](http://www.swig.org/) or ctypes)
* Keep all the python-related logic in Python instead of C (unlike
[CPython native C extensions](http://docs.python.org/extending/extending.html))
* Be complete and work on the level of API (unlike [ctypes](http://docs.python.org/library/ctypes.html))
Simple example
--------------
>>> from cffi import FFI
>>> ffi = FFI()
>>> ffi.cdef("""
... int printf(const char *format, ...);
... """)
>>> C = ffi.rawload(None) # loads the entire C namespace
>>> C.printf("hi there, %s!\n", ffi.new("char[]", "world"));
Contact
-------
[Mailing list](https://groups.google.com/forum/#!forum/python-cffi)
Initial motivation
------------------
http://mail.python.org/pipermail/pypy-dev/2012-May/009915.html
|