Skip to main content

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

basthon_turtle-0.3.1.tar.gz (54.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

basthon_turtle-0.3.1-py3-none-any.whl (36.0 kB view details)

Uploaded Python 3

File details

Details for the file basthon_turtle-0.3.1.tar.gz.

File metadata

  • Download URL: basthon_turtle-0.3.1.tar.gz
  • Upload date:
  • Size: 54.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.0

File hashes

Hashes for basthon_turtle-0.3.1.tar.gz
Algorithm Hash digest
SHA256 150845460bf51be5926447f5a1b3b98a8ce2de9eb501d0c0fef77f26e2eb5d45
MD5 02d7adb3dd3e910fd6feacfbbf2844bf
BLAKE2b-256 b1ab488c7f7c0e9cfd9f4a62668a1ac37af08ade642546de364c92e826d64f40

See more details on using hashes here.

File details

Details for the file basthon_turtle-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: basthon_turtle-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 36.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.0

File hashes

Hashes for basthon_turtle-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 229505b747f3c66d314f9e4ea385294bc6f7a2515d2d86236d7ab2294b2fbafa
MD5 80fdd49ffa37bae0fd1d442323a137d8
BLAKE2b-256 f3ad574e8771520a1f309c4c41afaec86c75a159c5541db17ec8b901fcd16ea0

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

2 files

This release

0.3.1 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page