Pygame API reference
Practical notes on the modules you use most, with parameters, return values, tested examples, common errors and links to the official documentation.
Modules
pygame.displayWindows, resolutions, fullscreen and showing frames.pygame.drawRectangles, circles, lines, polygons and arcs.pygame.eventThe event queue, event types and custom events.pygame.SurfaceImages in memory, blitting and transparency.pygame.RectPositions, sizes, alignment and collision tests.pygame.spriteSprite and Group classes and collision helpers.pygame.mixerSound effects, channels and streamed music.pygame.fontFonts, rendering and measuring text.pygame.timeFrame rate, delta time, timers and delays.pygame.transformScaling, rotation, flipping and filters.pygame.mathVector2, Vector3 and helper functions.
How this reference is organised#
Each page explains one module or class: what it is for, its most important functions with parameters and return values, a complete program that uses it, and the errors people run into. Where pygame and pygame-ce differ in ways that matter, the page says so. Signatures were checked against pygame 2.6.1 and pygame-ce 2.5.8.
This is a learning-focused companion, not a replacement for the official documentation, which lists every function and option:
- pygame documentation (pygame.org)
- pygame-ce documentation (pyga.me)
Other modules#
pygame.mask (pixel-perfect collision masks), pygame.joystick (gamepads), pygame.image (loading and saving), pygame.key and pygame.mouse are explained where you need them in the tutorials and articles. For example, collision detection explains masks and joystick input covers gamepads.
Where things live#
| You want to… | Module |
|---|---|
| Open a window or go fullscreen | pygame.display |
| Draw shapes | pygame.draw |
| React to keys, mouse, window events | pygame.event |
| Load, combine or make images transparent | pygame.Surface |
| Position objects and test collisions | pygame.Rect |
| Manage many game objects | pygame.sprite |
| Play sounds and music | pygame.mixer |
| Show text | pygame.font |
| Control frame rate and timers | pygame.time |
| Scale, rotate or flip images | pygame.transform |
| Work with directions and velocities | pygame.math |