Skip to main content

A Pythonic creative coding package inspired by p5.js.

Project description

p5py

PyPI Python Versions License: LGPL-2.1 CI Downloads

p5py is a friendly Python creative-coding library inspired by p5.js. It is for people who want to sketch with code: draw shapes, animate motion, react to input, load images, play with pixels, and make small visual experiments without first building a full app.

The public API is Python-first. Function names use snake_case, sketches are ordinary Python files, and the renderer is powered by the packaged Rust canvas runtime.

Install

pip install p5py-vibe

Install optional media helpers when you need camera, video, or sound-related extras:

pip install "p5py-vibe[media]"

First Sketch

Create a file named circle_sketch.py:

import p5


@p5.setup
def setup() -> None:
    p5.create_canvas(400, 300)
    p5.no_stroke()


@p5.draw
def draw() -> None:
    p5.background(245)
    p5.fill(255, 90, 90)
    p5.circle(200, 150, 100)


p5.run()

Run it:

python circle_sketch.py

For repeatable scripts, use a bounded headless render:

p5.run(headless=True, max_frames=1)

Callbacks can also be async def, which is useful with async-compatible asset helpers:

image = None


@p5.preload
async def preload() -> None:
    global image
    image = await p5.load_image_async("sprite.png")

What You Can Make

  • 2D drawings with shapes, curves, color, transforms, and blend modes.
  • Animated sketches using the familiar setup() and draw() lifecycle.
  • Decorator-based sketches, async-compatible callbacks, and object-oriented Sketch subclasses.
  • Image and pixel experiments, including canvas export.
  • Text, font measurement, and accessibility descriptions.
  • Interactive sketches with mouse, keyboard, and touch state when native window support is available.
  • WEBGL-style 3D sketches with primitives, lights, materials, models, textures, and shader objects on the current Rust-backed software 3D path.
  • Small games and visual toys using the examples as starting points.

Loaded images keep their Rust-managed asset until you mutate pixels, so normal load_image(); image(...) sprite drawing can stay on the fast renderer path. Image-local resize, mask, filter, crop/copy, and alpha compositing delegate bulk byte work to the Rust canvas extension while keeping the Python Image API and version semantics. For pixel effects, load_pixels() keeps the compatibility list API and load_pixel_bytes() provides a bytes readback path; update_pixels() accepts lists and buffer-like inputs such as bytes, bytearray, and memoryview. Small canvas get() and set() region operations use Rust region calls where possible instead of reconstructing the full canvas as a Python image. For dense drawing loops, p5.fast() returns a frame-local facade that keeps public style/transform state while reducing global-mode dispatch overhead. Opt-in enable_performance_diagnostics() counters can identify readback, pixel conversion, upload, texture cache, and CPU compositing fallback paths.

Learn More

For Contributors

This repository uses uv for Python commands:

uv sync --dev
uv run ruff check .
uv run mypy src
uv run pytest

The canvas runtime is a required PyO3 extension:

uvx maturin develop --manifest-path crates/p5_canvas/Cargo.toml --module-name p5.rust._canvas --python-source src --features extension-module

The contributor documentation explains the architecture, lifecycle, testing workflow, and release shape in more detail:

Performance benchmarks are opt-in:

uv run pytest tests/benchmark/test_canvas_backend_perf.py --run-benchmarks
uv run pytest tests/benchmark/test_api_overhead_perf.py --run-benchmarks
uv run pytest tests/benchmark/test_image_pipeline_perf.py --run-benchmarks
uv run pytest tests/benchmark/test_webgl_3d_perf.py --run-benchmarks

Canvas benchmark scenarios are expected to average at least 120 FPS. Failures below that floor are intentional optimization signals. Machine-specific baseline snapshots live in tests/benchmark/baselines/.

Long-running resource lifecycle checks are also opt-in:

uv run pytest tests/stress --run-stress -q -s

Compatibility

p5py is inspired by p5.js, but it is not a browser port. It does not include DOM helpers, browser-only APIs, JavaScript aliases, or a Pillow/Pyglet fallback. Unsupported features raise explicit package errors so sketches fail clearly.

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.4.0.tar.gz (156.1 kB view details)

Uploaded Source

Built Distributions

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

p5py_vibe-0.4.0-cp312-cp312-win_amd64.whl (2.9 MB view details)

Uploaded CPython 3.12Windows x86-64

p5py_vibe-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

p5py_vibe-0.4.0-cp312-cp312-macosx_11_0_arm64.whl (2.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

p5py_vibe-0.4.0-cp312-cp312-macosx_10_12_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: p5py_vibe-0.4.0.tar.gz
  • Upload date:
  • Size: 156.1 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.4.0.tar.gz
Algorithm Hash digest
SHA256 f3e5c9f82dc25390046582df56cb3091781dc19ebba5e333a7ef7534501c4ee7
MD5 821406dfc097aa8c34c1cf2a008f470a
BLAKE2b-256 d97cd2e132c9efa223680eba790f1b9a099a171fc905d66a7711bb20df8ff040

See more details on using hashes here.

Provenance

The following attestation bundles were made for p5py_vibe-0.4.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.4.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: p5py_vibe-0.4.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for p5py_vibe-0.4.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2d5288cd420fbdd8f68a49ec04864a46a7b572df4a6c5e0b9cc798b74fb68906
MD5 f0442d5c11240d6315b7c286a465349b
BLAKE2b-256 d98323cabedff033a2c40a8a8a6470a1c137ddcc16056df99a1e83917e89a948

See more details on using hashes here.

Provenance

The following attestation bundles were made for p5py_vibe-0.4.0-cp312-cp312-win_amd64.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.

File details

Details for the file p5py_vibe-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for p5py_vibe-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 72d3a1cbe85b25c23430555f8901f3165c17391e90150f51c44c5ed0058c6fc4
MD5 1b9dc590ed51e40a0d8de929586ba8a8
BLAKE2b-256 0e7a392691894a6dd6d4574f58a03338a8c1a81a092930258d567a61fc1096ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for p5py_vibe-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.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.

File details

Details for the file p5py_vibe-0.4.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for p5py_vibe-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2646d88963eb7f3a24b5589d81026705252f08c44580ea3f1b57a0fd678ca84a
MD5 8b70bceda2fc7b72b3d9a74d568360ac
BLAKE2b-256 6ffcf869f85b2f74e2ea941ab4bf929e4a27b206acd7597068cfca46ea0abdb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for p5py_vibe-0.4.0-cp312-cp312-macosx_11_0_arm64.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.

File details

Details for the file p5py_vibe-0.4.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for p5py_vibe-0.4.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8bad2588962575500242736b5ba6c7777e308062550941712a853adaaab06076
MD5 e133c9482dd931603f8b09766ddcabf5
BLAKE2b-256 620f64391000b648d27eb5c6f4ef4a81b9896ea528fda8b33e239e0c121efff3

See more details on using hashes here.

Provenance

The following attestation bundles were made for p5py_vibe-0.4.0-cp312-cp312-macosx_10_12_x86_64.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