Skip to main content

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

Project description

chumicro-compat

Stdlib polyfills for the bits CircuitPython and MicroPython skipped.

Import from chumicro_compat instead of the stdlib and your code works everywhere. CPython gets the real C implementation (zero overhead); CircuitPython and MicroPython get a lightweight pure-Python version of the same public API.


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

Install

# CircuitPython (after `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

For bundle setup, pre-compiled .mpy bundles, the experimental channel, and details on PyPI naming, see the chumicro INSTALL guide.

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.

Where this fits

Leaf — no upstream ChuMicro deps. Used directly by any library or app that wants stdlib features (functools.partial, …) missing from CircuitPython / MicroPython.

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)

Contributing

Working on chumicro-compat itself? Clone the mono-repo if you haven't already — the rest of the workflow assumes you're inside that workspace.

pip install -e .[test]
pytest tests/                  # host-side tests
pytest functional_tests/       # on-device tests (needs a board registered in devices.yml)

Register a board before running functional tests: chumicro-workspace add-device <id> --address <port>.

Docs

📖 Stable docs · Experimental docs

Find this library

License

MIT

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.3.1.tar.gz (9.0 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.3.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for chumicro_compat_experimental-0.3.1.tar.gz
Algorithm Hash digest
SHA256 4d60ac7842cdaf8a05da2eb9152c217e2dd5aa3ea6c0834c572f4ac552e291d5
MD5 9bc24e1e7db7745aab75fd58aede2c60
BLAKE2b-256 4ff095cf1b4edfa11c47cb4133d72e031d1af6fee16012b719e9f63971c78fe7

See more details on using hashes here.

Provenance

The following attestation bundles were made for chumicro_compat_experimental-0.3.1.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.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for chumicro_compat_experimental-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f57ee73da0662a0eb822cf3e8c89ffc47554c05b690c66a65a363be6c6ee9eb2
MD5 4895923a036de8af6d49e29d10104364
BLAKE2b-256 ba90ff2e8c1d032b3735e3f75e871e532916af0e47a050040d44c26239728e2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for chumicro_compat_experimental-0.3.1-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