Skip to main content

A Python binding for the great C library raylib

Project description

pyraylib

Downloads Downloads

A python binding for the great C library raylib. The library provides object-oriented wrappers around raylib's struct interfaces.

Getting Started

Prerequisites

pyraylib uses type annotations in its source, so a Python version that supports it is required.

Some Python versions may not have enum and/or typings modules as part of the standard library, wich are required. These are installed automatically by pip.

Installing

The easiest way to install pyraylib is by the pip install command:

Depending on you system and python version(s) installed, the command might be:

pip install pyraylib

or

python -m pip install pyraylib

or (with Python3.7 launcher with multiple versions installed)

py-3.x-32 -m pip install pyraylib

Note that the minimum Python version tested is 3.4. Please, let me know if you're able to run it in Python33.

pyraylib comes with 32bit binaries for Windows, Mac and Linux, but you're not required to use these. If you have a custom raylib dll, dylib or so binary, make sure to set a PATH indicating the directory it is located:

import os

# set the path before raylib is imported.
os.environ["RAYLIB_PATH"] = "path/to/the/binary"

import pyraylib

# let the fun begin.

You can set "__file__" as value to "RAYLIB_PATH" and pyraylib will search for the binary in the package dir:

# bynary file is wherever the package is located.
os.environ["RAYLIB_PATH"] = "__file__"

"__main__" can also be set to look for the binary in the project's directory where the starting script is located:

# binary file is in the same dir as this py file.
os.environ["RAYLIB_BIN_PATH"] = "__main__"

# ...

if __name__ == "__main__":
    # run the game
    # ...

Make sure the bin file name for the respective platform is raylib.dll, libraylib.3.7.0.dylib or libraylib.so.

Using pyraylib

Using pyraylib is as simple as this:

import pyraylib
from pyraylib.colors import (
    LIGHTGRAY,
    RAYWHITE
)
# Initialization
SCREEN_WIDTH, SCREEN_HEIGHT = 800, 450
window = pyraylib.Window((SCREEN_WIDTH, SCREEN_HEIGHT), 'pyraylib [core] example - basic window')
# Set our game to run at 60 frames-per-second
window.set_fps(60)

# Main game loop
while window.is_open(): # Detect window close button or ESC key
    # Update
    # TODO: Update your variables here
    # Draw
    window.begin_drawing()
    window.clear_background(RAYWHITE)
    pyraylib.draw_text('Congrats! You created your first window!', 190, 200, 20, LIGHTGRAY)
    window.end_drawing()

# Close window and OpenGL context
window.close()

The examples/ directory contains more examples.

Tests

pyraylib does not have test code, but you can run the examples in the examples directory.

raylib vs pyraylib

Below are the differences in usage between raylib and pyraylib. Note, though that these differences are being worked to make pyraylib as pythonic as possible, so changes may occur without notification.

Constant values

All C #defines got translated to Python 'constants'. Enums got translated to Python enums.

Structures

In general, all structures inherit from ctypes.Structure class. At the moment, constructors (except for vectors) require the exact argument types, so ints can't be passed where floats are expected (although the argument can be omitted).

All structures have __str__() implemented, so they have a very basic textual representation:

Contributing

Contributions of any kind welcome!

Authors

  • Ramon Santamaria - raylib's author - raysan5
  • Hussein Sarea - python binding code - pyraylib

License

pyraylib (and raylib) is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software.

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

pyraylib-1.0.2.tar.gz (1.9 MB view details)

Uploaded Source

File details

Details for the file pyraylib-1.0.2.tar.gz.

File metadata

  • Download URL: pyraylib-1.0.2.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for pyraylib-1.0.2.tar.gz
Algorithm Hash digest
SHA256 ac6d7e123ec2aa209084f5035cf4c1d9e9d7b453e1d85f7f6894c53874fbc583
MD5 7d923f1c9568ccb7455964c8540dabe6
BLAKE2b-256 fc96e0231d63dd3537ebdc34aea7f6f6ce39e3d0d7bebc58b0ba4dcb72489818

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