pygraphics

pygraphics — 2D graphics engine & canvas framebuffer.

pygraphics Native C and pure-Python 2D graphics library with drawing primitives, bitmap font rendering, paletted surface blitting, and area-dirtying pipelines.

Live Pure-Python Device

Graphics Engine Capabilities

Key features distinguishing pygraphics from standard framebuf.

Dirty Bounding Area Tracking

Every drawing method (fill_rect, circle, line, text) returns an Area(x, y, w, h) bounding box for partial screen updates.

Exposed Read-Only Attributes

Direct access to fb.buffer, fb.width, fb.height, fb.format, and fb.color_depth for zero-copy driver flushing (stride is an internal implementation detail, not a public attribute).

24-bit True Color (RGB888)

Native 24-bit pixel support ideal for high-res display panels as well as NeoPixel (WS2812B) and DotStar (APA102) LED matrix arrays.

Multi-Font Bitmap Engine

Includes built-in text8 (8x8), text14 (8x14), text16 (8x16) fonts, plus custom font object rendering.

Transparent Colorkey Blitting

blit_transparent() enables sprite rendering and icon compositing with custom transparent colorkey masks.

Dual-Mode Invocation

Invoke via OOP methods (fb.circle(...)), standalone functions (pygraphics.circle(fb, ...)), or the Draw styling context.

Installation

The two install lines from the README: the native wheel, and the pure-Python package.
# Native C extension (CPython desktop, Android, Pyodide)
pip install -i https://test.pypi.org/simple/ \
  --extra-index-url https://pypi.org/simple/ pydevices-pygraphics
# Pure Python, for MicroPython and CircuitPython
import mip
mip.install("pygraphics", index="https://PyDevices.github.io/mip")
# Native C module in your MicroPython 1.29 firmware: one manifest line
include("/path/to/pygraphics/manifest.py")

Every build reports which pygraphics it is: pygraphics.__version__ and pygraphics.__revision__, new in 0.0.39, are stamped at build time on MicroPython, CircuitPython and the CPython wheel. pygraphics.implementation() tells you whether the native module or the pure-Python package is running. The newcomer's guide maps the rest.

API Code Example

Dirty Area tracking and FrameBuffer creation.
from pygraphics import Area, FrameBuffer, RGB565, implementation

# Verify active backend: 'native_cmod' or 'pygraphics_python'
print("Active backend:", implementation())

# Allocate 16-bit RGB565 buffer
buf = bytearray(128 * 128 * 2)
fb = FrameBuffer(buf, 128, 128, RGB565)
fb.fill(0)

# Draw circle — returns modified dirty Area bounding box
dirty_area = fb.circle(64, 64, 30, 0xF800, f=True)
print("Dirty Area:", dirty_area)  # Area(34, 34, 60, 60)