summaryrefslogtreecommitdiff
path: root/README.md
blob: 8b46daa1f81fda6d6f998525a6c6c6e6bdf48cac (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
38
39
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 or SWIG or ctypes)

* 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)

.. _`luajit FFI`: 

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