micropython-uaioweb
A very minimal asyncio web framework for MicroPython. Doesn't come with all the bells and whistles you might want out of a serious web framework but the goal is just to make asyncio HTTP applications in MicroPython as simple and efficient as possible.
Current features
- minimal overhead in terms of code size or memory use
- easy integration into existing asyncio projects by running as a normal task alongside others
- basic endpoint/method based routing similar to flask (currently doesn't do any pattern matching)
- parses http request line, headers, and query strings
- supports WebSockets!
- supports Server-Sent Events!
Rationale
micropython-uaioweb is a packaged version of micropython-aioweb, an amazing minimal and functional HTTP toolkit for micropython by Davy Wybiral.
This project aims at releasing the library on PyPI by forking and reworking branch main with 1 commit per version.
Examples
Basic "Hello world!"
import uaioweb
from uaioweb import asyncio # Note: compatibility between micropython and python.
app = uaioweb.App(host='0.0.0.0', port=80)
# root route handler
@app.route('/')
async def handler(r, w):
# write http headers
w.write(b'HTTP/1.0 200 OK\r\n')
w.write(b'Content-Type: text/html; charset=utf-8\r\n')
w.write(b'\r\n')
# write page body
w.write(b'Hello world!')
# drain stream buffer
await w.drain()
# Start event loop and create server task
loop = asyncio.get_event_loop()
loop.create_task(app.serve())
loop.run_forever()
POST request handler
@app.route('/', methods=['POST'])
async def handler(r, w):
body = await r.read(1024)
form = uaioweb.parse_qs(body.decode())
name = form.get('name', 'world')
# write http headers
w.write(b'HTTP/1.0 200 OK\r\n')
w.write(b'Content-Type: text/html; charset=utf-8\r\n')
w.write(b'\r\n')
# write page body
w.write(b'Hello {}!'.format(name))
# drain stream buffer
await w.drain()
WebSocket handler
# /ws WebSocket route handler
@app.route('/ws')
async def ws_handler(r, w):
# upgrade connection to WebSocket
ws = await WebSocket.upgrade(r, w)
while True:
evt = await ws.recv()
if evt is None or evt['type'] == 'close':
# handle closed stream/close event
break
elif evt['type'] == 'text':
# print received messages and echo them
print('Received:', evt['data'])
await ws.send(evt['data'])
SSE (Server-Sent Events) handler
# /events EventSource route handler
@app.route('/events')
async def ws_handler(r, w):
# upgrade connection to text/event-stream
sse = await uaioweb.EventSource.upgrade(r, w)
count = 0
while True:
count += 1
try:
await sse.send('Hello world #{}'.format(count))
except:
break
await asyncio.sleep(1)
Metadata
Release files for micropython-uaioweb 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| micropython-uaioweb-0.0.3.tar.gz | 5.3 kB | Without provenance | Details for micropython-uaioweb-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| micropython_uaioweb-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for micropython_uaioweb-0.0.3-py3-none-any.whl |
Total release size: 11.1 kB
Release files / micropython-uaioweb-0.0.3.tar.gz
| Download URL | micropython-uaioweb-0.0.3.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
edaac99ea778775f372a9c44747d7e958d3843f37d468136f2e1defd7a8d3f7a
|
|
BLAKE2b-256 checksum How to use checksums |
e4e0c3d6a06b544b0b1c612c43c51a3e829c9071d4fe8e52fadf30383d06aa67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Release files / micropython_uaioweb-0.0.3-py3-none-any.whl
| Download URL | micropython_uaioweb-0.0.3-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9bd7f37b15eae0cd4065108b9701dedf7dd6849c25184836b96606197720f9c1
|
|
BLAKE2b-256 checksum How to use checksums |
becf25e30883c1c480a9fe6d36dfdd5505032ce2d21ca34b16f3b54e22edf03c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Security for micropython-uaioweb 0.0.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.