Skip to main content

Python CFFI bindings for Raylib

Project description

Python Bindings for Raylib 2.5

New CFFI API static bindings. Faster, fewer bugs and easier to maintain than ctypes.

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.

Install

Windows 10 (64 bit): Python 3.6 - 3.7

MacOS: Python 3.5 - 3.7

Linux (Ubuntu 16.04+): Python 3.5 - 3.7

We distribute a statically linked Raylib library, install from Pypi.

pip3 install raylib

If you're a different version of Python, or a Linux with incompatible libraries then you can either use the dynamic binding only or else you will have to build from source. Download, compile and install Raylib 2.5 then

cd raylib/static
python3 build_linux.py

Use

raylib.static

Goal is make usage as similar to the original C as CFFI will allow. There are a few differences you can see in the examples. See test_static.py and examples/*.py for how to use.

from raylib.static import *

InitWindow(800, 450, b"Hello Raylib")
SetTargetFPS(60)

camera = ffi.new("struct Camera3D *", [[18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0])
SetCameraMode(camera[0], CAMERA_ORBITAL)

while not WindowShouldClose():
    UpdateCamera(camera)
    BeginDrawing()
    ClearBackground(RAYWHITE)
    BeginMode3D(camera[0])
    DrawGrid(20, 1.0)
    EndMode3D()
    DrawText(b"Hellow World", 190, 200, 20, VIOLET)
    EndDrawing()
CloseWindow()

raylib.pyray

Wrapper around the static bindings. Makes the names snakecase and converts strings to bytes automatically. See test_pyray.py.

from raylib.pyray import PyRay
from raylib.colors import *

pyray = PyRay()

pyray.init_window(800, 450, "Hello Pyray")
pyray.set_target_fps(60)

camera = pyray.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0)
pyray.set_camera_mode(camera, pyray.CAMERA_ORBITAL)

while not pyray.window_should_close():
    pyray.update_camera(pyray.pointer(camera))
    pyray.begin_drawing()
    pyray.clear_background(RAYWHITE)
    pyray.begin_mode_3d(camera)
    pyray.draw_grid(20, 1.0)
    pyray.end_mode_3d()
    pyray.draw_text("Hello world", 190, 200, 20, VIOLET)
    pyray.end_drawing()
pyray.close_window()

raylib.dynamic

In addition to the API static bindings we have CFFI ABI dynamic bindings in order to avoid the need to compile a C extension module. There have been some weird failures with dynamic bindings and ctypes bindings before and often the failures are silent so you dont even know. Also the static bindings should be faster. Therefore I recommend the static ones...

BUT the dynamic bindings have the big advantage that you don't need to compile anything to install. You just need a Raylib DLL, which we supply for Windows/Mac/Linux.

See test_dynamic.py for how to use.

richlib

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

Platforms tested

  • MacOS 10.12.6 - Python 3.7
  • Ubuntu 18.04 LTS - Python 3.6
  • Windows 10 (64 bit) - Python 3.7

HELP WANTED

  • converting more examples from C to python
  • testing and building on more platforms
  • sorting out binary wheel distribution for Mac/Win and compile-from-source distributtion for Linux
  • dealing with conversions to pointers in PyRay automatically

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

raylib-2.5.0.post4.tar.gz (10.1 MB view details)

Uploaded Source

Built Distribution

raylib-2.5.0.post4-py3-none-any.whl (11.4 MB view details)

Uploaded Python 3

File details

Details for the file raylib-2.5.0.post4.tar.gz.

File metadata

  • Download URL: raylib-2.5.0.post4.tar.gz
  • Upload date:
  • Size: 10.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for raylib-2.5.0.post4.tar.gz
Algorithm Hash digest
SHA256 6ec4c72e55f2d588254d85224e41c7ae1efc1eea87f917b4309b0f6dacff471d
MD5 9350a7e32a79daf6ad79c3870952da36
BLAKE2b-256 bb83214eeb6323e95c38c438bd1474b061ac0107d104252b3e05ab3b257fc478

See more details on using hashes here.

File details

Details for the file raylib-2.5.0.post4-py3-none-any.whl.

File metadata

  • Download URL: raylib-2.5.0.post4-py3-none-any.whl
  • Upload date:
  • Size: 11.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for raylib-2.5.0.post4-py3-none-any.whl
Algorithm Hash digest
SHA256 bf9e550992824ea781ddeac86feb08400bde16fdf85f6779c66e6ad020577ca6
MD5 3dbb118f1065de8a1d531fde8190f7d2
BLAKE2b-256 638f82f1bca3175769b96e00d450bc1111e66125da0327882b7798e2a4bee38a

See more details on using hashes here.

Supported by

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