Skip to main content

Cross-runtime compatibility polyfills for CircuitPython, MicroPython, and CPython — functools.partial and more.

Project description

chumicro-compat

Standard library features that CircuitPython and MicroPython are missing.

Import from chumicro_compat instead of the stdlib and your code works everywhere. On CPython it re-exports the real C implementations (zero overhead); on microcontrollers it provides lightweight pure-Python versions.


Part of the ChuMicro family — small, focused Python libraries for microcontrollers and laptops. See all libraries.

Installation

CircuitPython (circup)

circup is CircuitPython's package manager — it uses bundles to find third-party packages. Register the ChuMicro bundle once, then install by name:

circup bundle-add ChuMicro/ChuMicro-Bundle
circup install chumicro-compat

MicroPython (mip)

mpremote mip install github:ChuMicro/ChuMicro-Bundle/chumicro_compat

Want pre-compiled .mpy bytecode? Add mpy6/ before the package name for faster startup and lower RAM usage on boards with mpy format v6 (MicroPython 1.24+):

mpremote mip install github:ChuMicro/ChuMicro-Bundle/mpy6/chumicro_compat

CPython (pip)

pip install chumicro-compat
Experimental (pre-release) versions and channel switching

Pre-release builds are published automatically when a library version is bumped. Do not register both bundles simultaneously — circup may pick either version for a given package.

# CircuitPython — switch to experimental
circup bundle-remove ChuMicro/ChuMicro-Bundle              # skip if never added
circup bundle-add ChuMicro/ChuMicro-Bundle-Experimental
circup install chumicro-compat

# MicroPython
mpremote mip install github:ChuMicro/ChuMicro-Bundle-Experimental/chumicro_compat

# CPython
pip install chumicro-compat-experimental

Quick example

from chumicro_compat.functools import partial

def set_led(pin: int, brightness: int) -> None:
    """Set an LED pin to a brightness level."""
    print(f"pin {pin}{brightness}%")

# Freeze the pin, vary the brightness later.
set_status_led = partial(set_led, 13)
set_status_led(50)   # pin 13 → 50%
set_status_led(100)  # pin 13 → 100%

What's included

functools

Symbol Description
partial(func, *args, **keywords) Freeze positional and keyword arguments to a callable
partial.func The original wrapped callable
partial.args Frozen positional arguments (tuple)
partial.keywords Frozen keyword arguments (dict)

Platform support

Runtime What happens
CPython Uses the built-in functools.partial directly — zero overhead
MicroPython Lightweight pure-Python replacement
CircuitPython Lightweight pure-Python replacement

The public API (.func, .args, .keywords, __call__, __repr__) is identical across all runtimes.

Examples

Example What it shows
partial_basic.py Freeze one argument to a function
partial_keyword_override.py Freeze keyword args, override at call time
partial_callback.py Wire a callback with frozen context (embedded pattern)

Docs

📖 Stable docs · Experimental docs

Find this library

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chumicro_compat_experimental-0.1.23.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

chumicro_compat_experimental-0.1.23-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file chumicro_compat_experimental-0.1.23.tar.gz.

File metadata

File hashes

Hashes for chumicro_compat_experimental-0.1.23.tar.gz
Algorithm Hash digest
SHA256 2f42094227cd58abb962fde41db9c7bc5672a87af8d23f3af03d0ecf9fa90cd4
MD5 53b4294489236c99d0067d48e0195e95
BLAKE2b-256 31fc6ae12bdf009007cd490acc9eb76eb1f1b0a71402a86a915c00afa92bc754

See more details on using hashes here.

Provenance

The following attestation bundles were made for chumicro_compat_experimental-0.1.23.tar.gz:

Publisher: release.yml on ChuMicro/ChuMicro

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chumicro_compat_experimental-0.1.23-py3-none-any.whl.

File metadata

File hashes

Hashes for chumicro_compat_experimental-0.1.23-py3-none-any.whl
Algorithm Hash digest
SHA256 c6bc2d3e528abd5c323b736873245423a7494f8b35d33e1b9b72d626b8dc9fe3
MD5 c453ce5f81ecd7b7c65d40d540596807
BLAKE2b-256 77199e1e6cb0efc23e1dd059423c837d1a5fee9c5b15cb483bda281c97ae4940

See more details on using hashes here.

Provenance

The following attestation bundles were made for chumicro_compat_experimental-0.1.23-py3-none-any.whl:

Publisher: release.yml on ChuMicro/ChuMicro

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page