Skip to main content

SDL2 wrapper with cffi

Project description

pysdl2-cffi is a Python wrapper for SDL2 written using cffi, featuring:

  • A cffi interface to the underlying SDL2 libraries.

  • Automatically generated, consistent helper functions for SDL2, SDL_image, SDL_mixer, and SDL_ttf that hide most allocation and dereferencing.

  • Useful docstrings on every function, including the C function signature and (for SDL2 only) the library’s original doxygen documentation reformatted as Sphinx restructured text.

  • A small collection of libSDL2’s original example / test programs converted to Python using Eric S. Raymond’s ctopy.

The goal is to provide a flat, consistent, faithful-to-C binding with some more-Pythonic renaming and conveniences.

This wrapper won’t contain anything that doesn’t directly translate to part of the library’s API. The goal is to be a dependency for something like pygame, not a replacement.

This library should be compatible with Linux, OSX and Windows.

This library is licensed under the GPLv2 or (at your option) any later version. Alternatively a commercial license can be purchased from the author for $10.

Install with pip, or download from

Source hosted at

Documentation hosted at


  • The wrapper is now built with cffi 1.1’s verify() mode and requires a C compiler to build. It is much faster than the previous version on CPython.

  • Appveyor-built binary packages now available on Windows. On Windows, the necessary SDL2 DLLs are now a pip-installed dependency.


  • Struct wrappers now expose all the attributes of the C-level struct as properties. Great for tinkering, as the property names can now be inspected interactively.

  • Struct wrappers no longer pass all attribute access through getattr/setattr. Arbitrary data can be attached to the struct wrappers as is customary in Python.

  • Fix a capitalization error for the “classy” API to conform to the general binding rules. ob.gL_Function is now ob.GL_Function.


  • Windows is now supported! You must manually download the SDL2 dll’s and place them on PATH set PATH=%PATH%;C:\users\me\SDL2Dir but pysdl2-cffi will attempt to load the Windows .dll as well as the Unix .so.


  • Enums are no longer wrapped in (nonexistent) classes

  • Python 2 can also pass Unicode where char* is required; automatically encoded to utf-8.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysdl2-cffi-0.8.0.tar.gz (195.3 kB view hashes)

Uploaded source

Built Distributions

pysdl2_cffi-0.8.0-cp34-none-win_amd64.whl (291.4 kB view hashes)

Uploaded cp34

pysdl2_cffi-0.8.0-cp34-none-win32.whl (265.6 kB view hashes)

Uploaded cp34

pysdl2_cffi-0.8.0-cp27-none-win_amd64.whl (291.5 kB view hashes)

Uploaded cp27

pysdl2_cffi-0.8.0-cp27-none-win32.whl (265.8 kB view hashes)

Uploaded cp27

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page