Skip to content

Commit cfdd81d

Browse files
committed
Add m/py:progress events description
1 parent 82e2c2d commit cfdd81d

File tree

2 files changed

+62
-46
lines changed

2 files changed

+62
-46
lines changed

docs/api.md

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,52 @@ The following code demonstrates a `pyscript.WebSocket` in action.
766766
ws = WebSocket(url="ws://example.com/socket", onmessage=onmessage)
767767
```
768768

769+
### `pyscript.js_import`
770+
771+
If a JavaScript module is only needed under certain circumstances, we provide
772+
an asynchronous way to import packages that were not originally referenced in
773+
your configuration.
774+
775+
```html title="A pyscript.js_import example."
776+
<script type="py">
777+
from pyscript import js_import, window
778+
779+
escaper, = await js_import("https://esm.run/html-escaper")
780+
781+
window.console.log(escaper)
782+
```
783+
784+
The `js_import` call returns an asynchronous tuple containing the JavaScript
785+
modules referenced as string arguments.
786+
787+
### `pyscript.py_import`
788+
789+
!!! warning
790+
791+
**This is an experimental feature.**
792+
793+
Feedback and bug reports are welcome!
794+
795+
If you have a lot of Python packages referenced in your configuration, startup
796+
performance may be degraded as these are downloaded.
797+
798+
If a Python package is only needed under certain circumstances, we provide an
799+
asynchronous way to import packages that were not originally referenced in your
800+
configuration.
801+
802+
```html title="A pyscript.py_import example."
803+
<script type="py">
804+
from pyscript import py_import
805+
806+
matplotlib, regex, = await py_import("matplotlib", "regex")
807+
808+
print(matplotlib, regex)
809+
</script>
810+
```
811+
812+
The `py_import` call returns an asynchronous tuple containing the Python
813+
modules provided by the packages referenced as string arguments.
814+
769815
## Main-thread only features
770816

771817
### `pyscript.PyWorker`
@@ -863,52 +909,6 @@ for el in document.querySelectorAll("[type='py'][worker][name]"):
863909

864910
## Worker only features
865911

866-
### `pyscript.js_import`
867-
868-
If a JavaScript module is only needed under certain circumstances, we provide
869-
an asynchronous way to import packages that were not originally referenced in
870-
your configuration.
871-
872-
```html title="A pyscript.js_import example."
873-
<script type="py">
874-
from pyscript import js_import, window
875-
876-
escaper, = await js_import("https://esm.run/html-escaper")
877-
878-
window.console.log(escaper)
879-
```
880-
881-
The `js_import` call returns an asynchronous tuple containing the JavaScript
882-
modules referenced as string arguments.
883-
884-
### `pyscript.py_import`
885-
886-
!!! warning
887-
888-
**This is an experimental feature.**
889-
890-
Feedback and bug reports are welcome!
891-
892-
If you have a lot of Python packages referenced in your configuration, startup
893-
performance may be degraded as these are downloaded.
894-
895-
If a Python package is only needed under certain circumstances, we provide an
896-
asynchronous way to import packages that were not originally referenced in your
897-
configuration.
898-
899-
```html title="A pyscript.py_import example."
900-
<script type="py">
901-
from pyscript import py_import
902-
903-
matplotlib, regex, = await py_import("matplotlib", "regex")
904-
905-
print(matplotlib, regex)
906-
</script>
907-
```
908-
909-
The `py_import` call returns an asynchronous tuple containing the Python
910-
modules provided by the packages referenced as string arguments.
911-
912912
### `pyscript.sync`
913913

914914
A function used to pass serializable data from workers to the main thread.

docs/faq.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,22 @@ done"` message is written to the browser's console.
682682
</script>
683683
```
684684

685+
#### m/py:progress
686+
687+
The `py:progress` or `mpy:progress` event triggers on the main thread *during* interpreter bootstrap, being this either on *main* or *worker*.
688+
689+
Following previous work around progress events from *micropip*, the received `event.detail` will be a string that confine operations between `Loading {what}` and `Loaded {what}`, where the first event would hence be `Loading Pyodide` and the last one per each bootstrap would be `Loaded Pyodide`.
690+
691+
In between all operations will be forwarded as `event.detail`, such as:
692+
693+
* `Loading files` and `Loaded files`, when `[files]` is found in the optional config
694+
* `Loading fetch` and `Loaded fetch`, when `[fetch]` is found in the optional config
695+
* `Loading JS modules` and `Loaded JS modules`, when `[js_modules.main]` or `[js_modules.worker]`
696+
is found in the optional config
697+
* finally, all optional packages handled via *micropip* or *mip* will also trigger various `Loading ...` and `Loaded ...` events so that users can actually see what is going on while the *app* is bootstrapping
698+
699+
An example of this listener applied to a dialog cna be found in here: https://agiammarchi.pyscriptapps.com/kmeans-in-panel-copy/v1/
700+
685701
### Packaging pointers
686702

687703
Applications need third party packages and [PyScript can be configured to

0 commit comments

Comments
 (0)