Skip to main content

A minimal HTTP routing framework based on Python’s built-in `http.server` for IPC tooling.

Project description

Miniroute

Miniroute is a minimal HTTP routing framework based on Python’s built-in http.server, designed for lightweight local servers and IPC tooling.

Warning

I've made this module facing a situation where the http protocol was the simplest way to solve a LOCAL Inter-Process-Communication issue, and did NOT wanted to add any dependency (like Flask or FastAPI) to my project. I found out that the standard http.server module would do the job, but was a pain to integrate.

As the officiel http documentation state : This is NOT a server to be used in PRODUCTION.

This module doesn't address any security flaws that http.server may bring up.

It's encouraged to be familiar with http.server documentation before using miniroute

Features

  • Simple flask-like route declaration using decorators
  • Purely based on standard libraries
  • No magic, no dependencies
  • Good for local-only HTTP endpoints, and non-performant reliant IPC.

Installation

pip install miniroute

Usage

from miniroute import Miniroute
import json

app = Miniroute()

@app.router.get("/hello")
def hello(handler):
    body = json.dumps({"message": "Hello, world!"}).encode()
    headers = [("Content-Type", "application/json")]
    return 200, headers, body

@app.router.post("/echo")
def echo(handler):
    length = int(handler.headers.get("Content-Length", 0))
    data = handler.rfile.read(length)
    return 200, [("Content-Type", "application/json")], data

if __name__ == "__main__":
    app.run()

Route handlers

Each route function:

  • Receives the current BaseHTTPRequestHandler as argument
  • Must return a tuple: status_code: int, headers: dict[str, str], body: bytes

Example:

return 200, [("Content-Type", "text/plain")], b"OK"

License

PSF License You are free to use, modify, and distribute this software under the terms of the Python Software Foundation License.

This project is not affiliated with or endorsed by the Python Software Foundation.

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

miniroute-0.1.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

miniroute-0.1.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file miniroute-0.1.1.tar.gz.

File metadata

  • Download URL: miniroute-0.1.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.2 Linux/6.1.0-33-amd64

File hashes

Hashes for miniroute-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a407176eb9e25e95536d2be2bcab3ceaf0255169ea2eba79c24691aa9026b497
MD5 8435bdf7d7fb027d0856411b2d63ee85
BLAKE2b-256 f944a5ae5d8f6402843888029074238e43046641a229e5b6365710c679f0aa45

See more details on using hashes here.

File details

Details for the file miniroute-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: miniroute-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.2 Linux/6.1.0-33-amd64

File hashes

Hashes for miniroute-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c592ae18b17d10430dfe0e2c7fb9f6a633f33edb0ffc18008acca82a9a74daa5
MD5 81c2f425fe15945e51ddd64270c15c11
BLAKE2b-256 ebf779b7d11e6a019c367b8f51a06ad3b29d5025e787f964e20a0bb541c99394

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