py5 is a new version of [Processing][processing] for Python 3.8+. The goal of py5 is to create a version of Processing that is integrated into the Python ecosystem. Built into the library are thoughtful choices about how to best get py5 to work with other popular Python libraries and tools such as Jupyter, numpy, shapely, trimesh, matplotlib, and Pillow.
py5 is an excellent choice for educators looking to teach Python in the context of creative coding and is currently used in classrooms all around the world. This website's documentation includes introductory tutorials as well as extensive reference documentation, complete with example code.
Here is a basic example of a py5 Sketch:
def setup():
size(400, 400)
rect_mode(CENTER)
def draw():
square(mouse_x, mouse_y, 10)
def mouse_clicked():
fill(random_int(255), random_int(255), random_int(255))
run_sketch()
Here is an animated GIF to give you an idea of what that Sketch looks like:
But don't settle for an animated GIF! Use the rocket ship icon at the top of
this page to run the example on Binder, or better yet, use Live Code with Thebe
(Thebe is somewhat experimental and does not always work). Then you will be able
to create a Sketch Portal and see the
running Sketch embedded right in this page. You'll even be able click on the
Sketch Portal to trigger the mouse_clicked()
event. The Sketch Portal accepts
all of py5's keyboard and mouse events. It is fully interactive!
py5_tools.sketch_portal()
The ability to embed a py5 Sketch in a html page like this is one of the many ways py5 leverages the power of Jupyter Notebooks and is well integrated into the Python ecosystem.
If you have Java 17 installed on your computer, you can install py5 using pip:
pip install py5
Detailed installation instructions are available on this website. There are some Special Notes for Mac Users that you should read if you use macOS.
If you are new to Python, start with the /tutorials/intro_to_py5_and_python tutorials. If you are familiar with Java programming and Processing, you'll find the /content/coming_from_processing_java page to be helpful.
There are currently five basic ways to use py5. They are:
setup()
and draw()
functions that call methods provided by the py5
library.py5.Sketch
. This mode supports multiple Sketches running at the same time.py5.
prefix. This mode is supported by the py5 Jupyter notebook kernel and the run_sketch
command line utility. The above example is created in imported mode.%%py5bot
IPython magic, and the run_sketch
command line utility.callPython()
method.py5 was created by the artist and software developer Jim Schmitz (@hx2A) starting in March of 2020. The library is the foundation of his art practice.
The py5 library makes the Java Processing jars available to the CPython interpreter using JPype. It can do just about everything Processing can do, except with Python instead of Java code. New py5 features and bug fixes are being added to py5 every day. The library is always in active development and is well maintained.
To view the actual installed py5 library code, look at the py5 repository. The py5 library code is the output of the meta-programming project py5generator. All py5 development is done through py5generator.
py5 is not an official part of the Processing Foundation and is not receiving any funding from them. Any funds you contribute will be used first for website expenses and next to support @hx2A's time to further develop py5 as a solid creative coding framework used by educators, artists, and hobbyists all around the world.
Have a comment or question about py5? We'd love to hear from you! The best ways to reach out are: