A Pythonic creative coding package inspired by p5.js.
Project description
p5py
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()anddraw()lifecycle. - Decorator-based sketches, async-compatible callbacks, and object-oriented
Sketchsubclasses. - 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:
- Contributor guide
- Architecture
- Runtime model
- Runtime diagnostics
- Build capabilities
- API performance policy
- Testing and CI
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3e5c9f82dc25390046582df56cb3091781dc19ebba5e333a7ef7534501c4ee7
|
|
| MD5 |
821406dfc097aa8c34c1cf2a008f470a
|
|
| BLAKE2b-256 |
d97cd2e132c9efa223680eba790f1b9a099a171fc905d66a7711bb20df8ff040
|
Provenance
The following attestation bundles were made for p5py_vibe-0.4.0.tar.gz:
Publisher:
publish.yml on JonathanHHenson/p5.py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
p5py_vibe-0.4.0.tar.gz -
Subject digest:
f3e5c9f82dc25390046582df56cb3091781dc19ebba5e333a7ef7534501c4ee7 - Sigstore transparency entry: 1882824522
- Sigstore integration time:
-
Permalink:
JonathanHHenson/p5.py@5885a5ca033220dac42532ba0164f1e2819e85f1 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/JonathanHHenson
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5885a5ca033220dac42532ba0164f1e2819e85f1 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d5288cd420fbdd8f68a49ec04864a46a7b572df4a6c5e0b9cc798b74fb68906
|
|
| MD5 |
f0442d5c11240d6315b7c286a465349b
|
|
| BLAKE2b-256 |
d98323cabedff033a2c40a8a8a6470a1c137ddcc16056df99a1e83917e89a948
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
p5py_vibe-0.4.0-cp312-cp312-win_amd64.whl -
Subject digest:
2d5288cd420fbdd8f68a49ec04864a46a7b572df4a6c5e0b9cc798b74fb68906 - Sigstore transparency entry: 1882825208
- Sigstore integration time:
-
Permalink:
JonathanHHenson/p5.py@5885a5ca033220dac42532ba0164f1e2819e85f1 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/JonathanHHenson
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5885a5ca033220dac42532ba0164f1e2819e85f1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file p5py_vibe-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: p5py_vibe-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72d3a1cbe85b25c23430555f8901f3165c17391e90150f51c44c5ed0058c6fc4
|
|
| MD5 |
1b9dc590ed51e40a0d8de929586ba8a8
|
|
| BLAKE2b-256 |
0e7a392691894a6dd6d4574f58a03338a8c1a81a092930258d567a61fc1096ae
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
p5py_vibe-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
72d3a1cbe85b25c23430555f8901f3165c17391e90150f51c44c5ed0058c6fc4 - Sigstore transparency entry: 1882824695
- Sigstore integration time:
-
Permalink:
JonathanHHenson/p5.py@5885a5ca033220dac42532ba0164f1e2819e85f1 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/JonathanHHenson
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5885a5ca033220dac42532ba0164f1e2819e85f1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file p5py_vibe-0.4.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: p5py_vibe-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2646d88963eb7f3a24b5589d81026705252f08c44580ea3f1b57a0fd678ca84a
|
|
| MD5 |
8b70bceda2fc7b72b3d9a74d568360ac
|
|
| BLAKE2b-256 |
6ffcf869f85b2f74e2ea941ab4bf929e4a27b206acd7597068cfca46ea0abdb8
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
p5py_vibe-0.4.0-cp312-cp312-macosx_11_0_arm64.whl -
Subject digest:
2646d88963eb7f3a24b5589d81026705252f08c44580ea3f1b57a0fd678ca84a - Sigstore transparency entry: 1882824860
- Sigstore integration time:
-
Permalink:
JonathanHHenson/p5.py@5885a5ca033220dac42532ba0164f1e2819e85f1 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/JonathanHHenson
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5885a5ca033220dac42532ba0164f1e2819e85f1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file p5py_vibe-0.4.0-cp312-cp312-macosx_10_12_x86_64.whl.
File metadata
- Download URL: p5py_vibe-0.4.0-cp312-cp312-macosx_10_12_x86_64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.12, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bad2588962575500242736b5ba6c7777e308062550941712a853adaaab06076
|
|
| MD5 |
e133c9482dd931603f8b09766ddcabf5
|
|
| BLAKE2b-256 |
620f64391000b648d27eb5c6f4ef4a81b9896ea528fda8b33e239e0c121efff3
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
p5py_vibe-0.4.0-cp312-cp312-macosx_10_12_x86_64.whl -
Subject digest:
8bad2588962575500242736b5ba6c7777e308062550941712a853adaaab06076 - Sigstore transparency entry: 1882825042
- Sigstore integration time:
-
Permalink:
JonathanHHenson/p5.py@5885a5ca033220dac42532ba0164f1e2819e85f1 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/JonathanHHenson
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5885a5ca033220dac42532ba0164f1e2819e85f1 -
Trigger Event:
push
-
Statement type: