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.

Install

Windows 10 (64 bit): Python 3.6 - 3.7

MacOS: Python 3.5 - 3.7

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

pip3 install raylib

If you're using Linux a different version of Python, or maybe a different version of Windows/Mac with incompatible libraries then you can either use the dynamic binding only or else you will have to build from source using Raylib 2.5, e.g.

cd raylib/static
python3 build_linux.py

Use

raylib.static

Currently the 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)
    DrawText(b"Hellow World", 190, 200, 20, VIOLET)
    EndDrawing()
CloseWindow()

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.

See test_dynamic.py for how to use them.

raylib.static.pyray

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

from raylib.static.pyray import pyray as prl
from raylib.colors import *

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

camera = prl.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0)
image = prl.load_image("examples/models/resources/heightmap.png")
prl.set_camera_mode(camera, prl.CAMERA_ORBITAL)

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

raylib.richlib

A very easy to use library on top of static bindings, modelled after Pygame Zero.

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

Project details


Release history Release notifications | RSS feed

This version

2.5.0

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.tar.gz (9.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: raylib-2.5.0.tar.gz
  • Upload date:
  • Size: 9.6 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.tar.gz
Algorithm Hash digest
SHA256 ae347b6066c6a05481604522728be008cdc75968c17d7b2dad87a32733b0dab0
MD5 cef9bdd309d7b91886c9f9458b038838
BLAKE2b-256 8c22c983f24c084b6a689c7a4f8e49bfef466f80c49eefadb1333f0cfcb96e31

See more details on using hashes here.

File details

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

File metadata

  • Download URL: raylib-2.5.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 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-py3-none-any.whl
Algorithm Hash digest
SHA256 3d3fa0ac4ae217c0b6e59ffa121cad58219daf68b0b8520f60dce500af7f8416
MD5 7750d5d040a3b5bc12081c945f2ab1ea
BLAKE2b-256 9d6e6a6a91e566a01e168a096950d98b8810c083b968e76894f0e0112f1cc823

See more details on using hashes here.

Supported by

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