Skip to main content

chumicro-wifi

Wifi that auto-reconnects so your app code doesn't have to.

One WiFi service across CircuitPython (Adafruit boards) and MicroPython on both ESP32 and Pi Pico W. Owns the radio (no CIRCUITPY_WIFI_* settings, no firmware-level auto-reconnect competing with you), surfaces state transitions as events you can wire into the rest of your app via chumicro-runner, and reads its config section via chumicro-config. CircuitPython's substrate-level connect() is blocking — see Platform support for what that means in practice.


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_wifi

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

# CPython
pip install chumicro-wifi-experimental

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

Quick example

User-app pattern (the 4-line bring-up):

from chumicro_config import load_runtime_config
from chumicro_runner import Runner
from chumicro_wifi import WifiConfig, WifiService

config = load_runtime_config()
runner = Runner()
wifi = WifiService(WifiConfig.from_config(config))
runner.add(wifi)

State + IP introspection any time:

wifi.state          # "disconnected" | "connecting" | "connected" | "reconnecting" | "failed"
wifi.connected
wifi.ip
wifi.last_error
wifi.on_state_change(lambda old, new: print(f"{old} -> {new}"))

What's included

Symbol What it does
WifiConfig Typed connection settings (ssid, password, hostname, timeouts, reconnect tuning). from_config(config) reads the flat wifi.* keys; try_from_config(config) returns None when the section isn't deployed.
WifiService State machine + reconnect supervisor; implements Runner.add()-compatible check/handle. Auto-detects the runtime adapter at construction time (FakeWifiAdapter on CPython, CpWifiAdapter on CircuitPython, substrate-aware MpWifiAdapter on MicroPython — handles ESP-IDF + CYW43 transparently).
WifiState String-sentinel state names: DISCONNECTED, CONNECTING, CONNECTED, RECONNECTING, FAILED.
chumicro_wifi.testing.FakeWifi Drop-in WifiService wrapping a FakeWifiAdapter with set_connect_outcome, drop_link, calls hooks for downstream library tests.

Where this fits

Depends on chumicro-config for its config section and registers with chumicro-runner for its tick contract. Provides the radio that the networking layers — chumicro-sockets on CircuitPython, downstream of that for HTTP / MQTT / WebSocket / NTP — sit on top of.

Platform support

Works on CPython, MicroPython, and CircuitPython. Ships three adapters: CircuitPython wifi.radio (_adapters/cp.py), MicroPython network.WLAN covering both ESP-IDF (ESP32 family) and CYW43 (Pi Pico W) stacks (_adapters/mp.py), and a FakeWifiAdapter for host-side tests. The right adapter is selected at runtime via sys.implementation.name; the MP adapter then auto-detects ESP-IDF vs CYW43 by matching sys.implementation._machine against a positive whitelist of known CYW43 boards.

CircuitPython connect is blocking — read this if you're shipping to CP

CircuitPython's substrate-level wifi.radio.connect() is blocking — there is no non-blocking variant exposed by the firmware. While WifiService is CONNECTING or RECONNECTING on a CircuitPython board, handle() stalls for up to connect_timeout_ms (default 15 000 ms). Other services in the same Runner — your LED heartbeat, an HTTP request, an MQTT keep-alive — pause for that window. Once the state reaches CONNECTED, the loop runs at full speed again and stays there until the link drops.

MicroPython's wlan.connect() is genuinely non-blocking on both ESP32 and Pi Pico W substrates — association happens in the background and handle() returns immediately. If non-blocking connect is load-bearing for your app, prefer MicroPython on RP2040 / RP2350 or ESP32-family boards.

Examples

Example What it shows
connect_to_ap.py Connect to a real AP, print state transitions, observe IP — reads wifi.ssid / wifi.password from runtime_config.msgpack.

Wiring wifi credentials for examples and functional tests

The acceptance test in functional_tests/test_acceptance.py connects to a real AP and skips silently when no credentials are configured. Two paths for getting credentials onto the device — workspace-based deploy or raw single-file deploy — are documented in docs/wiring-wifi-credentials.md. The library itself never reads TOML — it takes a WifiConfig and goes; WifiConfig.from_config(config) is the construction path used by the standard pipeline.

Contributing

Working on chumicro-wifi 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

Metadata

Release files for chumicro-wifi-experimental 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chumicro-wifi-experimental 0.8.1
File Size Uploaded
chumicro_wifi_experimental-0.8.1.tar.gz 32.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chumicro-wifi-experimental 0.8.1
File Interpreter ABI Platform
chumicro_wifi_experimental-0.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 46.6 kB

Release files / chumicro_wifi_experimental-0.8.1.tar.gz

Download URL chumicro_wifi_experimental-0.8.1.tar.gz
Size 32.4 kB
Tags Source
SHA-256 checksum
How to use checksums
71aa70aaaff0c6dae0f887f2307f51ac7aac09a7ed06a6a55375d475377ef243
BLAKE2b-256 checksum
How to use checksums
f3638ed2619d8ea78387fc9acd49c53f39269e170730d0a5a89844cfef076c81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 19, 2026.

Transparency log

Release files / chumicro_wifi_experimental-0.8.1-py3-none-any.whl

Download URL chumicro_wifi_experimental-0.8.1-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d4b514b739754b2950623b9d46a15c50dec01014ca57448ba58ef78b9373df57
BLAKE2b-256 checksum
How to use checksums
a28e2311bfbfd517ddca98277ba37ee1a3b5c581541b340fe4f2f405b2930620
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 19, 2026.

Transparency log

Release history Release notifications | RSS feed

0.11.2

2 release files

0.11.1

2 release files

0.9.0

2 release files

0.8.2

2 release files

This release

0.8.1 This release

2 release files

0.8.0

2 release 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