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
Metadata
Release files for basthon-turtle 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| basthon_turtle-0.4.1.tar.gz | 71.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| basthon_turtle-0.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 110.3 kB
Release files / basthon_turtle-0.4.1.tar.gz
| Download URL | basthon_turtle-0.4.1.tar.gz |
|---|---|
| Size | 71.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f3837f2fd02b7ea1812ea04f3c741a01b29541c3c2d81e701b7f115c6dfbb793
|
|
BLAKE2b-256 checksum How to use checksums |
6bb20a5cfdee4da0e19e632131358ad8fac618e95026f092109084895b412ad1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|
Release files / basthon_turtle-0.4.1-py3-none-any.whl
| Download URL | basthon_turtle-0.4.1-py3-none-any.whl |
|---|---|
| Size | 38.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0d6d97f7e3ba39428efa700e55e29c06a7a5003108991087a6d3c98569535af6
|
|
BLAKE2b-256 checksum How to use checksums |
d2c7c7a8266dda23750ce1f20a9cb403c9254b931e5f0a1ac7fb6fbff4436fb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.0
|