Python API

This is a wrapper around the C API with some syntactic sugar.

The API is still the same as Raylib, so you should still reply on:

The differences are:

  • the function names are in snake_case.

  • Some string and pointer conversions are handled automatically.

  • There are some helper functions to create structures.

Examples

Example program:

import pyray as pr

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

camera = pr.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0)

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

Tip

New in 3.7.0.post9:

You can also now import the functions with no prefix:

from pyray import *

init_window(800, 450, "Raylib texture test")
...

(You don’t need to use the PyRay() class anymore.)

See all examples here

API reference

pyray.BEIGE = (211, 176, 131, 255)
pyray.BLACK = (0, 0, 0, 255)
pyray.BLANK = (0, 0, 0, 0)
pyray.BLUE = (0, 121, 241, 255)
pyray.BROWN = (127, 106, 79, 255)
pyray.DARKBLUE = (0, 82, 172, 255)
pyray.DARKBROWN = (76, 63, 47, 255)
pyray.DARKGRAY = (80, 80, 80, 255)
pyray.DARKGREEN = (0, 117, 44, 255)
pyray.DARKPURPLE = (112, 31, 126, 255)
pyray.GOLD = (255, 203, 0, 255)
pyray.GRAY = (130, 130, 130, 255)
pyray.GREEN = (0, 228, 48, 255)
pyray.LIGHTGRAY = (200, 200, 200, 255)
pyray.LIME = (0, 158, 47, 255)
pyray.MAGENTA = (255, 0, 255, 255)
pyray.MAROON = (190, 33, 55, 255)
pyray.ORANGE = (255, 161, 0, 255)
pyray.PINK = (255, 109, 194, 255)
pyray.PURPLE = (200, 122, 255, 255)
pyray.RAYWHITE = (245, 245, 245, 255)
pyray.RED = (230, 41, 55, 255)
pyray.SKYBLUE = (102, 191, 255, 255)
pyray.VIOLET = (135, 60, 190, 255)
pyray.WHITE = (255, 255, 255, 255)
pyray.YELLOW = (253, 249, 0, 255)