The ctypes package


ctypes is an advanced ffi (Foreign Function Interface) package for Python 2.3 and higher. In Python 2.5 it is already included.

ctypes allows to call functions in dlls/shared libraries and has extensive facilities to create, access and manipulate simple and complicated C data types in Python - in other words: wrap libraries in pure Python. It is even possible to implement C callback functions in pure Python.

ctypes works on Windows, Windows CE, Mac OS X, Linux, Solaris, FreeBSD, OpenBSD. It may also run on other systems, provided that libffi supports this platform.

ctypes is licensed under the MIT License.


Documentation is available in several formats.

The ctypes-users mailing-list is the place to ask questions about ctypes and related packages; to reduce spam it is now required to be subscribed before posting. This mailing list is also available on gmane in several ways.

The ctypes-wiki will hopefully soon contain additional documentation, code snippets, answers to FAQs and more.

Related projects

A codegenerator (old documentation, out of date but you may get the idea) which will parse C header files and generate ctypes compatible Python code. There is currently no official release for the code generator, but you can get it from the ctypeslib SVN repository.

A pure Python COM package named comtypes, especially useful for calling and implementing custom COM interfaces without the need to write C/C++ code. The comtypes SVN repository contains a much improved version, I will release this asap.


Recent releases can be downloaded in the sourceforge files section. The current version is 1.0.1.

ctypes is registered in the Python package index, so you can also install it with easy_install.