The ctypes module

overview :: tutorial :: reference :: faq

( Work in progress: COM :: COM sample )

Overview

ctypes is a Python package to create and manipulate C data types in Python, and to call functions in dynamic link libraries/shared dlls. It allows wrapping these libraries in pure Python.

It works on Windows, Linux and MacOS X and other systems. The latter require that your machine is supported by libffi.

News

ctypes version 0.9.0 has been released.

ctypes now requires Python 2.3 or higher, Python 2.2 is no longer supported.

The big change is that ctypes now uses the same code base on all platforms, many, many bug should have been fixed this way on non-windows systems.

There have been lots of improvements and additions both to ctypes itself, and to the ctypes.com windows framework, too many to remember now and document here.

Most prominent additions to ctypes.com are:

A ctypes.com.client module supporting dynamic dispatch

An internet explorer toolband sample

Many improvements to the stoplite sample

Detailed changelogs are in CVS (well, sometimes I forget to update them):

ChangeLog

com ChangeLog

Future plans

The ultimate purpose of the 0.9 release series is to shake out the remaining bugs, especially on platforms I have no access to, and to target a rock stable ctypes 1.0 release.

When ctypes 1.0 is released, the com framework will be split off into a separate framework named comtypes.

Testimonials

I am using it and much prefer it to the calldll/windll ... easy to use, well documented ... - Ben C

Your ctypes stuff is awesome! Thanks so much for making it. Almost every time I write a C extension it's so I can call some Windows function - I don't know if I'll need to do that much anymore and that makes me very happy. :) - Dave Brueck

ctypes! With stuff like Pysco and Pyrex maturing, the main reason I was still writing C extensions was to access various Windows APIs (especially those not covered in the Win32 Python extensions), but no longer - I may never write another "wrapper" extension again and that makes me very, very happy. :) - Dave Brueck

I like the idea of using ctypes for creating highly native windows applications. So far I have been using wxPython, but that library is so big that it adds 3-4 seconds latency to the startup of the python :-), Also memory footprint is kind of huge. - Henk Punt

... and I just started using ctypes tonight. Good old calldll/windll won't be in my toolkit much longer. :) It's a very exciting time for Python. Between Psyco and ctypes, writing code in C is becoming quite rare for me! - Jimmy Retzlaff

ctypes is very cool! Great piece of work. - Just van Rossum

Old news

ctypes version 0.6.3 has been released. The changes are summarized here.

Yasushi Masuda has translated the docs into japanese.

A ctypes Wiki, and a mailing list which should be used to discuss the usage and further development of ctypes. More info can be found on the list info page.

ctypes version 0.6.0 has been released, and the documentation has been updated.

There have been some (also incompatible) changes, but I'm quite pleased with the result: ctypes is much more consistent than before.

A proof-of-concept COM framework has been implemented, and added to the package. It is in an early stage, and I would like experienced COM developers to look at it, and submit feedback.

ctypes now works on Windows, Linux and MacOSX. Thanks to Robin Becker and Just van Rossum for their help.

ctypes Development now takes place on sourceforge's ctypes project page.

I've started a FAQ which should be consulted in case of problems.

Documentation

An extensive tutorial is included in the source distribution, but also available online. You should also read the sample files in the source distribution.

Downloads

Recent releases can be downloaded in the sourceforge files section.

The source archives contain all the sources, the documentation you are reading here, and sample files in a samples subdirectory. Looking at the sample files is highly recommended in addition to reading the documentation.

The binary Windows distribution only everything except the documentation, the unittests, and some example scripts.

These files are distributed under the MIT license.



Page updated: Wed Jul 14 13:55:15 2004