Skip to main content

Python CFFI bindings for Raylib

Project description

Python Bindings for Raylib 3.7

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.

Full documentation

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!

Installation

We distribute a statically linked binary Raylib wheel:

pip3 install raylib

Some platforms that should be available: Windows 10 x64, MacOS 10.15 x64, Linux Ubuntu1804 x64.

If yours isn't available then pip will attempt to build from source, so you will need to have Raylib development libs installed.

If it doesn't work, build from source

How to use

There are three different ways of using this binding. You only need to pick one method, but you can combine two methods in one program if you want to.

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 raylib.static.

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

Use raylib.pyray.

If you insist on dynamic bindings and don't care that they are slower and less safe

Use raylib.dynamic.

RLZero

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 and building on more platforms

Performance

For fastest permformance 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.

Source Distribution

raylib-3.7.0.post5.tar.gz (85.7 kB view hashes)

Uploaded Source

Built Distributions

raylib-3.7.0.post5-cp310-cp310-win_amd64.whl (639.6 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

raylib-3.7.0.post5-cp310-cp310-macosx_10_14_x86_64.whl (677.4 kB view hashes)

Uploaded CPython 3.10 macOS 10.14+ x86-64

raylib-3.7.0.post5-cp39-cp39-win_amd64.whl (639.6 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

raylib-3.7.0.post5-cp39-cp39-manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.9

raylib-3.7.0.post5-cp39-cp39-macosx_10_14_x86_64.whl (677.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.14+ x86-64

raylib-3.7.0.post5-cp38-cp38-win_amd64.whl (639.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

raylib-3.7.0.post5-cp38-cp38-manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.8

raylib-3.7.0.post5-cp38-cp38-macosx_10_14_x86_64.whl (677.4 kB view hashes)

Uploaded CPython 3.8 macOS 10.14+ x86-64

raylib-3.7.0.post5-cp37-cp37m-win_amd64.whl (639.5 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

raylib-3.7.0.post5-cp37-cp37m-manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.7m

raylib-3.7.0.post5-cp37-cp37m-macosx_10_14_x86_64.whl (677.4 kB view hashes)

Uploaded CPython 3.7m macOS 10.14+ x86-64

raylib-3.7.0.post5-cp36-cp36m-win_amd64.whl (639.5 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

raylib-3.7.0.post5-cp36-cp36m-manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.6m

raylib-3.7.0.post5-cp36-cp36m-macosx_10_14_x86_64.whl (677.4 kB view hashes)

Uploaded CPython 3.6m macOS 10.14+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page