All-Night
Night is a tiny, single-file ASGI web framework for Python 3.11+.
It keeps the core dependency-free, supports sync and async handlers, and includes routing, request/response helpers, validation, sessions, testing, realtime APIs, JSON-RPC, OpenAPI, a small SQLite ORM, Cloudflare Python Workers integration, stateless MCP tooling, and Vercel ASGI deployment.
pip install -U all-night
from night import Night
app = Night()
@app.get("/")
def index():
return {"hello": "night"}
@app.get("/users/<int:user_id>")
def user(user_id: int):
return {"id": user_id}
Run with an ASGI server:
uvicorn app:app --reload
or use Night's CLI:
night run app.py
Why Night
- Single-file core — the framework core stays in
night.pyand has no required runtime dependencies on normal CPython. - Fast routing — static routes use direct indexes; common dynamic routes are compiled into specialized fast paths so large route tables do not require linear scans.
- Sync + async — handlers are classified at registration time and Night compiles route-specific invokers to reduce per-request branching.
- HTTP batteries included — JSON, forms, multipart uploads, cookies, sessions, CSRF helpers, streaming, SSE, WebSocket, static files, middleware, hooks, and error handlers.
- Typed request bodies — validate nested dataclasses, optional values, and
list[T]request bodies. - Tooling — built-in in-process
TestClient, CLI, named routes, OpenAPI generation, extensions, JSON-RPC, and a lightweight SQLite ORM. - MCP 2026-07-28 — the optional
night_mcpmodule exposes the existing RPC registry as statelessserver/discover,tools/list, andtools/callHTTP endpoints without adding runtime dependencies. - Cloudflare Python Workers —
Night.cloudflare_fetch()bridges Workers Requests into Night, whileNight.cloudflare_rpc()exposes the same@app.rpc(...)registry over Workers RPC/Service Bindings. Cloudflare-specific imports stay optional outside Workers. - Vercel Functions — Vercel's Python runtime accepts Night directly as an ASGI
app; no request/response adapter is needed. - Browser Night — run Night entirely in a browser tab with Pyodide; a service worker persistently caches versioned Pyodide runtime assets after the first load.
MCP
from night import Night
from night_mcp import enable_mcp
app = Night()
mcp = enable_mcp(app)
@mcp.tool(description="Add two integers")
def add(a: int, b: int):
return {"value": a + b}
Existing @app.rpc(...) methods are also visible as MCP tools. The first implementation targets the stateless MCP 2026-07-28 core with server/discover, tools/list, tools/call, header/body validation, cache hints, and server metadata.
See the MCP guide.
Cloudflare Workers
The repository contains a working Python Workers template under deploy/cloudflare-night.
from night import Night
from workers import WorkerEntrypoint
app = Night()
@app.get("/")
def index():
return {"hello": "edge"}
class Default(WorkerEntrypoint):
async def fetch(self, request):
return await app.cloudflare_fetch(request)
Night uses the official workers-runtime-sdk conversion layer for Workers RPC values. See the Cloudflare Workers guide.
Vercel Functions
Vercel's Python runtime can serve Night directly because Night exposes a standard ASGI app.
from night import Night
app = Night()
@app.get("/")
def index():
return {"hello": "vercel"}
A ready-to-copy template lives in deploy/vercel-night. See the Vercel deployment guide.
Browser Night
Night can run entirely in the browser through Pyodide and the night_web adapter. No Python server is required: routes execute inside the tab and Web-style requests are bridged into the same Night application.
from night import Night, send_file
app = Night().gz()
app.get("/hello", lambda: {"hello": "browser"})
app.get("/data", send_file("data.json"))
The GitHub Pages demo lives under deploy/browser-night. Its service worker caches only versioned Pyodide CDN assets (.mjs, .wasm, package metadata, and packages such as sqlite3) in Cache Storage, so later starts can reuse the runtime without freezing Night's own source updates. See the Browser Night guide.
Documentation
- Documentation index
- Quickstart
- HTTP guide
- Browser Night / Pyodide
- MCP
- Cloudflare Workers
- Vercel Functions
- Deployment
- API reference
- 日本語ドキュメント
For coding agents and automated tooling, see SKILL.md.
Version
Current PyPI release: 0.1.2.
Night is alpha software. Features merged after the latest PyPI release may exist on main before the next package publication. Benchmark numbers in this repository are development measurements; in-process test clients do different bookkeeping and should not be treated as production HTTP throughput results.
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 all_night-0.1.2.tar.gz.
File metadata
- Download URL: all_night-0.1.2.tar.gz
- Upload date:
- Size: 46.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0f79127fcdc0de6ea266809a0d2813e5a6d2bd74f050530cc31574af282ec34
|
|
| MD5 |
e624ab6d65b5dcbea5dd8b2afbe25c0d
|
|
| BLAKE2b-256 |
ac91b6e09628e347cf6037e2eccd490476d9f4009a8ace7c26a077d4b92ac04f
|
File details
Details for the file all_night-0.1.2-py3-none-any.whl.
File metadata
- Download URL: all_night-0.1.2-py3-none-any.whl
- Upload date:
- Size: 41.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
122897439a8295f350fd7c8d349e33cef43a9d9c9561d378938ec328e4f19b15
|
|
| MD5 |
e32ccff66161a06210e334a6dbdac2da
|
|
| BLAKE2b-256 |
de4659e8227b0a7d5643aad2112ede987e6c6d004c3b355bc647c3d3bb0f5a7a
|