Skip to main content

Async server for userv

Project description

The catch

Most simplistic socket server for micropython

Webserver

first we need to add routes to a router. This is described in userv.core although serving static files is described below.

Example:

from userv.routing import Router
from userv.socket_server import run_server
router = Router()
# we add some routes

run_server(router)

this way the server starts and runs forever. Because sometimes you want to start a standby mode there is way to kill the run task by given a callback which controls the loop. We call it the timeout callback for now. Basicly the server runs as long as the function returns True.

Example:

def we_never_timeout():
    return True

run_server(router, timeout_callback=we_never_timeout)

This is only a realy simple and silly example, but be aware to not do heavy lifting in this function, because it will hinder your server to react normal.

Serve static files

It is prety simple just add the address with the file you want to serve.

Example:

from userv.socket_server import static_file
router.add("/index", static_file('boot.py'))

Although the example should never expose your code. It is a prety simple and fast test.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for userv.socket-server, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size userv.socket_server-0.3.0.tar.gz (2.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page