Skip to content

Differences from CPython

petitpy runs most everyday Python unchanged, but it builds on MicroPython and is still alpha software. This page lists what behaves differently from CPython 3.12+, so you can tell a bug from a known limit.

The native build (pip install petitpy, uvx petitpy, brew install abilian/tap/petitpy; the command is petitpy or ppy) and the browser build (npm install petitpy, the playground) run the same Python. The browser build adds direct DOM access through the js module and leaves out what a page cannot use: files, os, time, subprocess and sockets.

Language and built-in types

Area petitpy CPython
str.upper() / lower() ASCII letters only; no unicodedata. Full Unicode case mapping.
Complex numbers 2j does not compile. Supported.
Keyword arguments to built-ins Taken where CPython takes them, except int(x, base=), int.to_bytes and int.from_bytes, which take positional arguments only and ignore signed. Taken by name wherever the signature allows.
Implicit exception chaining __context__ is always None; raise ... from works, with __cause__ and a chained traceback. Recorded and printed.
Annotations A class's __annotations__ is an OrderedDict of their source text, as under from __future__ import annotations; typing.get_type_hints() evaluates them. Functions keep no annotations. Evaluated objects (or lazy, 3.14).
Enum classes Members are real (.name, .value, Color(1), Color.__members__), but the class itself cannot be iterated, measured or subscripted: for c in Color, len(Color) and Color["RED"] fail. There are no metaclasses. Supported.
Exception text MicroPython's: ValueError('x',) as repr, KeyError: x unquoted, divide by zero. ValueError('x'), KeyError: 'x', division by zero.
Tracebacks File names and functions, no line numbers or source lines. Line numbers and source.

Library and platform

Area petitpy CPython
Standard library A subset: json, re, math, itertools, functools, collections, dataclasses, datetime, pathlib, typing, enum, random, string, struct, … (what runs). No asyncio (coroutines run, there is no event loop), csv, decimal, fractions, unicodedata, sqlite3, ssl. The full library.
Files (native) A write is visible to a reread only after close() or flush(). Same rule, but CPython closes a dropped file at once (reference counting).
Files, os and time (browser) No open(), os or time, so no datetime, pathlib or uuid either; programs see the files the page passes in. Full file system, os and time.
Threads _thread is a stub. Available.
subprocess (native) run(), check_output() and call() only, without shell=True; no Popen. A command that cannot be started gives return code 127. Popen, and FileNotFoundError for a missing command.
Missing module import nope raises ModuleNotFoundError with CPython's message, but without its name attribute. Raises ModuleNotFoundError, with name set.

Reporting a difference

Anything else that behaves differently from CPython is a bug or an unknown gap. Please report it with the smallest program that shows it.