8000 Added donkey export decription · danyeaw/pyscript-docs@f16f917 · GitHub
[go: up one dir, main page]

Skip to content

Commit f16f917

Browse files
committed
Added donkey export decription
1 parent 9943caf commit f16f917

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/api.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,33 @@ store = await storage("my-data-store", storage_class=MyStorage)
417417
# The store object is now an instance of MyStorage.
418418
```
419419

420+
### `@pyscript/core/donkey`
421+
422+
Meant as *JS* related imports, you can `import { donkey } from '@pyscript/core/dist/core.js'` and automatically have both *pyscript* module running on your page and a utility to bootstrap a terminal based worker that could evaluate any Python code you need to.
423+
424+
```js title="A donkey worker"
425+
import { donkey } from '@pyscript/core/dist/core.js';
426+
427+
const {
428+
process, // process(code) directly (code visible on the terminal)
429+
execute, // execute(statement) in Python exec way
430+
evaluate, // evaluate(expression) in Python eval way
431+
clear, // clear() the terminal
432+
reset, // reset() the terminal (including colors)
433+
kill, // kill() the worker forever
434+
} = donkey({
435+
type: 'py' || 'mpy', // the donkey interpreter to run
436+
persistent: false, // use `true` to track globals and locals
437+
terminal: '', // optionally set a target terminal container
438+
config: {}, // the worker config (packages, files, etc.)
439+
});
440+
```
441+
442+
About the **terminal** option, please note by default *PyScript* would create a target for that, so that if you don't want it visible on your page you can point to a *CSS* addressable container that is not visible (that is: a `#target` element that has a `display: none` as *CSS* property).
443+
444+
With this primitive, and without even bothering with specialized *PyScript* tags, we hope anyone can try out of the box what is that *PyScript* enables on the Web!
445+
446+
420447
### `@pyscript/core/dist/storage.js`
421448

422449
The equivalent functionality based on the *JS* module can be found through our module.

0 commit comments

Comments
 (0)
0