Zero-dependency web router.
Project description
muxy
A router/http request multiplexer for composing servers conforming to Granian's Rust Server Gateway Interface (RSGI)
Inspiration
Go's stdlib has a minimalist but fully-functional router that allows simple composition of endpoint handlers. The routing uses a radix-tree which is far more efficient than Starlette's linear search of regex patterns. Whether this practically makes a difference, I don't really care, I just think it's a nice to do things properly.
package main
import (
"fmt"
"log"
"net/http"
)
func helloWorld(w http.ResponseWriter, req *http.Request) { // implements `HandlerFunc` interface
fmt.Print(w, "Hello world")
}
func main() {
// i want a way to compose RSGI apps like this
childMux := http.NewServeMux() // implements `http.Handler` interface
childMux.HandleFunc("GET /hello", helloWorld) // mount a `HandlerFunc`
rootMux := http.NewServeMux()
rootMux.Handle("/child/", http.StripPrefix("/child", childMux)) // nest an `http.Handler`
// could then pass the root RSGI app to granian, which provides the `ListenAndServe`
log.Fatal(http.ListenAndServe("localhost:8080", rootMux))
}
Planning
RSGI is our equivalent interface to `http.Handler`
from asyncio import AbstractEventLoop
from typing import Protocol
from granian.rsgi import HTTPProtocol, Scope, WebsocketProtocol
class RSGI(Protocol):
async def __rsgi__(
self, __scope: Scope, __proto: HTTPProtocol | WebsocketProtocol
): ...
def __rsgi_init__(self, __loop: AbstractEventLoop): ...
def __rsgi_del__(self, __loop: AbstractEventLoop): ...
The request metadata & headers are in Scope and it's body is accessible in
HTTPProtocol. The response is writable using the HTTPProtocol.
Scope:
schememethodpathquery_stringheadersserver
Request body:
proto()async for chunk in proto()
Response:
proto.response_empty(status, headers)proto.response_{str,bytes}(status, headers, body)proto.response_{file}(status, headers, path)proto.response_{stream}(status, headers).send_{str,bytes}(data)
We need to implement a way to create and compose instances of applications
implementing the RSGI.
Project details
Release history Release notifications | RSS feed
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 muxy-0.1.0.dev1.tar.gz.
File metadata
- Download URL: muxy-0.1.0.dev1.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09b26663c0be48777c054d70301c36cc4410f0419d2e3e97fef3623e7db2dec1
|
|
| MD5 |
56d3f48499b0f4a24202282b71321b08
|
|
| BLAKE2b-256 |
c1628ad8fd9a6227925a4da4d52621bd55fb1a992f46d43e6c537b988d626a38
|
Provenance
The following attestation bundles were made for muxy-0.1.0.dev1.tar.gz:
Publisher:
release.yaml on oliverlambson/muxy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
muxy-0.1.0.dev1.tar.gz -
Subject digest:
09b26663c0be48777c054d70301c36cc4410f0419d2e3e97fef3623e7db2dec1 - Sigstore transparency entry: 780857084
- Sigstore integration time:
-
Permalink:
oliverlambson/muxy@5b70bba9103f3bf7148c4939f8ee8df85ed0511f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/oliverlambson
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@5b70bba9103f3bf7148c4939f8ee8df85ed0511f -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file muxy-0.1.0.dev1-py3-none-any.whl.
File metadata
- Download URL: muxy-0.1.0.dev1-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4cda7df8fd0a969a795f84ebbfed6c4d02cee30bcaee315bceb5a5c3c12740b8
|
|
| MD5 |
553b41e7c0621e527ef2727af18ac80f
|
|
| BLAKE2b-256 |
059f51c6b00aa2501dc7c756cb4215036f2112a5ff576dd9ca6e15e7916079a3
|
Provenance
The following attestation bundles were made for muxy-0.1.0.dev1-py3-none-any.whl:
Publisher:
release.yaml on oliverlambson/muxy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
muxy-0.1.0.dev1-py3-none-any.whl -
Subject digest:
4cda7df8fd0a969a795f84ebbfed6c4d02cee30bcaee315bceb5a5c3c12740b8 - Sigstore transparency entry: 780857085
- Sigstore integration time:
-
Permalink:
oliverlambson/muxy@5b70bba9103f3bf7148c4939f8ee8df85ed0511f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/oliverlambson
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@5b70bba9103f3bf7148c4939f8ee8df85ed0511f -
Trigger Event:
workflow_dispatch
-
Statement type: