Documentation
Python
Starlette

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 uvicorn

Usage

Since Starlette apps are standard ASGI apps, use mekong-uvicorn:

mekong-uvicorn myapp:app --reload --domain

Example 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 --domain

Starlette 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/ws

Granian

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 granian

Usage

# 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 \
  --domain

RSGI Mode (Granian-native)

mekong-granian myapp:app --interface rsgi --domain

Example: FastAPI with Granian

pip install fastapi granian mekong-tunnel
 
mekong-granian main:app --interface asgi --reload --domain

All Granian Options Pass Through

mekong-granian myapp:app \
  --interface asgi \
  --host 0.0.0.0 \
  --port 8000 \
  --workers 4 \
  --threads 2 \
  --http 2 \
  --reload \
  --domain

Hypercorn

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 hypercorn

Usage

# Same as: hypercorn myapp:app
mekong-hypercorn myapp:app
 
# With options
mekong-hypercorn myapp:app \
  --bind 0.0.0.0:8000 \
  --workers 2 \
  --domain

HTTP/2 with Hypercorn

mekong-hypercorn myapp:app \
  --bind 0.0.0.0:8000 \
  --keyfile key.pem \
  --certfile cert.pem \
  --domain

Server Comparison

ServerTypeLanguageBest For
UvicornASGIPythonFastAPI, Starlette, general ASGI
GunicornWSGIPythonFlask, Django, multi-worker
GranianASGI/RSGIRustHigh performance, low memory
HypercornASGIPythonHTTP/2, HTTP/3 support
DaphneASGIPythonDjango 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