A revised version of CPython’s turtle module, browser-friendly.
The optional standalone mode supports interactive CPython use. The abbreviated docstrings remain less suitable for help() than CPython’s implementation.
All public methods/functions of the CPython version should exist, if only to print out a warning that they are not implemented. The intent is to make it easier to “port” any existing turtle program from CPython to the browser.
Initially the code was part of Brython, then ported to Basthon, then published as a standalone package.
Installation
pip install basthon-turtle
For a live, persistent browser window in a regular CPython session, install the proof-of-concept standalone extra:
pip install "basthon-turtle[standalone]"
or
import micropip
await micropip.install('basthon-turtle')
Usage
Note: if running multiple times you need to restart the state of screen with turtle.restart() function.
Standalone CPython
The browser starts lazily on the first visible turtle operation. It remains alive between commands and receives incremental drawing updates:
from turtle import forward, left
forward(100)
left(90)
forward(50)
Jupyter
Install the portable persistent Jupyter renderer with:
pip install "basthon-turtle[notebook]"
Turtle commands are buffered during each cell and animated in one persistent inline SVG widget after the cell finishes:
from turtle import forward, left
forward(100)
left(90)
forward(50)
For a JupyterLab-specific panel, install basthon-turtle[sidecar] instead. Call jupyter_sidecar(False) before drawing to force the portable inline widget when sidecar is otherwise available. The original done() and svg() workflow remains available.
Marimo
Install the native persistent Marimo renderer with:
pip install "basthon-turtle[notebook]"
from turtle import forward, left
forward(100)
left(90)
forward(50)
The first visible operation mounts a persistent AnyWidget in the current cell. Later turtle calls update that canvas without requiring done() or mo.Html(svg()).
Browser-only Pyodide
Plain Pyodide can host the live mode entirely in one browser tab. Run Python in a Web Worker and forward the semantic turtle protocol to the persistent SVG renderer with postMessage. This keeps animation responsive without a localhost server or WebSocket; see docs/pyodide.md for a complete example.
Credits
bearney74
André Roberge
Romain Casati
Implementation
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file basthon_turtle-0.3.0.tar.gz.
File metadata
- Download URL: basthon_turtle-0.3.0.tar.gz
- Upload date:
- Size: 55.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7e80c9e0ea831c7effde6ff43ba85c59498703ea18ecfe24594c1165f8f9519
|
|
| MD5 |
24051888033a23e6395423c73c2814c9
|
|
| BLAKE2b-256 |
25a6db37ee8e9586daa04e19347fd3c08efa0dadf15537bffef7a281272acae9
|
File details
Details for the file basthon_turtle-0.3.0-py3-none-any.whl.
File metadata
- Download URL: basthon_turtle-0.3.0-py3-none-any.whl
- Upload date:
- Size: 36.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba874ff9a9899aff74f807e0dd9604c10c30fffa710f68f6787bf95a4857d243
|
|
| MD5 |
77bfbf76b16332ece7c02355ce4cbb97
|
|
| BLAKE2b-256 |
924116ee5efcae8a7a46dfa0c2ee7009c159cb15296cd3fb22c739aa36babacc
|