Skip to main content

a simple HTTP server using functional principles for Micropython and CPython

Project description

micro_http_server

a simple http server for micropython and CPython which also happens to be fast

examples

def my_post_handler(url, data) -> tuple:
    code, hdrs = 404, {}
    if url == "/users":
        for k, v in data.items():
            DB[k] = v
        code = 200
    return code, "", hdrs

def my_get_handler(url, data) -> tuple:
    return 200, "hello world!", {}

async def my_handle_client(reader, writer):
    handlers = {
        "get": my_get_handler,
        "post": my_post_handler,
    }
    await userver.handle_client(reader, writer, handlers)
    await userver.finalise_client(reader, writer)
    
async def main():
    loop.create_task(asyncio.start_server(my_handle_client, "0.0.0.0", 3000))

speed

Not a design consideration, but. Benchmarking a simple GET request handler, one request takes ~200 usec user time. Running on a Macbook M1, a single core can serve approx 6000 requests/sec.

Project details


Download files

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

Source Distribution

micro_http_server-0.1.2.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

micro_http_server-0.1.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file micro_http_server-0.1.2.tar.gz.

File metadata

  • Download URL: micro_http_server-0.1.2.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.1

File hashes

Hashes for micro_http_server-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fe3419b89734012fa46779b628d33084443d8d20cd6a01e19fd7e1959c07f932
MD5 3a962642a0ba7f888d797f5dde6a6e26
BLAKE2b-256 00fdf596b98e5d1cf210403f2c78e86b4dfd10bf01cfbf9d829a1afcae22fef2

See more details on using hashes here.

File details

Details for the file micro_http_server-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for micro_http_server-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 67c73818949a6b46ffafa74f9c8c61e2e611f99c0b10d33ad4fa4ec13baf634c
MD5 f00178fe947b7bea142b5ed8de61e668
BLAKE2b-256 6912b87a73f6002050a602fbc1437d7a94b4b16b1f1134f407ee229df437461e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page