This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is raylib-python-cffi (version 6.0.1.0), Python CFFI bindings for Raylib 6.0 game development library. It provides two main Python modules:
raylib: Direct C API bindings (exact copy of C functions)pyray: More Pythonic API wrapper
Also includes bindings for raymath, raygui, rlgl, physac, and GLFW.
/raylib/: Core static CFFI bindings module with build systembuild.py— Main CFFI build entry point; parses C headers and generates bindings__init__.py— Module init, loads compiled CFFI extensioncolors.py,enums.py,defines.py— Generated Python constants
/pyray/: Pythonic wrapper API module aroundraylib/dynamic/: Dynamic binding version (separateraylib_dynamicpackage)setup.py— Separate setuptools config for dynamic buildraylib/__init__.py— Runtime-loaded dynamic bindings
/examples/: Python example code organized by category (core, textures, shapes, models, shaders, physics, audio, raygui, extra)/tests/: Test scripts for both static and dynamic versions/raylib-c/: Embedded Raylib C library source (git submodule)/raygui/: Embedded raygui C library source (git submodule)/physac/: Embedded physac physics library source/docs-src/: Sphinx documentation source/docs/: Pre-built HTML documentation (hosted on GitHub Pages)setup.py— Main setuptools entry point for static buildsversion.py— Single source of truth for package version
The project uses CFFI with setuptools. Main build entry point is raylib/build.py which:
- Parses C headers from embedded libraries (
raylib-c/src/raylib.h, etc.) - Generates CFFI bindings (
_raylib_cffi.c) - Compiles platform-specific extension modules
- Handles platform-specific linking (Desktop/SDL/DRM backends)
- Supports environment variable customization for build paths
- Default:
raylib - SDL backend:
raylib_sdl - DRM backend:
raylib_drm - Software rendering (SDL):
_software(name suffix)
# Build Python library manually (generates CFFI bindings + compiles)
python3 raylib/build.py
# Build wheel distribution
pip3 install wheel
python3 setup.py bdist_wheel
# Install from wheel
pip3 install dist/raylib*.whl# Run main static test suite
cd tests && ./run_tests.sh
# Run dynamic version tests
cd tests && ./run_tests_dynamic.sh
# Individual test files
python3 tests/test_hello_world.py# Build for multiple Python versions (Linux)
./raylib/build_multi_linux.sh
# Build for multiple Python versions (general)
./raylib/build_multi.sh# Generate docs (uses Sphinx)
./make_docs.shRAYLIB_PLATFORM: Desktop (default), SDL, DRM, PLATFORM_COMMA, SDL_SOFTRAYLIB_LINK_ARGS: Manual linker arguments instead of pkg-configRAYLIB_INCLUDE_PATH: Custom path toraylib.hRAYGUI_INCLUDE_PATH: Custom path toraygui.hGLFW_INCLUDE_PATH: Custom path toglfw3.hPHYSAC_INCLUDE_PATH: Custom path tophysac.hPKG_CONFIG_LIB_raylib: pkg-config package name for raylib (defaultraylib)PKG_CONFIG_LIB_raygui: pkg-config package name for raygui (defaultraygui)
The project publishes multiple mutually exclusive PyPI packages:
raylib: Standard desktop versionraylib_sdl: SDL backend versionraylib_drm: DRM framebuffer versionraylib_dynamic: Dynamic linking version (separatedynamic/directory)
Only one can be installed at a time.
The main CI/CD workflow. Triggered on push, pull request, and manual dispatch.
Jobs:
build-mac-intel— macOS Intel runners (macos-15-intel), Python 3.7–3.14 + PyPy 3.11, Desktop/SDL platformsbuild-mac-arm64— macOS ARM64 (macos-14), Python 3.10–3.14, Desktop/SDL platformsbuild-linux— Ubuntu 16 container (electronstudio/ubuntu16-modern), Python 3.7–3.14 + PyPy 3.11, Desktop/SDL/DRM/SDL_SOFT platformsbuild-linux32— 32-bit Ubuntu 16 container, same Python versions and platformsbuild-linux-arm64— Ubuntu ARM64 (ubuntu-22.04-arm), Python 3.10–3.14, Desktop/SDL/SDL_SOFTbuild-linux-arm64-drm— Raspberry Pi OS containers (Bullseye/Bookworm), Python 3.10–3.14, DRM onlybuild-windows— Windows Server 2022, Python 3.7–3.14 + PyPy 3.11, Desktop/SDL/SDL_SOFT, x64build-windows32— Windows Server 2022, same Python versions, x86source-distro— Builds and publishes sdistdynamic-distro— Builds and publishesraylib_dynamicsdistmerge— Merges all artifact uploads
Manual dispatch inputs:
publish_to_pypi(boolean): Publish wheels to PyPI after build. RequiresPYPI_KEYsecret.
All build jobs perform a smoke test after building: import pyray; pyray.init_window(100,100,"test"), checking output for "INFO: Initializing raylib".
On-demand workflow to verify packages work when installed directly from PyPI. Triggered manually via workflow_dispatch.
Inputs:
package_name(string): Which package to test (raylib,raylib_sdl,raylib_drm,raylib_dynamic) — defaultraylibversion(string): Specific version to install (e.g.,5.5.0.2) — leave empty for latestpre_release(boolean): Whether to pass--preto pip to allow pre-release versions
Matrix:
- OS: macOS Intel (
macos-15-intel) and macOS ARM64 (macos-14) - Python versions: 3.10, 3.11, 3.12, 3.13, 3.14
- Python source: Homebrew (
brew install python@X.Y) and python.org (actions/setup-python)
The workflow installs the selected package from PyPI and runs the same smoke test (import pyray; pyray.init_window(...)) to verify the installed wheel works correctly.
test_*.py— Standard tests (run byrun_tests.sh)xtest_*.py— Extra/manual tests (not run by default scripts)test_hello_world.py— Minimal smoke test for basic import and window inittest_pyray.py— Tests thepyraywrapper APItest_static_with_only_api_from_dynamic.py— Ensures static API matches dynamictest_color.py,test_float_pointers.py— Type/struct sanity checkstest_gamepad.py,test_raygui_style.py— Feature-specific tests
- Source:
/docs-src/(Sphinx reStructuredText) - Built output:
/docs/(HTML, committed for GitHub Pages) - Hosted at: https://electronstudio.github.io/raylib-python-cffi
make_docs.shregenerates/docs/from/docs-src/
- The
version.pyfile is the single source of truth for the package version. - CFFI bindings are generated at build time from headers in
raylib-c/src/,raygui/src/,physac/src/. - Submodules must be initialized (
git submodule update --init --recursive) before building. - The
raygui.h.diffpatch is applied in CI to fix a raygui bug before compilation.