Starlette
Starlette (opens in a new tab) is a lightweight ASGI framework — the foundation that FastAPI is built on. Use it when you want maximum control without the full FastAPI layer.
Install
pip install mekong-tunnel starlette uvicornUsage
Since Starlette apps are standard ASGI apps, use mekong-uvicorn:
mekong-uvicorn myapp:app --reload --domainExample App
# myapp.py
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
async def homepage(request):
return JSONResponse({"message": "Hello from Starlette!"})
async def health(request):
return JSONResponse({"status": "ok"})
app = Starlette(routes=[
Route("/", homepage),
Route("/health", health),
])mekong-uvicorn myapp:app --reload --domainStarlette Middleware
from starlette.middleware.cors import CORSMiddleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)WebSockets with Starlette
WebSocket connections work through the MekongTunnel proxy:
from starlette.websockets import WebSocket
async def ws_endpoint(websocket: WebSocket):
await websocket.accept()
while True:
data = await websocket.receive_text()
await websocket.send_text(f"Echo: {data}")
app = Starlette(routes=[
WebSocketRoute("/ws", ws_endpoint),
])mekong-uvicorn myapp:app --reload --domain
# Connect: wss://your-tunnel.mekongtunnel.dev/wsGranian
Granian (opens in a new tab) is a modern, high-performance Rust-based ASGI/RSGI server — an alternative to uvicorn and gunicorn with excellent performance.
Install
pip install mekong-tunnel granianUsage
# Same as: granian --interface asgi myapp:app
mekong-granian myapp:app --interface asgi
# With options
mekong-granian myapp:app \
--interface asgi \
--host 0.0.0.0 \
--port 8000 \
--workers 2 \
--domainRSGI Mode (Granian-native)
mekong-granian myapp:app --interface rsgi --domainExample: FastAPI with Granian
pip install fastapi granian mekong-tunnel
mekong-granian main:app --interface asgi --reload --domainAll Granian Options Pass Through
mekong-granian myapp:app \
--interface asgi \
--host 0.0.0.0 \
--port 8000 \
--workers 4 \
--threads 2 \
--http 2 \
--reload \
--domainHypercorn
Hypercorn (opens in a new tab) is an ASGI server that supports HTTP/1, HTTP/2, and HTTP/3 (QUIC).
Install
pip install mekong-tunnel hypercornUsage
# Same as: hypercorn myapp:app
mekong-hypercorn myapp:app
# With options
mekong-hypercorn myapp:app \
--bind 0.0.0.0:8000 \
--workers 2 \
--domainHTTP/2 with Hypercorn
mekong-hypercorn myapp:app \
--bind 0.0.0.0:8000 \
--keyfile key.pem \
--certfile cert.pem \
--domainServer Comparison
| Server | Type | Language | Best For |
|---|---|---|---|
| Uvicorn | ASGI | Python | FastAPI, Starlette, general ASGI |
| Gunicorn | WSGI | Python | Flask, Django, multi-worker |
| Granian | ASGI/RSGI | Rust | High performance, low memory |
| Hypercorn | ASGI | Python | HTTP/2, HTTP/3 support |
| Daphne | ASGI | Python | Django Channels, WebSockets |
All are fully supported by the mekong-tunnel package.
Environment Variables
MEKONG_TOKEN=your_token mekong-granian myapp:app --interface asgi
MEKONG_TOKEN=your_token mekong-hypercorn myapp:app --bind 0.0.0.0:8000