Skip to main content

The fastest 2D object rendering library for Python

Project description

FastObjects

The fastest 2D object rendering library for Python.

FastObjects renders thousands of 2D sprites and shapes per frame with a single OpenGL draw call per batch. State lives in flat NumPy arrays instead of per-object Python instances, so you mutate positions with array slicing and let the GPU do the rest.

Installation

pip install fastobjects

Quick start

import fastobjects as fo

win = fo.Window(800, 600, title="FastObjects demo")

sprites = fo.SpriteBatch("player.png", capacity=1000)
group = sprites.spawn(1, x=400, y=300)

@win.frame
def update(dt: float) -> None:
    if win.keys[fo.KEY_RIGHT]:
        group.pos[:, 0] += 200 * dt

    win.clear(0.1, 0.1, 0.1)
    win.draw(sprites)

    if win.keys[fo.KEY_ESCAPE]:
        win.request_close()

win.run()
  • Window opens a native GLFW window with an OpenGL 3.3 core context and drives the frame loop (run() calls your @win.frame callback every frame with dt). win.keys[fo.KEY_X] and win.mouse expose polled input state.
  • SpriteBatch holds up to capacity textured sprites; spawn() returns a SpriteGroup whose .pos, .size, .rot, and .color are NumPy views into the batch — writing to them updates the sprites directly, no per-object overhead.
  • ShapeBatch works the same way for rectangles, circles, and lines (batch.rects(...), batch.circles(...), batch.lines(...)), useful for debug overlays or non-textured geometry.
  • win.draw(*batches) issues one draw call per batch, in the order given.

Why it's fast

FastObjects is written in Python, but the hot path isn't: sprite/shape state lives in flat NumPy arrays, and each batch.draw() uploads the whole array and issues a single OpenGL draw call (via moderngl) for the entire batch — no per-object Python loop, no per-object GPU call. The interpreter overhead that usually kills naive Python renderers never touches the per-sprite path.

Benchmarks

Sprites sustained at 60 fps, measured on the same machine (AMD Radeon RX 580, Python 3.13) against other Python rendering libraries — see benchmarks/RESULTS.md for methodology and full history:

Framework Sprites @ 60 fps
fastobjects 218,809
arcade 5,692
raylib 5,692
pyglet 3,795
pygame-ce 1,687

Note: raylib and pygame-ce numbers above reflect a specific run in that history file — check benchmarks/RESULTS.md for the full, dated series and hardware details before quoting a number as "current".

Development

Install with development dependencies:

pip install -e ".[dev,bench]"

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

fastobjects-0.2.0.tar.gz (78.3 kB view details)

Uploaded Source

Built Distribution

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

fastobjects-0.2.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file fastobjects-0.2.0.tar.gz.

File metadata

  • Download URL: fastobjects-0.2.0.tar.gz
  • Upload date:
  • Size: 78.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastobjects-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f85b01060d79729a1cc5d292702ae51393066be83cd986128239a712cfe464fd
MD5 65a77b3b64fdf93a781d6571b81cca9c
BLAKE2b-256 9d267f811c26118fb3130002b2087354818adbe78dfbe7e9373d7fae8365dd0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastobjects-0.2.0.tar.gz:

Publisher: publish.yml on Enzo-Azevedo/FastObjects

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastobjects-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: fastobjects-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastobjects-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2aa103860a9a7a85997e4bc9b7c3495827c4541ce160c63a79620ca07b40b4f
MD5 90f206554295eb4ee0cd6437da8ad733
BLAKE2b-256 98f25501e822b93732621848b3f8aacaf9fb6f954f2a257326cdcea194fb02b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastobjects-0.2.0-py3-none-any.whl:

Publisher: publish.yml on Enzo-Azevedo/FastObjects

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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