Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

PySDL is a pure Python SDL binding via on-the-fly ctypes generation

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 SDL some work on Python3 compatibility. yet incomplete October 04, 2011
Octocat-spinner-32 cparser enum consts: increment chars February 07, 2012
Octocat-spinner-32 .gitignore gitignore February 07, 2012
Octocat-spinner-32 Update April 06, 2013
Octocat-spinner-32 updated better_exchook October 04, 2011
Octocat-spinner-32 python 2to3 on October 04, 2011
Octocat-spinner-32 example2.png example2 initial. by Gabriel Jacobo July 07, 2011
Octocat-spinner-32 again the fix for SDL 1.3 as in example1 July 07, 2011


Similar projects first:

  • The equally named PySDL on SourceForge. Last update was from 2000. Implemented in C.
  • Pygame. Actively developed. Implemented in C. Is not a straight-forward 1:1 binding to SDL but has a different API.

How does this PySDL differ?

  • Purely implemented in Python.
  • On-the-fly ctypes generation from the SDL.h.
  • Straight-forward 1:1 binding to SDL.

How is it implemented?

It uses PyCParser to automatically parse the SDL headers and to generate a ctypes interface to the library.


  • I only tested it on MacOSX yet. There I needed some additional ObjC/Cocoa initializing code. Basically the stuff in SDLmain.m. Maybe similar stuff is needed on other architectures. Maybe it would also be possible to search for the SDLmain.a and just call the main in there. However, there is already a report that it also works on Linux.
  • Some more testing. Some more complex example.
  • The interface generated by PyCParser could be cached so it doesn't has to be recreated each time it is started. This has become less important though since the C parser already supports caching itself at least for the parsing part.
  • Maybe it makes sense to provide an (possibly optional) additional wrapper around SDL_Surface* which calls SDL_FreeSurface in its __del__ method.
  • PyCParser could be extended. It works just enough so that it is able to fully parse the SDL headers.

--- Albert Zeyer

Something went wrong with that request. Please try again.