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.
This module is made for users familiar with the http.server module, with which it shares the same qualities and flaws.
WARNING
I've made this module when I encountered a situation where http protocol was the simplest way to solve a LOCAL Inter-Process-Communication issue, and I did NOT want to add a heavy dependency (like Flask or FastAPI) to the program I was coding. I found out that the standard http 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 ADD NEW security issues to the http module, but it doesn't SOLVE them either.
http.server
To understand what the "handler" object passed to your route actually is, you will need to get familiar with how the http.server module operate. You can find its documentation here
Features
- Simple route declaration using decorators
- Pure standard library
- No magic, no dependencies
- Good for local-only HTTP endpoints
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
BaseHTTPRequestHandleras 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file miniroute-0.1.0.tar.gz.
File metadata
- Download URL: miniroute-0.1.0.tar.gz
- Upload date:
- Size: 4.9 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe5edb9874a9a1b3ad1444c3961618bb8678e15bb20a05b19550e7d1877e6ba0
|
|
| MD5 |
3be7649457e63b335fe0bdafc3ad9262
|
|
| BLAKE2b-256 |
2a2438db3b940b752a21de2e854aae5a18dada1e75fbe792f2a5b2a8fc21d2ac
|
File details
Details for the file miniroute-0.1.0-py3-none-any.whl.
File metadata
- Download URL: miniroute-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69a53a30d8cf3d713835a65e09c4438ff4f0be6e02b31f3a79b40ed863aedf06
|
|
| MD5 |
ea05631974495c287c7ff7cf5960c8fb
|
|
| BLAKE2b-256 |
16b0a71078322c1dc3e720228833e59806afb4941a2deb086e3f1a368dda3218
|