# API compatibility for p5py

**URL:** <https://discourse.processing.org/t/api-compatibility-for-p5py/20492>\
**Category:** p5py\
**Created:** [May 4, 2020, 2:54pm UTC](https://discourse.processing.org/t/api-compatibility-for-p5py/20492 "2020-05-04T14:54:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [May 4, 2020, 2:54pm UTC](https://discourse.processing.org/t/api-compatibility-for-p5py/20492/1 "2020-05-04T14:54:34Z")

</div>

@tabreturn has posted a great tutorial on how to use [Thonny IDE](https://thonny.org) with [p5](https://github.com/p5py/p5) (also known as p5py) here: [Portable Thonny and p5](https://discourse.processing.org/t/portable-thonny-and-p5/19556)

I find the p5py maintainers decision to forgo any attempt at API compatibility with Py.Processing annoying. Sometimes I think about writing wrapper functions as a compatibility layer for it…

I put daily effort on didactic materials for my students using Processing Python mode and a huge body of examples, like Jeremy Douglass’ Rosetta Code collection, goes to waste if p5py succeeds (as I hope it will) and Python mode dwindles away (as I’m afraid it might).

So @jeremydouglass suggested we might want to discuss this idea/comment here 🙂

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 4, 2020, 4:29pm UTC](https://discourse.processing.org/t/api-compatibility-for-p5py/20492/2 "2020-05-04T16:29:21Z")

</div>

@villares – maybe make this new discussion? like “API compatibility for pyp5?”

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [May 5, 2020, 12:41am UTC](https://discourse.processing.org/t/api-compatibility-for-p5py/20492/3 "2020-05-05T00:41:20Z")

</div>

Where do you think would be best to talk about it?  
Here in `teaching` or under `Processing.py`?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 5, 2020, 3:50am UTC](https://discourse.processing.org/t/api-compatibility-for-p5py/20492/4 "2020-05-05T03:50:51Z")

</div>

I agree that the basic decision to make the p5py API as pythonic as possible (rather than as cross-compatible as possible) can create some problems. This is particularly difficult for new modes which have little documentation (so students are more likely to need to rely on examples from other modes, which use the different API). If learners are trying to adapt materials from other modes into the new mode, being different makes it harder.

That said, there can be some advantages to being as pythonic as possible. The core devs might have other audiences in mind, or see other advantages in a break with tradition–it might be worth asking. JRubyArt and Processing.R also embrace some aspects of their language that are very unlike the Java API.

I really like your idea for a wrapper / compatibility layer – it might be the best of both worlds. One that you could dynamically load or import might be even better than a fork. I’m thinking of a design along the lines of `from __future__ import print_function` – such as `from p5 import api`.

This might be a good conversation to have with the core devs.

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [May 5, 2020, 11:11am UTC](https://discourse.processing.org/t/api-compatibility-for-p5py/20492/5 "2020-05-05T11:11:02Z")

</div>

I feel like they are overwhelmed already by the task of building it, and my first impression of the maintainer was not very good:

> <https://github.com/p5py/p5/pull/46#discussion_r185139666>

But I guess It would be worth a try once we have a proof of concept.

More discussions going on here (with brilliant contribution by @GoToLoop as usual):

> <https://github.com/p5py/p5/issues/130>
>
> I searched the readme and the issues and couldn't find my question, i just found p5py and tried to transfer a...

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 5, 2020, 3:33pm UTC](https://discourse.processing.org/t/api-compatibility-for-p5py/20492/6 "2020-05-05T15:33:35Z")

</div>

Yes, it is mostly unfunded open source – being overwhelmed is pretty normal for beginners and vets alike.

Good idea about a proof of concept. I believe that Sam moved ahead with a P4 prototype by just developing a public fork – then it didn’t matter whether or not Ben had the bandwidth to review a branch on the main Processing repo – so that could also be a model. But sometimes it is nice to try to integrate or at least ask first before forking.

Maybe we could start with an API matching list? A lot of things are just changing underscores to 🐪 camelCase, right?

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [May 17, 2020, 11:54pm UTC](https://discourse.processing.org/t/api-compatibility-for-p5py/20492/7 "2020-05-17T23:54:31Z")

</div>

I should get started with the list, but I’m curious if y’all have suggestions on how to ‘inject’ into the namespace the wrapper functions 🙂

> <https://gist.github.com/villares/df72b47e8361cfe3bf1a471e3c5e7fbb>

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [September 19, 2020, 3:14am UTC](https://discourse.processing.org/t/api-compatibility-for-p5py/20492/8 "2020-09-19T03:14:14Z")

</div>

It looks like the tuple interface for positions ins now optional!  
So now we have a much easier job…

I started with the inputs. Help with implementation of the `import` mechanism would be appreciated.

```auto
 mouse_moved(): mouseMoved()
 mouse_pressed(): mousePressed()
 mouse_released(): mouseReleased()
 mouse_clicked(): mouseClicked()
 mouse_dragged(): mouseDragged()
 mouse_wheel(): mouseWheel()
 mouse_is_pressed: mouseIspressed # like p5js, but I would prefer mousePressed if possible
 mouse_is_dragging: mouseIsdragging # this is new, so I'm not sure
 mouse_button: mouseButton
 mouse_x: mouseX,
 mouse_y: mouseY
 pmouse_x: pmousey
 pmouse_y: pmouseY
 key_is_pressed: keyIspressed # same issue as mouseIsPressed/mousePressed
 key_pressed(): keyPressed()
 key_released(): keyReleased()
 key_typed(): keyTyped()

```

---

<div class="post-metadata">

**Author:** ![parsoyaarihant](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/parsoyaarihant/32/10581_2.png) [@parsoyaarihant](https://discourse.processing.org/u/parsoyaarihant)\
**Post date:** [September 19, 2020, 3:59am UTC](https://discourse.processing.org/t/api-compatibility-for-p5py/20492/9 "2020-09-19T03:59:47Z")

</div>

Hi @villares. I have opened an issue in p5py for this:

> <https://github.com/p5py/p5/issues/280>
>
> https://discourse.processing.org/t/api-compatibility-for-p5py/20492
> Its possible for p5py to support both APIs of p5py and Processing by simply copying existing functions into new objects with...

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [September 19, 2020, 4:18am UTC](https://discourse.processing.org/t/api-compatibility-for-p5py/20492/10 "2020-09-19T04:18:37Z")

</div>

I’ve just noticed this works too:

```auto
    ...
    push_matrix()
    translate(100, 100)
    circle(0, 0, 50)
    pop_matrix()

```

If I recall correctly, it was only `with push_matrix():` before? Nice! I’m thinking this will make p5py --\> pyp5js easier (for running Python sketches in web browsers) 😃

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [September 19, 2020, 11:39am UTC](https://discourse.processing.org/t/api-compatibility-for-p5py/20492/11 "2020-09-19T11:39:33Z")

</div>

> [@parsoyaarihant](#):
>
> I have opened an issue in p5py for this

I cant’t thank you enough!
