GSOC 2019: pyp5js - Enable Python3 with p5.js

Hello from Brazil!

Me and Alexandre Villares have been talking for a while about how we could use Python 3 with Processing. Unfortunately, it seems we’re in a dead end when it comes to supporting Python 3 because of the Jython’s dependency. Jython doesn’t have a clear roadmap to support Python 3 and this Stackoverflow’s topic has a lot of links covering this issue.

So, we’ve started to think about other strategies and also to research some other Python explorations on integrations with Processing. Our main results were two projects, both from Professor Claudio Esperanca:

  • pyprocessing is a pure Python 2 implementation similar to Processing’s API;
  • Brythonide provides an online editor to write Python code integrated with p5.js using the Brython project under the hood.

Both of them are incredible projects, but hey didn’t fit our initial requirements. pyprocessing is still using Python 2, so it would require the effort of porting it to Python 3. But besides that, there are some API decisions that differs from’s one. For us, this was a deal breaker because the sketches we’ve been creating with maybe wouldn’t work and, also, we would have to stop using existing Processing’s documentation as our reference.

BrythonIDE, on the other hand, is a very useful tool but it has some drawbacks when it comes to performance. By comparing the frame rate with pure p5.js, we could notice that there’s some slowdowns. But BrythonIDE really opened our ideas to the possibility of integrating Python 3 with p5.js. But it’s definitely worthwhile to take a look at the project’s examples.

Following this path, we’ve started to think about and to develop pyp5js, a lib to “transcribe” Python 3 code to Javascript code integrated with p5.js. The lib is still under an alpha version, but we’re really excited about the progress so far!

We have some issues listed, but we feel that there’s a major one that would really help newcomers on programming to interact with p5.js using Python. We’d love to be able to encapsulate pyp5js as Processing mode or to create its own “live editor”. The issue covering this discussion is titled Encapsulate pyp5js as Processing Mode or perhaps as a Mu mode #41 and feedback or opinions on it would really help us on thinking solutions.



I had the same issue with and started work on a native Python 3 implementation of Processing around two years ago. Most of the development so far has happened during the Google Summer of Code as a project for the Processing Foundation. See the project reports from GSOC 2017, 2018 and some details of the 2019 project.

pyp5js certainly looks interesting, however, I had two questions:

  1. Is there any special reason you’re transcribing Python code into Javascript?
  2. Will users be able to use other Python libraries (say, numpy) with pyp5js?

Hi @abhikpal, thanks for your reply!

I’m familiar with your work with p5 and I’ve already even tested it. I really think it’s a very notable and promising work, although I don’t like with some of the code design decisions because they break existing Python mode sketches (for example the renamed methods from a camel case syntax to a more pythonic way). But, please, keep on with your work because I really think it’s very important to the Python community =]

About pyp5js, here are my thoughts:

1 - The reason is that Transcrypt was the best tool I was able to use for the job because of the reasons described in my previous comment. But I also think pyp5js had a different goal than p5py because I wanted to take a step further beyond writing sketches with Python code. My main goal was to share my sketches online with my friends and members of Brazil’s creative coding community. To do so, for now, I need to transcribe it to Javascript code. But I really think that, in a very close future, I won’t need this transcription anymore. More details about this in answer number 2.

2 - In the present, unfortunately, no. We can use only Python libs with JS compatible versions implemented by Transcrypt. But I don’t think pyp5js will rely on Transcrypt forever… There’s a lot of ongoing work on porting Python to the web, including the majority of its scientific stack, under the pyodide project. The project, supported by Mozilla, compiles the CPython to Webassembly giving us the ability to run pure Python code in the browser. I’m following the work closely because it’ll enable pyp5js not only to use all CPython libs, but also to directly manipulate all of the browsers APIs, including the DOM and the Canvas. This will open new paths on rewriting the pyp5js that I’m really interested on exploring.


1 Like

Out of interest, on the Processing on the JVM front, had you looked at the viability of a Py4J / JEP like approach, or even Graal Python?


No, I didn’t! Thanks for the links @neilcsmith

1 Like