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`)
circup install chumicro-compat

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

# CPython
pip install chumicro-compat

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.0.tar.gz (14.9 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.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for chumicro_compat_experimental-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4194194d2bdd5ecae4a3fb43b91867d6827770e84ed17194b81d7bfda049fb70
MD5 6c5561b41750c8f1eb3e78365f80939a
BLAKE2b-256 074c285fb765b897714ce13108ea81e1b9eff03a5d992334212225672327c7f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for chumicro_compat_experimental-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 560b186aba67e55636ebc3b72a1abb7720b8b65553e6901e8449c2bae5aa76c8
MD5 9526271acce98045e67975ee7ec2fd58
BLAKE2b-256 bad8642796d6a081677312b7087344fb66ed4b1afaf4a4bf06584e0745f762ad

See more details on using hashes here.

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