Registry / http-networking / adafruit-circuitpython-requests

adafruit-circuitpython-requests

JSON →
library4.1.17pypypi✓ verified 82d ago

Adafruit CircuitPython Requests provides a requests-like API for making HTTP requests from CircuitPython microcontrollers. It offers a familiar interface for GET, POST, PUT, DELETE, and HEAD operations, allowing microcontrollers with network capabilities (like WiFi or Ethernet) to interact with web services. The current version is 4.1.16, and it typically follows a rapid release cadence with bug fixes and minor improvements.

pip install adafruit-circuitpython-requests
INSTALL
IMPORT
SIG · ADAFRUIT-CIRCUITPY
A
adafruit-circuitpython-requests
http-networkingpythonv4.1.17
Install
2.6s avg
Import
72ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.1.17 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.074s · 27.4MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.6s · import 0.070s · 28MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Session
from adafruit_requests import Session
import adafruit_requests
Response
from adafruit_requests import Response
OutOfRetries
from adafruit_requests import OutOfRetries

This quickstart demonstrates the `adafruit_requests.Session` API. Note that actual network operations on CircuitPython require configuring `wifi.radio` (or Ethernet) and creating a `socketpool.SocketPool` instance, which involves specific hardware and `secrets.py` setup not fully runnable in a generic Python environment. The provided code includes mock objects to illustrate the API without requiring actual hardware, but real network requests will fail.

import ssl import socketpool # Required for network communication import wifi # Required for WiFi connectivity import adafruit_requests # --- This section requires CircuitPython board setup --- # In a real CircuitPython environment, you'd connect to WiFi: # try: # from secrets import secrets # except ImportError: # print("WiFi secrets are kept in secrets.py, please add them there!") # raise # wifi.radio.connect(secrets["ssid"], secrets["password"]) # pool = socketpool.SocketPool(wifi.radio) # --- For demonstration purposes (not runnable without actual network setup) --- # Mock objects for local run-ability, replace with real ones on device: class MockRadio: ipv4_address = "192.168.1.100" class MockSocketPool: def __init__(self, radio): pass # In a real scenario, this would create actual sockets def socket(self, family, type, proto=0): raise NotImplementedError("Mock socketpool does not provide real sockets") class MockSSLContext: def __init__(self): pass # Replace these mocks with real objects on a CircuitPython board wifi.radio = MockRadio() pool = MockSocketPool(wifi.radio) ssl_context = MockSSLContext() # Initialize the requests session with a socket pool and SSL context # On a real CircuitPython device: requests = adafruit_requests.Session(pool, ssl.create_default_context()) requests = adafruit_requests.Session(pool, ssl_context) # Make a GET request (this will fail in mock, but demonstrates API) try: response = requests.get("http://example.com/api/data") print(f"Status Code: {response.status_code}") print(f"Response Text: {response.text}") response.close() except Exception as e: print(f"Error making request (expected in mock setup): {e}") # Make a POST request with JSON data post_data = {"key": "value"} try: response = requests.post("http://example.com/api/submit", json=post_data) print(f"POST Status Code: {response.status_code}") print(f"POST Response Text: {response.text}") response.close() except Exception as e: print(f"Error making POST request (expected in mock setup): {e}")
Debug
Known issues
gotchaThis library is designed for CircuitPython microcontrollers. Running it on a standard CPython environment (e.g., PC) will require `adafruit-blinka` and potentially custom `socketpool` and `wifi` implementations or mocks, and won't interact with physical network hardware directly.
fix
Ensure you are targeting a CircuitPython board with proper network hardware (WiFi, Ethernet) and an initialized `socketpool`.
affects: All versions
gotchaMicrocontrollers have limited memory. Large HTTP responses (e.g., big JSON files, images) can quickly exhaust RAM, leading to `MemoryError` or system crashes.
fix
Request only necessary data, use streaming where possible, or parse responses chunk by chunk if the API allows. Consider the `response.iter_content()` method for streaming large responses.
affects: All versions
gotchaSSL/TLS support on microcontrollers is resource-intensive. `ssl.create_default_context()` might not always be available or performant, and specific certificate handling might be required, especially for HTTPS.
fix
Always use `ssl.create_default_context()` where possible for HTTPS. For custom certificates or older hardware, consult Adafruit's CircuitPython documentation for specific SSL setup instructions for your board.
affects: All versions
gotchaHTTP requests are typically blocking operations. A long request or a network timeout can freeze your CircuitPython program until it completes or fails.
fix
Design your application to handle blocking operations gracefully. Consider using asynchronous patterns if available (e.g., `asyncio` on some boards, though not directly supported by `adafruit_requests`), or implement timeouts for requests to prevent indefinite blocking.
affects: All versions
Upgrade
Version history
4.1.17latest on PyPI · released Apr 23, 2026
Audit
Dependencies
adafruit-blinkaoptionalEnables running some CircuitPython libraries on single-board computers like Raspberry Pi with CPython.
adafruit-circuitpython-busdevicerequiredProvides low-level bus communication utilities, often used by network hardware drivers.
adafruit-circuitpython-typingrequiredProvides type hinting support for CircuitPython specific types.
Agent activity
43 hits · last 30 days
node
38
OpenAI (training)
1
Resources
adafruit-circuitpython-requests — pip install adafruit-circuitpython-requests · libregistry