- Notifications
You must be signed in to change notification settings - Fork1.5k
-
In yesterday's community call we discussed the names in and structure of the API we provide in the We feel it essential that we have community engagement in this process... so we have a fun challenge for you.Yes folks, it's the Great Pythonic API BakeOff, and you really will want to take part! ;-) "How?", I hear you ask... well, my friend, it's easy... and it bears absolutely no resemblance to a famous cooking programme we like, but we had to think of something to grab your attention:
We'll collate the (reasonable and sensible :-P) responses we get and, sometime in September, share a "first draft" based upon the results. From this draft we hope to engage further with the community to make sure we have the most polished API possible. Then we'll ship it. The existing browser APIs are, how can we put it?, colourful in their diversity. We're looking for names that are easy to understand, a structure that is rational and understandable and ways of working that are consistent (for example, any asynchronous APIs are always awaited in Python). For example, modern browsers include speech recognition (https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition) and text to speech (https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis). We could expose them in PyScript like this: frompyscript.speechimportlisten,say,set_voiceuser_says=awaitlisten()print("You said: ",user_says)set_voice("barry")say(user_says) Clearly, in this example the intention is only to reveal the simplest / most common use cases. Bonus points for including "escape hatches" to more advanced / lower level APIs closer to the browser's own implementations. Folks who have contributed to the final API that we eventually ship get their name immortalised in our release notes! :-) So... Ready? Set? Bake! |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 9 comments 11 replies
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I tried to reorganize the namespace and the following reasons well to me:
|
BetaWas this translation helpful?Give feedback.
All reactions
-
Not sure if this is the kind of input you are looking for: Beacons beacon api
E.g. frompywebimportbeaconBeacon=beacon("url")# possibly define if sending txt or application/x-www-form-urlencodedbeacon_data= {"events":[]}defaction(event):globalbeacon_databeacon_data['events'].append("action")defsend_beacon()globalbeacon_dataBeacon.send(beacon_data)forbinbeacon_data:beacon_data[b]= [] Note:
|
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
One of the most important api's, for me, is the File System API To implement this we need to differentiate between:
There are also synchronous (e.g 'file.write()`) and async reader writer (e.g. blob, string, buffer) functions available. The synchronous ones are much faster on OPFS files and code could be easily migrated from traditional python style to operate on OPFS files efficiently. frompyscriptimportpyfsapiasfsactual_inf=fs.choose_local_file(filettype=[".png",".gif",".jpeg",".jpg"])# shadowing Window.showOpenFilePicker()in_file=fs.copy_opfs(actual_inf)# in_file is now on the OPFS for faster access# usual file access python code stylewithopen(in_file)asinf: ...# finished with file accessfs.save_opfs_to_local(in_file,actual_inf)# saved the OPFS file back to the local filesystem It would be nice if there was a recipe/example which showed how to use a Worker to get the file and proxy it for you. And if this worker also had an option to clean up the OPFS file when it terminated (defaulting to True). So cleanup and exceptions for file not found were handled... |
BetaWas this translation helpful?Give feedback.
All reactions
-
Chiming in explicitly, even if we discussed this in a couple of community calls already... I think@WebReflection comment above captures most of my preferences (as well as@mchilvers , iirc). A couple of small comments on the specifics though:
I do think we need to think about the future, when we add more simplified and pythonic versions of these APIs, to make access easier. For instance, what's in |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
not only that, I don't see any need for breaking anything we have right now ... I just did a round of "examples update" and every time we touch our namespace alot of stuff breaks or need updates and if that's true for ourselves, it's even more true for anyone trusting this project in amature enough state to build up next things ... and I fully agree with that statement, as moving around APIs (aka: shuffling cards of the same deck) doesn't help anyone to date and doesn't help us keeping docs and examples or internal state updated with greater ease, which is (imho) important. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hi Folks, With all the work on
Most fall under option two. Those under option one have already been created elsewhere, or they're of fundamental importance. Those labelled with option three are simply "nice to have". Please don't hesitate to suggest more, or suggest changes to the API priority.
Assuming we're more-or-less aligned with attempting to create Pythonic versions of the capabilities listed above, our next task is to agree on the "pattern" of the API. For instance, in what consistent manner would we report certain capabilities are not available to users? How might these capabilities be organised into an easy-to-comprehend API taxonomy (see@WebReflection's suggestions)? Are there "refined" capabilities we may wish to reveal (for example, to turn on the phone's light, you'd have to use the Media API to access the camera to turn it on and off... a long winded process that we could hide in a As always folks, thoughts, constructive feedback and creative ideas are most welcome..! 🤗 |
BetaWas this translation helpful?Give feedback.
All reactions
-
+1 on the proposal. I think the path we took with |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Hi It's not in the list, I only saw WEBSERIAL Thanks in advance |
BetaWas this translation helpful?Give feedback.
All reactions
-
Hi Folks, Following on from my earlier API list, here's a first stab at how the built-in APIs might line up in a As usual, this is a straw-man / first draft just so we're able to work out what we really want. NOTE Not all the features from the underlying web APIs may be made available... just the most fun/common/easy to use. Should folks require the "advanced" stuff, they can always work directly with the JavaScript APIs via our FFI. The details of such features can be figured out as we implement them. The point of this comment is to get us in the same ball park when it comes to the features / shape / naming of the API. It is important to remember, when it comes to the First off, what about our existing API..? Anything not explicitly referenced below remains the same. However, I really like some of@WebReflection's suggestions:
I also think a bunch of stuff could find themselves in the
I've already discussed this with@mchilvers - but Some of the existing functionality could be moved into a
Given the recent work in#2239 the
This leaves the following aspects of the existing API as-is:
These feel to me (note the use of "feel" - this is an aesthetic judgement), like they're already in the right place because they're of their fundamental nature. Even if we move things around as described above, as part of the transition to the new API, we could alias alias things so they appear in the old location for a few released while folks move over. And so, we get to those aspects of the API that are dependent on whether the context is on the main thread or on a worker. I suggest simply calling a spade, "a spade" as the saying goes:
Finally, there are aspects of our API that are not revealed in our docs, or are for internal use only. Following Python conventions, these should be renamed to start with an underscore:
And so we come to the new API, drafted in the table below. The "done" column is a RAG status 🔴 🟡 🟢 and the issue# can be filled in as we create tickets/PRs for each feature. Of course, THIS IS A DRAFT / STRAW MAN for discussion purposes. A note on naming: Some of the APIs have their own top level in the API. I "feel" these are fundamental or the name fits. The
All feedback, creative ideas and constructive criticism most welcome..! |
BetaWas this translation helpful?Give feedback.
All reactions
-
Hey hey.@WebReflection thanks for the feedback. 👍 on a dedicated call, and how this is a big subject. How about Wednesday for that? Just so we have a chance to at least show / discuss this in front of the community on Tuesday, and folks will know when the call will be..? I suggest we replace the community engagement call with a technical call about the API refactor? Thoughts..? WRT plurals and |
BetaWas this translation helpful?Give feedback.
All reactions
-
I think I am OK with that, except I don't think any discussion should be made tomorrow around it, just a hint/notice we're going to discuss that in depth, so that such community can have a chance to read, digest, and eventually show up the day after with thoughts and/or hints. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Also food for thoughts (maybe) ... there's no difference in JS between imports and modules, imports are modules, that's it ... you import something once? every other import would be the same forever: importsare modules, so that second line really makes little sense to me right now. |
BetaWas this translation helpful?Give feedback.
All reactions
-
👍 Agreed (notice of the discussion on Wednesday in the Tuesday meeting). Also, the JS naming conventions (imports/modules etc)... that's why we have discussions like this: to make sure it all makes sense. Like I said this ^^^ is just an initial brain-dump / first draft. We MUST refine it. 😉 |
BetaWas this translation helpful?Give feedback.
All reactions
-
Sure thing, if I could get an understanding of the meaning of
That's it from me (around this initial topic), looking forward to the deeper discussion around the rest of it! |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Looks good! I do wonder where things like the camera should go though? Is the playback/display of images/video/sound different to the recording of them? ie. pyscript.device.camera for recording videao/taking pictures? Not sure where the mic would live? pyscript.device.mic? The device then starts to feel cumbersome.... We could flatten even more and pull the device namespace out? pyscript.sensors etc.... Just some early morning ramblings.... |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Yeah... I hear ya! I had a bit of a ponder about that... I started with a Anyway, I hope this explanation of my thought pattern that led to my naming makes sense. As always, I'm happy to change things around and discuss better ways to modelling this. The whole point of this comment isn't for me to say "that's how it is", rather, "it's a start, let's refine". 👍 |
BetaWas this translation helpful?Give feedback.
All reactions
-
My summary for today meeting: About pyscript.js VS pyscript.pyUnless we have extremely specific use cases I don't think having a dedicated namespace would help. About pyscript.utilsI don't have any thought on those but most suggestions are there fromlegacy. About Eventspyscript.events.whenpyscript.events.Event I am OK with About most common used thingspyscript.configpyscript.documentpyscript.ffi.*pyscript.storagepyscript.window It would be the third time we change the world ... meaning:
I am looking at the latter point: is this really fair for our users? Should we alias/deprecate whatever is in already somehow instead? About main/worker ideapyscript.main.PyWorkerpyscript.main.workerspyscript.worker.sync There is no My concern here is that we make the initial idea of workers, which was seamlessly portable code, beside Are we moving away from that initial idea? About dunder exportsI belkieved that was a Python convention so I wonder why we should care. About the table
|
BetaWas this translation helpful?Give feedback.
All reactions
-
+1 on most of the above here but I have a question and a few comments... Question:@WebReflection , a lot of your comments seemed to indicate more work than just bringing these APIs, 1:1, to the python/pyscript layer. My understanding of where we aligned, was that for the most part, we are not looking at adding much work than just a 1:1 layer. The additional work to provide a Pythonic API on top of(or in addition to) that is going to be for a future phase. Comments: I does seem like we could trim some of that list down and wait on some of them to be requested. The deprecated ones are an easy pick, but also the ones that seem to be tricky and are likely less popular... we can probably wait.
+1 on
While I agree on keeping it YAGNI...... Given that most of these, at this stage, are going to be a thin layer API exposing the underlying JS api out of the box mostly dynamically, it shouldn't be that much work to add these... Given that, and the nature of some of these APIs, I'd rather just bite the bullet on this one (or on others, like battery for instance) because of the low cost of adding it. (Not strongly opposed to skip it for now though)
I think it's fine for me tbh.. |
BetaWas this translation helpful?Give feedback.
All reactions
-
This is just kind of a goofy idea but I thought it might be helpful. If my memory serve me correctly and if i understand things currently (2 BIG IF HERE) pyscript is bassed on a plug-in. I would think that each plugin could have a name and source you load the plugin from you could allow import it to whatever you want this way. This would be similar to the way you import Javascript esm module . I would have the plugin name followed by the import name you want. This would allow you test 2 version of the same plugin. |
BetaWas this translation helpful?Give feedback.