Skip to main content

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.py and 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_mcp module exposes the existing RPC registry as stateless server/discover, tools/list, and tools/call HTTP endpoints without adding runtime dependencies.
  • Cloudflare Python WorkersNight.cloudflare_fetch() bridges Workers Requests into Night, while Night.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

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

all_night-0.1.2.tar.gz (46.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

all_night-0.1.2-py3-none-any.whl (41.0 kB view details)

Uploaded Python 3

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

Hashes for all_night-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e0f79127fcdc0de6ea266809a0d2813e5a6d2bd74f050530cc31574af282ec34
MD5 e624ab6d65b5dcbea5dd8b2afbe25c0d
BLAKE2b-256 ac91b6e09628e347cf6037e2eccd490476d9f4009a8ace7c26a077d4b92ac04f

See more details on using hashes here.

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

Hashes for all_night-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 122897439a8295f350fd7c8d349e33cef43a9d9c9561d378938ec328e4f19b15
MD5 e32ccff66161a06210e334a6dbdac2da
BLAKE2b-256 de4659e8227b0a7d5643aad2112ede987e6c6d004c3b355bc647c3d3bb0f5a7a

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page