# sdl2.ext - Helpful wrappers for the SDL2 API

The `sdl2.ext` module provides a rich set of modules, classes, and functions for creating games and other applications using PySDL2.

The aim of the sdl2.ext module is to wrap commonly-used parts of the SDL2 API in a more friendly and Pythonic manner, reducing the need for developers to understand the intricacies of working with `ctypes` and making it simpler and more fun to get PySDL2 programs up and running.

In addition, this module provides a number of template classes and utility functions for working with colors, input events, file assets, and more.

Due to its broad scope, the `sdl2.ext` module is divided into a number of submodules. However, everything in these submodules can be imported directly from `sdl2.ext`. For example, `from sdl2.ext import Window` is exactly the same as `from sdl2.ext.window import Window`.

## SDL2 module wrappers

Some parts of the `sdl2.ext` module contain Pythonic wrappers for common and/or unpleasant parts of the SDL2 API. At present, these modules include:

- sdl2.ext.common - Frequently Used SDL2 Functions
- sdl2.ext.window - Creating and Working with SDL2 Windows
- sdl2.ext.mouse - Configuring and Handling Mouse Input
- sdl2.ext.displays - Querying the Connected Displays
- sdl2.ext.renderer - Accelerated 2D Rendering
- sdl2.ext.msgbox - Displaying Alerts and Dialog Boxes

## Utilities for working with SDL2 in Python

Other parts of this module implement functions and classes that make it easier to work with SDL2 functions and data structures in Python (and vice versa). These include functions for converting text to and from UTF8-encoded bytes, reading and writing `ctypes` arrays, and casting `SDL_Surface` objects to Numpy arrays:

- sdl2.ext.err - Handling & Raising SDL Errors
- sdl2.ext.compat - Python Version Compatibility Helpers
- sdl2.ext.array - Tools for Working with ctypes Arrays
- sdl2.ext.pixelaccess - Array-like Access to SDL Surface Contents

## SDL2-based extensions

In addition to simple Pythonic wrappers for SDL2 functions and structures, the `sdl2.ext` module also offers a number of high-level classes and functions that use SDL2 internally to provide APIs for font rendering, handling input events, importing images, and more:

- sdl2.ext.input - Handling SDL2 Input Events
- sdl2.ext.surface - Creating and Manipulating Software Surfaces
- sdl2.ext.draw - Drawing Routines for Software Surfaces
- sdl2.ext.image - Importing and Exporting Image Files
- sdl2.ext.ttf - Rendering Text With TrueType Fonts
- sdl2.ext.bitmapfont - Basic Bitmap Font Rendering

## Useful helpers for building apps

Beyond wrappers and utilities for working with SDL2’s API, the `sdl2.ext` module also includes a number of submodules with various functions and classes to help facilitate general game and app development with PySDL2. These include classes for managing program resource files, working with colors, and more:

- sdl2.ext.resources - Resource Management
- sdl2.ext.color - Color Representation and Conversion
- sdl2.ext.colorpalettes - Predefined Color Palettes
- sdl2.ext.algorithms - Useful Algorithms

## Component-Oriented Systems

PySDL2 contains several modules designed around the concept of component-oriented game programming. These modules define various types of “systems” for processing events and “factories” for creating different types of objects, among other things.

Note

These modules are not regularly maintained, and their documentation may be inaccurate or out-of-date.

- Working with component-based entities
- General purpose event handling routines
- Sprite, texture and pixel surface routines
- Designing component-oriented user interfaces
- A simple particle system