Skip to main content

A Pythonic creative coding package inspired by p5.js.

Project description

p5-py

p5-py is a Pythonic creative-coding package inspired by p5.js.

It keeps the familiar p5 sketch lifecycle and many p5-style APIs while staying native to Python, backend-agnostic, typed, and testable.

Status

The current package supports a strong 2D-first workflow, a deterministic headless renderer, a native Pyglet interactive backend, optional WEBGL-style/3D APIs, optional media extras, and optional Rust acceleration for a few compute-heavy paths.

The public API is intentionally Python-first:

  • canonical APIs use snake_case, such as create_canvas() and frame_rate()
  • p5.js-style aliases such as createCanvas() and frameRate() delegate to the same implementations
  • excluded browser-only APIs fail with explicit p5_py exceptions instead of failing indirectly

Installation

Install the published package with pip:

pip install p5-py

Install optional media support when you need camera/video helpers:

pip install "p5-py[media]"

For local development in this repository, use uv:

uv sync --dev

Quick start

import p5_py as p5


def setup() -> None:
    p5.create_canvas(320, 240)
    p5.no_stroke()


def draw() -> None:
    p5.background(245)
    p5.fill(255, 80, 80)
    p5.circle(160, 120, 80)


p5.run(setup=setup, draw=draw)

Run a sketch headlessly for deterministic tests or export flows:

uv run python examples/basic_shapes.py --backend headless --frames 1

Backends

p5-py keeps the user-facing API backend-agnostic.

  • headless renders deterministically with Pillow and is ideal for tests, CI, and export.
  • pillow is currently an alias of headless.
  • pyglet opens a native interactive window and presents frames with HiDPI support.

For backend details, see docs/user/backends.md.

Examples

Examples live in examples/.

A few useful entry points:

  • examples/basic_shapes.py
  • examples/bouncing_ball.py
  • examples/transforms.py
  • examples/image_text_data.py
  • examples/pixels_blend_export.py
  • examples/plugin_hooks.py
  • examples/webgl_primitives_gallery.py

See examples/README.md for the full index.

Documentation map

User docs:

  • docs/user/getting_started.md
  • docs/user/lifecycle.md
  • docs/user/backends.md
  • docs/user/compatibility.md
  • docs/user/images_and_pixels.md
  • docs/user/events.md
  • docs/user/plugins.md

Technical docs:

  • docs/technical/testing.md
  • docs/technical/releasing.md
  • docs/technical/hidpi_rendering.md
  • docs/technical/native_pyglet_renderer.md
  • docs/technical/rust_acceleration.md
  • docs/technical/advanced_3d_media_strategy.md
  • docs/technical/project_plan.md

Development workflow

Common local commands:

uv run ruff check .
uv run ruff format .
uv run mypy src
uv run pytest
uv run python examples/basic_shapes.py --backend headless --frames 1
uv build

Equivalent shortcuts are available in Makefile:

make lint
make test-fast
make test
make typecheck
make build

Compatibility policy

p5-py aims to keep the p5 mental model while remaining idiomatic Python.

  • Use the snake_case APIs as the canonical interface.
  • Use camelCase aliases when porting or teaching from p5.js material.
  • DOM and browser-only features are excluded.
  • Unsupported compatibility stubs raise explicit package-specific errors.

See docs/user/compatibility.md for details.

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

p5py_vibe-0.1.0.tar.gz (322.5 kB view details)

Uploaded Source

Built Distribution

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

p5py_vibe-0.1.0-py3-none-any.whl (85.1 kB view details)

Uploaded Python 3

File details

Details for the file p5py_vibe-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for p5py_vibe-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c7a8f9cf091ccbd82fe31fce2b13b9dc16fc6b9abda7e4b6f1d06548adf655d2
MD5 8f33fcd4f1608618aa1295d0ac5ae01f
BLAKE2b-256 29cca8610dc652f8e9498821e7c2128253f1a487830e9e5a47219a62adcbb5d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for p5py_vibe-0.1.0.tar.gz:

Publisher: publish.yml on JonathanHHenson/p5.py

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

File details

Details for the file p5py_vibe-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for p5py_vibe-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 010193504a5022f36953768f378b77e369f3e91856720e0782d75e0520972e2c
MD5 67baec136d8f14d91485ad4e8303b819
BLAKE2b-256 4d502e8fe94a2823bd4d673b897800e893abc7ccd87b15d7b975733d0013de59

See more details on using hashes here.

Provenance

The following attestation bundles were made for p5py_vibe-0.1.0-py3-none-any.whl:

Publisher: publish.yml on JonathanHHenson/p5.py

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