All-Night
Night is a tiny, single-file ASGI web framework for Python 3.11+ with portable Web-runtime adapters for browsers, Node.js, and serverless platforms.
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, Vercel ASGI deployment, Node.js/Pyodide hosting, and Netlify Functions support.
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. - Node.js 22 / 24 —
night_node.mjsruns the same Night application under Node through Pyodide and Web-standardRequest/Response; both supported Node lines run in CI. - Netlify Functions — the official Node 24 template uses Netlify's modern
Request -> ResponseFunctions API and the shared Night Node adapter. - 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.
Node.js
Node.js 22 and 24 are official Night runtime targets. The shared adapter starts Pyodide once per warm Node process, loads Night and your Python application, accepts Web-standard Request objects, and returns Web-standard Response objects.
import { createNightNodeHandler } from "./night_node.mjs";
const night = createNightNodeHandler({ sourceDir: "python" });
const response = await night(new Request("https://night.local/"));
console.log(response.status, await response.text());
Install the pinned Node dependency with npm install. See the Node.js runtime guide.
Netlify Functions
The official Netlify template lives in deploy/netlify-night and targets Node.js 24. The Function itself is only a thin modern Netlify wrapper around night_node.mjs; the build vendors Night's Python sources and the application into the Function bundle.
cd deploy/netlify-night
npm install
npm run dev
See the Netlify deployment guide.
Midnight
Browser Night includes Midnight, a bidirectional Python ↔ HTML bridge for DOM events, structured DOM updates, custom events, and optional WebSocket transport. See docs/guides/midnight.md.
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
- Node.js runtime
- Netlify Functions
- 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.
Node.js and Netlify support described above can be newer on main than the current PyPI package. 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.3.tar.gz.
File metadata
- Download URL: all_night-0.1.3.tar.gz
- Upload date:
- Size: 64.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6618db4e0b3a3ca1293e639e7e16d84ba862720b3e37ba97ca9906a0ed19f36
|
|
| MD5 |
eacb9edeec74a7403b1222cd850fe0e6
|
|
| BLAKE2b-256 |
ee473283ef3887f23d48766a3f6db077175cc147fa254048597476db1b8af42d
|
File details
Details for the file all_night-0.1.3-py3-none-any.whl.
File metadata
- Download URL: all_night-0.1.3-py3-none-any.whl
- Upload date:
- Size: 55.6 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 |
0d0ee65581dc472d550dda915758208b980eed3e1ef803f68d8ee9b87ea572f9
|
|
| MD5 |
d94becc1198f46bb63376ec19ab1359e
|
|
| BLAKE2b-256 |
18648af322ad4a2b5d4ccd1dfb875f7b0c2cf41eb1baed8cd47f1a279b0f6831
|