Skip to main content

Running Pyglet on PyPy

As part of our efforts of making PyPy's Python interpreter usable we put quite some effort into interfacing with external libraries. We were able, in quite a short amount of time (I think beginning really from Leysin sprint, or slightly earlier) to provide a prototype of the ctypes library. It is written in completely normal Python, at applevel, based on a very thin wrapper around the libffi library. This makes development a lot easier, but it makes the resulting ctypes implementation rather slow. The implementation is not complete yet and it will still need quite some effort to make it feature-complete (ctypes has lots of details and special cases and do-what-I-mean magic). Yet another point will be to make it faster, but that's for much later.
The implementation is good enough to run those parts of Pyglet that don't depend on PIL (which PyPy doesn't have). Here are a few pictures of running Pyglet demos on top of compiled pypy-c. To compile a version of PyPy that supports ctypes, use this highly sophisticated command line
./ --gc=generation ./ --allworkingmodules --withmod-_rawffi
Note: this works on linux only right now.
The list of missing small ctypes features is quite extensive, but I consider the current implementation to be usable for most common cases. I would love to hear about libraries written in pure python (using ctypes), to run them on top of PyPy and use them as test cases. If someone knows such library, please provide a link.


Richard Jones wrote on 2008-02-21 01:17:

This is very cool news indeed! The second screenshot seems to show a strange artefact though on the inside of the torus. Is that running the unmodified examples/ code, or has the example been modified to display a second torus? It should also be noted that pyglet is perfectly usable without PIL (as long as you have libgdk installed under Linux which almost everyone will do).

Richard Jones wrote on 2008-02-21 03:16:

ps. it's "pyglet" with a little "p" :)

René Dudfield wrote on 2008-02-21 04:04:

Very cool :)

Here's two more ctypes things... which you probably know about already, but eh :)


Anonymous wrote on 2008-02-21 08:52:

Congratulations from me!

Carl Friedrich Bolz-Tereick wrote on 2008-02-21 09:07:

hi illume,

yep, we know about those, thank you anyway :-).


Carl Friedrich

Anonymous wrote on 2008-02-21 13:53:

Very exciting to see my humble 'triangles' pyglet demo being used in the blue colored screenshot. If anyone's interested, the code for that is here:

I should remember to put an explicit CC license on my whole site.

Justin wrote on 2008-02-29 08:58:

needs only ctypes, iirc.

Gerhard Häring wrote on 2008-03-05 16:07:

Please try the ctypes-based pysqlite reimplementation at

It's meant to become the "sqlite3" module for PyPy.

Carl Friedrich Bolz-Tereick wrote on 2008-03-05 21:15:

Hi Gerhard,

yip, we know about this sqlite implementation, thank you! We are already using it for our tests (and most of its tests already work).


Carl Friedrich