Skip to content

Commit 7d5fa2b

Browse files
authored
Merge pull request #139 from pyscript/2024-09-01
Update to docs for the 2024.9.1 release.
2 parents 82e2c2d + 9a75798 commit 7d5fa2b

File tree

8 files changed

+96
-65
lines changed

8 files changed

+96
-65
lines changed

docs/api.md

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ store = await storage("my-data-store", storage_class=MyStorage)
409409
# The store object is now an instance of MyStorage.
410410
```
411411

412+
### `@pyscript/core/dist/storage.js`
413+
414+
The equivalent functionality based on the *JS* module can be found through our module.
415+
416+
The goal is to be able to share the same database across different worlds (interpreters) and the functionality is nearly identical except there is no *class* to provide because the storage in *JS* is just a dictionary proxy that synchronizes behind the scene all read, write or delete operations.
417+
412418
### `pyscript.web`
413419

414420
The classes and references in this namespace provide a Pythonic way to interact
@@ -766,6 +772,52 @@ The following code demonstrates a `pyscript.WebSocket` in action.
766772
ws = WebSocket(url="ws://example.com/socket", onmessage=onmessage)
767773
```
768774

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

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

864916
## Worker only features
865917

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-
912918
### `pyscript.sync`
913919

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

docs/beginning-pyscript.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ module in the document's `<head>` tag:
117117
<meta charset="utf-8" />
118118
<meta name="viewport" content="width=device-width,initial-scale=1" />
119119
<title>🦜 Polyglot - Piratical PyScript</title>
120-
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.2/core.css">
121-
<script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
120+
<link rel="stylesheet" href="https://pyscript.net/releases/2024.9.1/core.css">
121+
<script type="module" src="https://pyscript.net/releases/2024.9.1/core.js"></script>
122122
</head>
123123
<body>
124124

@@ -168,8 +168,8 @@ In the end, our HTML should look like this:
168168
<meta charset="utf-8" />
169169
<meta name="viewport" content="width=device-width,initial-scale=1" />
170170
<title>🦜 Polyglot - Piratical PyScript</title>
171-
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.2/core.css">
172-
<script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
171+
<link rel="stylesheet" href="https://pyscript.net/releases/2024.9.1/core.css">
172+
<script type="module" src="https://pyscript.net/releases/2024.9.1/core.js"></script>
173173
</head>
174174
<body>
175175
<h1>Polyglot 🦜 💬 🇬🇧 ➡️ 🏴‍☠️</h1>

