Basthon Turtle is a browser-friendly implementation of Python’s turtle module. It keeps the familiar turtle API while replacing the Tk canvas with SVG, so turtle programs can run in notebooks and browser-based Python environments.
The package supports four display environments:
CPython with an optional standalone browser window;
Jupyter with a persistent inline SVG widget or optional JupyterLab sidecar;
Marimo with a persistent AnyWidget canvas; and
Pyodide, where a Web Worker sends incremental drawing updates to an SVG page without a Python server or WebSocket.
The rendering backends share turtle state and drawing operations, while each environment supplies its own transport and display. The traditional done() workflow remains available, and svg() returns the current SVG scene.
Installation
pip install basthon-turtle
For a live, persistent browser window in a regular CPython session, install the standalone extra:
pip install "basthon-turtle[standalone]"
or
import micropip
await micropip.install('basthon-turtle')
Usage
When reusing a Python process, call turtle.restart() to reset the screen and turtle state.
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(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.
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 the same canvas automatically; no explicit done() call is required.
Browser-only Pyodide
Plain Pyodide can host the live mode entirely in one browser tab. The example runs Python in a Web Worker and forwards incremental turtle operations to a 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
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.4.0.tar.gz.
File metadata
- Download URL: basthon_turtle-0.4.0.tar.gz
- Upload date:
- Size: 67.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbb31d8e428f376d9cb67a44f4a30844c9a47fe341378b15b3ca74dc694acde2
|
|
| MD5 |
19180dd82f821f1c43e7a71856098de2
|
|
| BLAKE2b-256 |
4d6cb5f89ce46e0c11b8fda150222753f912b7ab098d56748f476105c709aa12
|
File details
Details for the file basthon_turtle-0.4.0-py3-none-any.whl.
File metadata
- Download URL: basthon_turtle-0.4.0-py3-none-any.whl
- Upload date:
- Size: 37.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 |
7b0bc3f04f47c17bfe59d713768b1035d7cbdd57e3be1b79a60fa3635fa1c2ce
|
|
| MD5 |
8fb92d5580c381898b05f846bb13c893
|
|
| BLAKE2b-256 |
7262c38327bce8641d299be920ee6b7d724934f322d0a2bf09b22279819b2c9b
|