Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hugokernel/micropython-nanoweb
Full async Micropython web server with small memory footprint.
https://github.com/hugokernel/micropython-nanoweb
async esp esp32 esp8266 python raspberry-pi-pico webserver
Last synced: 9 days ago
JSON representation
Full async Micropython web server with small memory footprint.
- Host: GitHub
- URL: https://github.com/hugokernel/micropython-nanoweb
- Owner: hugokernel
- License: mit
- Created: 2020-09-05T07:10:34.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-06-09T07:39:43.000Z (5 months ago)
- Last Synced: 2024-10-15T18:40:19.512Z (24 days ago)
- Topics: async, esp, esp32, esp8266, python, raspberry-pi-pico, webserver
- Language: Python
- Homepage:
- Size: 35.2 KB
- Stars: 104
- Watchers: 8
- Forks: 18
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-python-web-frameworks - micropython-nanoweb - Full async MicroPython web server with small memory footprint. (Frameworks for Micropython / More)
- awesome-micropython - micropython-nanoweb - Full async MicroPython web server with small memory footprint. (Libraries / Communications)
README
# Nanoweb
Nanoweb is a full asynchronous web server for micropython created in order to benefit from
a correct ratio between memory size and features.It is thus able to run on an ESP8266, ESP32, Raspberry Pico, etc...
## Features
* Completely asynchronous
* Declaration of routes via a dictionary or directly by decorator
* Management of static files (see assets_extensions)
* Callbacks functions when a new query or an error occurs
* Extraction of HTML headers
* User code dense and conci
* Routing wildcards## Installation
You just have to copy the `nanoweb.py` file on the target (ESP32, Nano, etc...).
## Use
See the [example.py](example.py) file for an advanced example where you will be able to:
* Make a JSON response
* Use pages protected with credentials
* Upload file
* Use `DELETE` method
* Read `POST` dataAnd this is a simpler example:
```Python
import uasyncio
from nanoweb import Nanowebnaw = Nanoweb()
async def api_status(request):
"""API status endpoint"""
await request.write("HTTP/1.1 200 OK\r\n")
await request.write("Content-Type: application/json\r\n\r\n")
await request.write('{"status": "running"}')# You can declare route from the Nanoweb routes dict...
naw.routes = {
'/api/status': api_status,
}# ... or declare route directly from the Nanoweb route decorator
@naw.route("/ping")
async def ping(request):
await request.write("HTTP/1.1 200 OK\r\n\r\n")
await request.write("pong")loop = asyncio.get_event_loop()
loop.create_task(naw.run())
loop.run_forever()
```## Contribute
* Your code must respects `flake8` and `isort` tools
* Format your commits with `Commit Conventional` (https://www.conventionalcommits.org/en/v1.0.0/)