Skip to main content

A simple and easy-to-use library to enjoy videogames programming (written in C)

Project description

raylib-py

PyPI - Python Version GitHub release (latest by date) GitHub Release Date

PyPI - Wheel PyPI - License PyPI - Downloads

GitHub all releases GitHub release (by tag) GitHub forks

GitHub commit activity GitHub commits since tagged version

A python binding for the great C library raylib.

WARNING: Do not fork this project.

Please, read this issue for more information.

The repository for this project exists only to make new package releases. No specific changes in the source will be made.

Release Information:

The current release was made as output of another project, as mentioned in #45.

Features:

  • PEP8 naming convention only:

    Structure attributes are in snake_case, classes and other types in PascalCase.

  • Type hinting (not type annotation):

    def get_ray_collision_mesh(ray, mesh, transform):
        # type: (Ray, Mesh, Matrix) -> RayCollision
    
  • structures with functions as methods and properties:

    sound = Sound.load('my/resorces/sound.wav')     # same as load_sound(...)
    position = Vector(4.0, 10.0)
    
    # later...
    sound.play()                                    # same as play_sound(sound)
    length = position.length                        # same as vector2length(position); uses raymath.h functions
    
  • Vector{2,3,4}, Rectangle and Color have attribute swizzling;

    vec3 = Vector3(2.0, 5.0, 3.0)
    vec2 = vec3.zxy                 # vec2 is a Vector2, not a sequence type
    other_vec3 = vec2.xxy           # same thing: other_vec3 is a Vector3
    vec2.xy = vec3.y, other_vec3.z  # sequences can be set as values
    
    c_red = Color(255, 0, 0)
    c_yellow = c_red.rrb
    
    # Rectangles have aliases for width and height: w and h respectively
    rect = Rectangle(10.0, 10.0, 320.0, 240.0)
    other_rect = rect.whxy
    # Also, r and b for right and bottom; c and m for center (x axis) and middle (y axis)
    bottomright = rect.br
    rect.cm = 32.0, 40.0
    
  • Pretty printing: most structures implement __str__() and __repr__();

  • Custom library loading: load a custom lib binary when importing raylib-py:

    You may add a .raylib file to specify custom binaries to be loaded. How it works:

    • Create a .raylib file with the following contents:

      {
          "win32": {
              "64bit": "path/to/my/custom/win32/binary/filename.ext"
          },
          "linux": {
              "64bit": "path/to/my/custom/linux/binary/filename.ext",
              "32bit": "path/to/my/custom/linux/binary/filename.ext"
          },
          "darwin": {
              "64bit": "path/to/my/custom/macos/binary/filename.ext"
          }
      }
      

      Ommit platforms or architectures you don't want/have a custom binary; the default binaries will be loaded instead. The file is not inspected for any extra content.

    • Before importing raylib, make sure the current working directory points to where .raylib is located in your project.

      If .raylib is found, it will use the binary path for the system and try to load it.

      If the .raylib is invalid JSON, it will fallback to the default binary.

      If the binary is not found, it won't fallback to the default binary.

      No path manipulations like os.path.join(...) is made.

  • Context managers: begin_* and end_* functions can be called as context managers:

    Without context managers:

    # this example shows a rendering step
    
    begin_drawing()
    
    begin_texture_mode(minimap_texture)
    # render the "minimap"
    draw_line(2, 2, 5, 5, RED)
    end_texture_mode(minimap_texture)
    
    begin_mode2d(main_camera)
    # 2d drawing logic...
    draw_texture(minimap_texture, 10, 10, WHITE)
    end_mode2d()
    
    end_drawing()
    

    With context managers:

    # this example shows a rendering step
    
    with drawing():
    
        with texture_mode(minimap_texture):
            # render the minimap
            draw_line(2, 2, 5, 5, RED)
    
        with mode2d(main_camera):
            # 2d drawing logic...
            draw_texture(minimap_texture, 10, 10, WHITE)
    
  • Context managers for some structures: Camera{2,3}D, Shader and others;

    Folowing the example above:

    # this example shows a rendering step
    
    with drawing():
    
        with minimap_texture:
            # render the minimap
            draw_line(2, 2, 5, 5, RED)
    
        with main_camera:
            # 2d drawing logic...
            draw_texture(minimap_texture, 10, 10, WHITE)
    
  • RLGL and RayMath functions exposed

    Includes all symbols in raymath.h and rlgl.h

Issues:

  • Callback for logging will not work

    I've no good workaround for wrapping C functions with variable number of arguments. If you know how to solve this issue, your help would be appreciated.

  • Functions with vararg will not work

    For the reason above.

  • Avoid string manipulation functions

    For the reason above, also because some functions involve memory allocation and manual freeing of resources. Python string methods can provide you with same and more functionality.

  • Some examples are broken due to API changes

    There was some function renaming, some changes in the examples to update to newer releases.

Would you like to have a more customized binding for raylib?

Again, in issue 45 I explain the actual state of this project in more detail.

It my seems like bad news but actually it is the contrary.

Please, take a look at this project: raylibpyctbg

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-py-4.2.0.post2.tar.gz (4.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_py-4.2.0.post2-py3-none-any.whl (4.5 MB view details)

Uploaded Python 3

File details

Details for the file raylib-py-4.2.0.post2.tar.gz.

File metadata

  • Download URL: raylib-py-4.2.0.post2.tar.gz
  • Upload date:
  • Size: 4.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.0

File hashes

Hashes for raylib-py-4.2.0.post2.tar.gz
Algorithm Hash digest
SHA256 6fa432a3ecbedee4b68da810106835e3bd0ddf15374b74cef096d180de57d8dc
MD5 7ac0799b9888da4d7b22e890f3512839
BLAKE2b-256 965c49f440eba23d35eb66e45b6d8b39b22205c18b353a12b48e6546880addc3

See more details on using hashes here.

File details

Details for the file raylib_py-4.2.0.post2-py3-none-any.whl.

File metadata

File hashes

Hashes for raylib_py-4.2.0.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 f91ecd44ebb3d446e465957b700148a9f73a075daa0879a501d71aa88955d0d7
MD5 38b87056450a853ba26657f7c9fe9681
BLAKE2b-256 c991b2c69d603ca6ad74228e7ae891ec4d2de7dd84907aec2464c31bcb02a980

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