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.3.0.tar.gz (97.4 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.3.0-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fastobjects-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f3f600f8860eb6d5ac4229dd5bc784c27a866dcce05e05add61c3d2e541bd71b
MD5 6e0d372164bbf7b6d70db8d4180f70a0
BLAKE2b-256 d90a5a3da58afa8c8d19d3554638d51dd80115e9f410533fc7968bc85df20fa2

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastobjects-0.3.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.3.0-py3-none-any.whl.

File metadata

  • Download URL: fastobjects-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.7 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ebb58c204848c4276888ab15aae825a6d0a4b60c2156c4925ce603ecc46ad04
MD5 323b6ef60ba4596b0fb6007ee6440873
BLAKE2b-256 b6ba82bbc629830576515d4bb2f56cade50d5288af60864906dc162c9f2ab64a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastobjects-0.3.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