Metadata-Version: 2.4
Name: all-night
Version: 0.1.2
Summary: A tiny, single-file Flask-like ASGI web framework
Author: 22552
License: MIT
Project-URL: Homepage, https://github.com/22552/all-night
Project-URL: Documentation, https://github.com/22552/all-night/tree/main/docs
Project-URL: Repository, https://github.com/22552/all-night
Keywords: asgi,web,framework,night,mcp,serverless
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# 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.

```bash
pip install -U all-night
```

```python
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:

```bash
uvicorn app:app --reload
```

or use Night's CLI:

```bash
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 Workers** — `Night.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

```python
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](docs/guides/mcp.md).

## Cloudflare Workers

The repository contains a working Python Workers template under [`deploy/cloudflare-night`](deploy/cloudflare-night).

```python
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](docs/guides/cloudflare-workers.md).

## Vercel Functions

Vercel's Python runtime can serve Night directly because Night exposes a standard ASGI `app`.

```python
from night import Night

app = Night()

@app.get("/")
def index():
    return {"hello": "vercel"}
```

A ready-to-copy template lives in [`deploy/vercel-night`](deploy/vercel-night). See the [Vercel deployment guide](docs/operations/vercel.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.

```python
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`](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](docs/guides/browser.md).

## Documentation

- [Documentation index](docs/README.md)
- [Quickstart](docs/getting-started/quickstart.md)
- [HTTP guide](docs/guides/http.md)
- [Browser Night / Pyodide](docs/guides/browser.md)
- [MCP](docs/guides/mcp.md)
- [Cloudflare Workers](docs/guides/cloudflare-workers.md)
- [Vercel Functions](docs/operations/vercel.md)
- [Deployment](docs/operations/deployment.md)
- [API reference](docs/reference/application.md)
- [日本語ドキュメント](docs/ja/README.md)

For coding agents and automated tooling, see [`SKILL.md`](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.
