A web based Python console powered by Pyodide and ImJoy. It allows you to run Python code in the browser, and you can also directly execute code / python file from URL.
Online demo:
- Run Python code in browser
- Directly execute code / python file from URL
- Better Matplotlib support
- Integrate with ImJoy ecosystem
- Control by ImJoy plugins
- Control other ImJoy plugins
- Editor with Python syntax highlighting.
- Support mounting native file system to the console.
This project is a fork of Pyodide's console.
code
: the Python code to be executedfile
: the URL of the Python file to be executedshow_code
: whether to show the code in console, default istrue
install_rpc
: whether to install theimjoy-rpc
package, default istrue
- Sin(x) curve ASCII
- matplotlib
- altair
- ImageJ.JS
- Bioengine
- Run deep learning models in the BioImage.IO through the Bioengine.
The console is integrated with ImJoy, you can use the ImJoy API to control the console.
API | Description | Parameters |
---|---|---|
.echo |
Print a message to the console | msg: string |
.clear |
Clear the console | |
.exec |
Execute Python code | code: string; show_code: bool = true |
.restart |
Restart the console | |
.get_content |
Get the content of the console | |
.get_variable |
Get a variable from the console | name: string |
.set_variable |
Set a variable in the console | name: string; value: any |
.mount_native_fs |
Mount a native file system to the console | mount_point: string; |
.ready |
A promise that resolves when the console is ready |
You can also control other ImJoy plugins from the console using ImJoy API. For example, you can use the following code to control the ImageJ.JS:
import numpy as np
arr = np.random.randint(0, 255, (100,100), dtype=np.uint8)
ij = await api.createWindow(src="https://ij.imjoy.io")
await ij.viewImage(arr)
The complete ImJoy API can be found here.
API | Description | Parameters |
---|---|---|
api.restart |
Restart the console | |
api.insertHtml |
Insert HTML to the console | html: string; width: string; height: string |
api.mountNativeFs |
Mount a native file system to the console | mountPoint: string; |
api.openEditor |
Open a Python script editor |
Usage example:
# restart the console
await api.restart()
# insert HTML as an iframe
await api.insertHtml("<h1>Hello World</h1>", width="100%", height="100px")
This console can be used in ImageJ.JS as a ImJoy plugin.
Click the Upper left ImJoy icon to open the menu, then click + ImJoy Plugin
to add a new plugin. Then enter the following URL to install the plugin:
https://nanguage.github.io/web-python-console/
Editor:
https://nanguage.github.io/web-python-console/python-editor.imjoy.html
Then click the menu again and click web-python-console
to open the console, or click python-editor
to open the editor.
Try it here!
A demo:
Plugin links for BioImage.IO ChatBot:
https://nanguage.github.io/web-python-console/chatbot-extension.imjoy.html