1. License
“Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction”
MIT No Attribution allows any use, including selling, with no notice required.
github.com/python-cffi/cffi/blob/main/LICENSE3. Used by agents' projects
Dependency in 39 public GitHub projects set up for AI coding agents that we scanned (0.6%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily; card checked Nov 11, 2026. Tap a verdict to see its source.How we checkedReport an error
What CFFI does
CFFI is a free Python library that lets Python programs use code written in C. You copy a few C declarations, and Python can call a library already on the computer or a small fast function you wrote in C. It works without a C compiler, but with one it is safer and faster.
What people build with it
Use a C library already on the machine
Your Python app calls a C library that is installed on the computer, such as zlib, without writing any C and without a compiler.
Speed up one slow calculation
A loop that is too slow in Python, like counting or scoring many items, moves into a small C function your Python code calls like any other.
Wrap C source code you were given
You have the .c and .h files of a library, for example from a device maker, and turn them into one module your Python app imports.
Read binary files with a fixed layout
Load pixel data or records from a binary file into C-shaped structures, change a few fields and write them back.
Let a C program run Python code
Package Python code as a plug-in library that an existing C or C++ program loads and calls.
Drive a device from a web backend Idea
A Python backend controls a label printer or scanner through the maker's C library, so the web page can print or scan.
CFFI popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How CFFI is used
- CFFI is a dependency in 39 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (2.4% of the 1,623 Python ones), #9 of 70 in languages, types and runtimes.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,041; those are left out of every share on this page.
- The most used alternative in our scan is Cython (4 projects).
- Projects that use it most often also use pycparser (97.4%), Pydantic (92.3%), Click (87.2%).
By coding agent
Often used with
More about CFFI
More in Languages, types and runtimes
Alternatives
CFFI This page
Pick pybind11 when the code you want to call from Python is C++, which CFFI does not support.
Pick Cython when you want to speed up existing Python code by compiling it, with C types added where needed.
Pick Numba when the slow part is a numeric loop and you would rather not write any C.
Get started
Tell your AI assistant
“Use cffi (pin cffi==2.1.1, Python 3.10+) to call this C library from Python; prefer API mode with set_source() and a build script, add setuptools on Python 3.12+, pass bytes for char * arguments, and keep every ffi.new() object alive while C uses it.”
Install it into your project's Python environment (Python 3.10 or newer).
pip install cffiDeclare the C functions you need and load a library that is already installed (no compiler needed).
>>> 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[]", b"world") # equivalent to C code: char arg[] = "world"; >>> C.printf(b"hi there, %s.\n", arg) # call printf hi there, world.When a C compiler is available, prefer the compiled mode with set_source() and compile(); it is safer and faster.
Mistakes to avoid
In our run on Python 3.12 compile() stopped with "This CFFI feature requires setuptools on Python >= 3.12"; it worked after installing setuptools.
char * parameters take bytes, not str.
The inner object has no Python reference, so its memory is freed at once and C reads garbage.
char * allocates a single character, not a string.
On Python 3 under Windows dlopen(None) does not work.
Questions
Do I need a C compiler?
Not for the simple mode that loads an installed library. The compiled mode, which the docs recommend, needs one on the machine that builds the module.
Why does compile() fail with "requires setuptools" on Python 3.12?
Python 3.12 removed the old build tools CFFI used. Add setuptools to your project; CFFI does not pull it in by itself.
Can I pass a normal Python string to a C function?
No. Functions that take char * expect bytes, so encode the string first.
Can I use it in a commercial product?
Yes. The MIT No Attribution license allows any use, without a credit requirement.
Is it still maintained?
Yes. Version 2.1.1 came out in August 2026 and keeps up with new Python versions.