Skip to main content

A shorthand wrapper for pygame that makes game development fast and easy

Project description

GLPG — GameLib for Pygame

A tiny wrapper for pygame that makes game development fast and approachable. Write games in a few lines instead of dozens.

pip install glpg

If you need a newer Python version, pygame-ce is also supported:

pip install pygame-ce glpg

Quickstart — Managed Loop

import glpg as gl

gl.window("720p", title="My Game", fps=60, bg_color="#1a1a2e")

@gl.on_update
def update(dt):
    if gl.key("escape"):
        gl.quit()

@gl.on_draw
def draw():
    gl.draw.rect(100, 100, 64, 64, "#e63946")
    gl.draw.circle(400, 300, 40, "cyan")
    gl.draw.text("Hello GLPG", 20, 20, size=32, color="white")

gl.run()

Quickstart — Manual Loop

import glpg as gl

gl.window("720p", title="Manual Loop")

x = 100

while (dt := gl.tick()) is not None:
    if gl.key("escape"):
        gl.quit()
    if gl.key("right"):
        x += 200 * dt

    gl.draw.rect(x, 300, 48, 48, "white")
    gl.flip()

API Reference

Window

Call Description
gl.window(size, title, icon, fps, bg_color) Initialise the window. Call once before anything else.
gl.get_size() Returns (width, height)
gl.get_width() / gl.get_height() Individual dimensions
gl.set_title(title) Change the window title
gl.set_fps(fps) Update the FPS cap at runtime
gl.set_bg_color(color) Update the clear colour
gl.get_screen() Raw pygame.Surface for advanced use

Size strings: "480p" (854×480) · "720p" (1280×720) · "1080p" (1920×1080) · "1440p" (2560×1440) Or pass a custom (width, height) tuple.


Managed Loop

Call Description
@gl.on_update Decorator that runs each frame and receives dt (seconds)
@gl.on_draw Decorator that runs each frame after clearing the screen
gl.run() Start the managed loop and block until the window closes
gl.quit() Signal the loop to stop
gl.is_running() True while the loop is active
gl.get_fps() Measured FPS for the current frame

Manual Loop

Call Description
gl.tick() Begin a frame, returns dt in seconds or None when finished
gl.flip() Present the frame at the end of your loop
gl.quit() Stop the loop on the next tick

Drawing

All draw calls go through gl.draw.*.

Call Description
gl.draw.rect(x, y, w, h, color, border, radius) Rectangle. Use radius for rounded corners.
gl.draw.circle(x, y, radius, color, border) Circle centred at (x, y)
gl.draw.ellipse(x, y, w, h, color, border) Ellipse inside a bounding box
gl.draw.line(x1, y1, x2, y2, color, width) Line between two points
gl.draw.polygon(points, color, border) Polygon from a list of (x, y) points
gl.draw.text(content, x, y, size, color, font, center, antialias) Text. center=True centres on (x, y). Returns pygame.Rect
gl.draw.image(path, x, y, scale, center, cache) Image from file. Returns pygame.Rect
gl.draw.clear(color) Clear the screen. Defaults to window bg_color
gl.draw.clear_image_cache() Evict cached image surfaces between scenes

Colors accept:

  • Named strings: "red", "white", "cornflowerblue"
  • Hex strings: "#e63946", "#ff0000ff" (with alpha)
  • RGB tuples: (255, 99, 71), (255, 99, 71, 128)

border=0 means filled. Any positive value draws an outline.


Input — Keyboard

Call Description
gl.key("W") True while the key is held
gl.key_pressed("space") True only on the first frame the key is pressed
gl.key_released("shift") True only on the release frame

Key names: letters a–z, digits 0–9, "space", "enter", "escape", "backspace", "tab", "up", "down", "left", "right", "shift", "ctrl", "alt" (also "lshift", "rshift" etc.), "f1"–"f12", "delete", "insert", "home", "end", "pageup", "pagedown".


Input — Mouse

Call Description
gl.mouse.pos (x, y) cursor position
gl.mouse.x / gl.mouse.y Individual coordinates
gl.mouse.clicked("left") True only on the click frame. Buttons: "left", "right", "middle"
gl.mouse.held("right") True while the button is held

License

MIT License 2026

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

glpg_pygame-1.0.1.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

glpg_pygame-1.0.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file glpg_pygame-1.0.1.tar.gz.

File metadata

  • Download URL: glpg_pygame-1.0.1.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for glpg_pygame-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8efcc8e9b74c725305e3eb183107a80920d7086f331f560b0d745717098ff332
MD5 70f9637e1e2aad046d1ab95915d7546f
BLAKE2b-256 9e2005b676fbdc638ac3a727310c3999ba3da417e8de3a65a372834dd286abe8

See more details on using hashes here.

File details

Details for the file glpg_pygame-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: glpg_pygame-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for glpg_pygame-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 558b45963bd41c34a40fd3bd0634398b87aa877c153a672bcd24aa53f1965a17
MD5 2b59b729d3d094d90f78740780483a76
BLAKE2b-256 08cbc99211b11a96e9851fd6d6e25e042cabf7f4901de29f72cc346bc2e9baba

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