PyRobusta is a memory-conscious HTTP/1.1 server library built for embedded devices where heap usage, connection reliability, and stream processing efficiency matter. PyRobusta offers robust keep-alive connection management and efficient byte-stream processing while maintaining a predictable memory footprint.
- Routing decorators and wildcard-based URL matching
- Multipart request and response handling
- Support for chunked encoding and streaming payloads
- Query parameter parsing with percent encoding support
- Built-in API for uploading, downloading, and deleting files stored on the server
- Persistent connection handling via the
Connection: keep-aliveheader - HTTP/1.0 and HTTP/1.1 support
- TLS support
- Predictable memory usage through fixed-size stream buffers
- Incremental byte-stream processing with bounded memory overhead
- State-machine-driven request parsing for extensibility and protocol correctness
- Reliable connection handling with keep-alive, timeouts, and transport error recovery
- Designed specifically for MicroPython and memory-constrained embedded environments
PyRobusta is under active development. The public API is not yet considered stable and may change between releases.
Starting with v1.0.0, backwards compatibility will be maintained within each major version. Any backwards-incompatible changes introduced before then are clearly documented in the release notes.
Install PyRobusta on your MicroPython-enabled device using the mip package manager.
A minimum of 40 KB free heap is required. However, for better usability and stability, devices with more SRAM are strongly recommended. The ESP32-C3 SuperMini is a good entry-level option, providing a comfortable amount of free memory after installation.
If you haven’t already set up your environment, follow the setup guide to install mpremote and connect your device to Wi-Fi.
# Install the latest version of PyRobusta
import mip
mip.install("github:szeka9/PyRobusta")
# Install required assets
from pyrobusta.utils.assets import install_www
install_www()
# Start the HTTP server
import asyncio
from pyrobusta.server.http_server import HttpServer
async def main():
server = HttpServer()
asyncio.create_task(server.start_socket_server())
while True:
await asyncio.sleep(1)
asyncio.run(main())Open a web browser and enter your device’s IP address in the address bar.
If the server is running correctly, the default homepage will be displayed. Refer to the documentation for configuration options, routing, streaming payloads, and advanced HTTP features.
import asyncio
from gc import mem_free, mem_alloc, collect
import pyrobusta.server.http_server as http_server
from pyrobusta.protocol.http import HttpEngine
@HttpEngine.route("/mem-usage", "GET")
def mem_usage(http_ctx, _):
collect()
free = mem_free()
used = mem_alloc()
usage_percentage = 100 * used / (free + used)
return "text/plain", (
f"Currently used: {usage_percentage:.2f}%\n"
f"Free [bytes]: {free}\n"
f"Used [bytes]: {used}\n"
f"Total [bytes]: {used + free}\n"
)
async def main():
server = http_server.HttpServer()
asyncio.create_task(server.start_socket_server())
while True:
await asyncio.sleep(1)
asyncio.run(main())To fine-tune heap usage and optimize performance, see:
Check the provided development guide to create and deploy custom builds to your device: development guide
