Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.
Latest commit message
Commit time

              (c) Ctypesgen developers 2007-2022

ctypesgen is a pure-python ctypes wrapper generator. It parses C header files and creates a wrapper for libraries based on what it finds.

Preprocessor macros are handled in a manner consistent with typical C code. Preprocessor macro functions are translated into Python functions that are then made available to the user of the newly-generated Python wrapper library.

It can also output JSON, which can be used with Mork, which generates bindings for Lua, using the alien module (which binds libffi to Lua).


See for full documentation.

Run ctypesgen --help for full range of available options.


ctypesgen can be installed by pip install ctypesgen. It requires Python 3.7 to run.

Basic Usage

This project automatically generates ctypes wrappers for header files written in C.

For example, if you'd like to generate Neon bindings, you can do so using this recipe (using a standard pip install):

ctypesgen -lneon /usr/local/include/neon/ne_*.h -o

Some libraries, such as APR, need special flags to compile. You can pass these flags in on the command line.

For example:

FLAGS = `apr-1-config --cppflags --includes`
ctypesgen $FLAGS $HOME/include/apr-1/apr*.h -o

Sometimes, libraries will depend on each other. You can specify these dependencies using -mmodule, where module is the name of the dependency module.

Here's an example for apr_util:

ctypesgen $FLAGS $HOME/include/apr-1/ap[ru]*.h \
	-mapr -o

If you want JSON output (e.g. for generating Lua bindings), use


When outputting JSON, you will probably also want to use

--all-headers --builtin-symbols --no-stddef-types --no-gnu-types

Related Software of Interest

libffi is a portable Foreign Function Interface library:

Mork, the friendly alien, can be found at:


ctypesgen is distributed under the New (2-clause) BSD License: