Skip to main content

Python CFFI bindings for Raylib

Project description

Python Bindings for Raylib 4.0.0

New CFFI API static bindings.

  • Automatically generated to be as close as possible to original Raylib.
  • Faster, fewer bugs and easier to maintain than ctypes.
  • Commercial-friendly license.
  • Docstrings and auto-completion.
  • Now includes extra libraries: raygui, rlgl and physac

Full documentation

Quickstart

pip3 install raylib

from pyray import *
init_window(800, 450, "Hello")
while not window_should_close():
    begin_drawing()
    clear_background(WHITE)
    draw_text("Hello world", 190, 200, 20, VIOLET)
    end_drawing()
close_window()

Installation

First make sure you have the latest pip installed:

python3 -m pip install --upgrade pip

Then install

python3 -m pip install raylib

On most platforms it should install a binary wheel (Windows 10 x64, MacOS 10.15 x64, Linux Ubuntu1804 x64).

If yours isn't available then pip will attempt to build from source, in which case you will need to have Raylib development libs installed, e.g. using homebrew, apt, etc.

If it doesn't work, you can build manually.

Dynamic binding version

There is now a separate dynamic version of this binding:

python3 -m pip install raylib_dynamic

Read this before using raylib_dynamic

Beta testing

You can install an alpha or beta version by specifying the exact version number like this:

python3 -m pip install raylib==4.0a6

How to use

There are two APIs, you can use either or both:

If you are familiar with C coding and the Raylib C library and you want to use an exact copy of the C API

Use the C API.

If you prefer a slightly more Pythonistic API and don't mind it might be slightly slower

Use the Python API.

RLZero

A related library (that is a work in progress!):

A simplified API for Raylib for use in education and to enable beginners to create 3d games

Help wanted

  • Converting more examples from C to Python
  • Testing on more platforms

License (updated)

The bindings are now under the Eclipse Public License, so you are free to statically link and use in non-free / proprietary / commercial projects!

Performance

For fastest performance use Pypy rather than standard Python.

Every call to C is costly, so it's slightly faster if you use Python data structures and functions when calculating in your update loop and then only convert them to C data structures when you have to call the C functions for drawing.

Bunnymark

Library Implementation Bunnies (60 FPS) Percentage
Raylib 3.7 C 168100 100%
Raylib Python CFFI 3.7 Pypy 3.7 33800 20%
Raylib Python CFFI 3.7 Python 3.9 7700 4.5%
Raylib Python CFFI 3.7 Python 3.9 Nuitka 8600 5.1%
Raylib Python CFFI 3.7 Dynamic Python 3.9 6300 3.7%

Packaging your app

You can create a standalone binary using the Nuitka compiler. For example, here is how to package Bunnymark:

pip3 install nuitka
cd examples/textures
python3 -m nuitka --onefile --linux-onefile-icon resources/wabbit_alpha.png textures_bunnymark.py

Advert

RetroWar: 8-bit Party Battle is out now. Defeat up to 15 of your friends in a tournament of 80s-inspired retro mini games.

Coding Games With Pygame Zero & Python is a book for Python beginners.

Project details


Download files

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

Files for raylib, version 4.0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size raylib-4.0.0.2-cp310-cp310-macosx_10_14_x86_64.whl (922.8 kB) File type Wheel Python version cp310 Upload date Hashes View
Filename, size raylib-4.0.0.2-cp310-cp310-manylinux2014_x86_64.whl (1.5 MB) File type Wheel Python version cp310 Upload date Hashes View
Filename, size raylib-4.0.0.2-cp310-cp310-win_amd64.whl (739.2 kB) File type Wheel Python version cp310 Upload date Hashes View
Filename, size raylib-4.0.0.2-cp37-cp37m-macosx_10_14_x86_64.whl (922.8 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size raylib-4.0.0.2-cp37-cp37m-manylinux2014_x86_64.whl (1.5 MB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size raylib-4.0.0.2-cp37-cp37m-win_amd64.whl (739.1 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size raylib-4.0.0.2-cp38-cp38-macosx_10_14_x86_64.whl (922.8 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size raylib-4.0.0.2-cp38-cp38-manylinux2014_x86_64.whl (1.5 MB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size raylib-4.0.0.2-cp38-cp38-win_amd64.whl (739.2 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size raylib-4.0.0.2-cp39-cp39-macosx_10_14_x86_64.whl (922.8 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size raylib-4.0.0.2-cp39-cp39-manylinux2014_x86_64.whl (1.5 MB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size raylib-4.0.0.2-cp39-cp39-win_amd64.whl (739.2 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size raylib-4.0.0.2-pp37-pypy37_pp73-manylinux2014_x86_64.whl (1.0 MB) File type Wheel Python version pp37 Upload date Hashes View
Filename, size raylib-4.0.0.2.tar.gz (54.6 kB) File type Source Python version None Upload date Hashes View

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 Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page