docs/faq.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,31 @@ 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*
688+
interpreter bootstrap (no matter if your code is running on main or in a
689+
worker).
690+
691+
The received `event.detail` is a string that indicates operations between
692+
`Loading {what}` and `Loaded {what}`. So, the first event would be, for
693+
example, `Loading Pyodide` and the last one per each bootstrap would be
694+
`Loaded Pyodide`.
695+
696+
In between all operations are `event.detail`s, such as:
697+
698+
* `Loading files` and `Loaded files`, when `[files]` is found in the optional
699+
config
700+
* `Loading fetch` and `Loaded fetch`, when `[fetch]` is found in the optional
701+
config
702+
* `Loading JS modules` and `Loaded JS modules`, when `[js_modules.main]` or
703+
`[js_modules.worker]` is found in the optional config
704+
* finally, all optional packages handled via *micropip* or *mip* will also
705+
trigger various `Loading ...` and `Loaded ...` events so that users can see
706+
what is going on while PyScript is bootstrapping
707+
708+
An example of this listener applied to a dialog can be [found in here](https://agiammarchi.pyscriptapps.com/kmeans-in-panel-copy/v1/).
709+
685710
### Packaging pointers
686711

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

docs/user-guide/first-steps.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ CSS:
2020
<meta charset="UTF-8">
2121
<meta name="viewport" content="width=device-width,initial-scale=1.0">
2222
<!-- PyScript CSS -->
23-
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.2/core.css">
23+
<link rel="stylesheet" href="https://pyscript.net/releases/2024.9.1/core.css">
2424
<!-- This script tag bootstraps PyScript -->
25-
<script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
25+
<script type="module" src="https://pyscript.net/releases/2024.9.1/core.js"></script>
2626
</head>
2727
<body>
2828
<!-- your code goes here... -->

docs/user-guide/offline.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ cd pyscript-offline
4040
Build PyScript core by cloning the project repository and follow the
4141
instructions in our [developer guide](../developers.md)
4242

43-
Once completed, copy the `build` folder, that was been created by the build
43+
Once completed, copy the `dist` folder, that has been created by the build
4444
step, into your `pyscript-offline` folder.
4545

4646
### PyScript core from `npm`
@@ -114,7 +114,7 @@ python3 -m http.server -d ./public/
114114
If you would like to test `worker` features, try instead:
115115

116116
```sh
117-
npx static-handler --coi ./public/
117+
npx mini-coi ./public/
118118
```
119119

120120
## Download a local interpreter
@@ -231,7 +231,7 @@ Finally, we need the ability to install Python packages from a local source
231231
when using Pyodide.
232232

233233
Put simply, we use the packages bundle from
234-
[pyodide releases](https://github.com/pyodide/pyodide/releases/tag/0.24.1).
234+
[pyodide releases](https://github.com/pyodide/pyodide/releases/tag/0.26.2).
235235

236236
!!! warning
237237

@@ -240,8 +240,8 @@ Put simply, we use the packages bundle from
240240
It contains each package that is required by Pyodide, and Pyodide will only
241241
load packages when needed.
242242

243-
Once downloaded and extracted (we're using version `0.24.1` in this example),
244-
we can simply copy the files and folders inside the `pyodide-0.24.1/pyodide/*`
243+
Once downloaded and extracted (we're using version `0.26.2` in this example),
244+
we can simply copy the files and folders inside the `pyodide-0.26.2/pyodide/*`
245245
directory into our `./public/pyodide/*` folder.
246246

247247
Feel free to either skip or replace the content, or even directly move the

docs/user-guide/plugins.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ For example, this will work because all references are contained within the
100100
registered function:
101101

102102
```js
103-
import { hooks } from "https://pyscript.net/releases/2024.8.2/core.js";
103+
import { hooks } from "https://pyscript.net/releases/2024.9.1/core.js";
104104

105105
hooks.worker.onReady.add(() => {
106106
// NOT suggested, just an example!
@@ -114,7 +114,7 @@ hooks.worker.onReady.add(() => {
114114
However, due to the outer reference to the variable `i`, this will fail:
115115

116116
```js
117-
import { hooks } from "https://pyscript.net/releases/2024.8.2/core.js";
117+
import { hooks } from "https://pyscript.net/releases/2024.9.1/core.js";
118118

119119
// NO NO NO NO NO! ☠️
120120
let i = 0;
@@ -147,7 +147,7 @@ the page.
147147

148148
```js title="log.js - a plugin that simply logs to the console."
149149
// import the hooks from PyScript first...
150-
import { hooks } from "https://pyscript.net/releases/2024.8.2/core.js";
150+
import { hooks } from "https://pyscript.net/releases/2024.9.1/core.js";
151151

152152
// The `hooks.main` attribute defines plugins that run on the main thread.
153153
hooks.main.onReady.add((wrap, element) => {
@@ -197,8 +197,8 @@ hooks.worker.onAfterRun.add(() => {
197197
<!-- JS plugins should be available before PyScript bootstraps -->
198198
<script type="module" src="./log.js"></script>
199199
<!-- PyScript -->
200-
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.2/core.css">
201-
<script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
200+
<link rel="stylesheet" href="https://pyscript.net/releases/2024.9.1/core.css">
201+
<script type="module" src="https://pyscript.net/releases/2024.9.1/core.js"></script>
202202
</head>
203203
<body>
204204
<script type="mpy">

docs/user-guide/workers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ Here's how:
282282
<meta charset="utf-8">
283283
<meta name="viewport" content="width=device-width,initial-scale=1">
284284
<!-- PyScript CSS -->
285-
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.2/core.css">
285+
<link rel="stylesheet" href="https://pyscript.net/releases/2024.9.1/core.css">
286286
<!-- This script tag bootstraps PyScript -->
287-
<script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
287+
<script type="module" src="https://pyscript.net/releases/2024.9.1/core.js"></script>
288288
<title>PyWorker - mpy bootstrapping pyodide example</title>
289289
<script type="mpy" src="main.py"></script>
290290
</head>

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "2024.8.2"
2+
"version": "2024.9.1"
33
}

0 commit comments

Comments
 (0)