Korvex
A fast router for Python, written in Rust, with an ASGI app on top and a built-in server to run it.
Korvex is young (alpha). It's fast (see Performance), but it lacks some of what full frameworks offer: validation, OpenAPI. The roadmap lists what's coming.
pip install korvex
The router
Router maps a path and an HTTP method to a handler name. It never
calls your code: what you do with the name is up to you.
from korvex import Router
router = Router()
router.get("/users/{id:int}", "get_user")
router.post("/users", "create_user", middleware=["auth"])
router.match("/users/42") # ("get_user", {"id": 42}, ())
router.match("/users", "POST") # ("create_user", {}, ("auth",))
router.match("/nope") # None
router.match("/users", "DELETE") # raises MethodNotAllowed, .allowed == ["POST"]
Path syntax
| Segment | Matches | Example |
|---|---|---|
users |
exactly users |
/users |
{id} |
any segment | /users/{id} |
{id:int} |
an integer (42, -7) |
/users/{id:int} |
{id:uuid} |
a UUID | /items/{id:uuid} |
*path |
the rest of the path (last segment) | /static/*path |
{id:int} gives an int and {id:uuid} a uuid.UUID; every other
captured value is a string. When several routes could match,
the most specific one wins: literal, then {id:int}/{id:uuid}, then
{id}, then *path.
API
| Method | Does |
|---|---|
route(path, handler, *, method="GET", middleware=None) |
Registers a route (replaces an existing one). |
get / post / put / patch / delete / head / options(path, handler, *, middleware=None) |
Shortcuts for route. |
match(path, method="GET") |
(handler, params, middleware), None, or raises MethodNotAllowed. |
remove(path, method="GET") |
Removes a route by its pattern. Returns whether it existed. |
routes() |
Every route as (path, method, handler, middleware). |
group(prefix, *, middleware=None) |
A RouteGroup (see below). |
Invalid paths or methods raise ValueError.
match keeps the last 1,024 distinct lookups in a cache, and adding or
removing a route clears it. Its results are shared between calls, so they
are immutable: params is a read-only mapping and middleware a tuple.
Route groups
api = router.group("/api", middleware=["auth"])
api.get("/users", "list_users") # GET /api/users, middleware ("auth",)
admin = api.group("/admin", middleware=["admin"])
admin.get("/stats", "stats") # GET /api/admin/stats, middleware ("auth", "admin")
The ASGI app
App runs the matched handler for you. Serve it with any ASGI server
(uvicorn, hypercorn, granian...).
from korvex import App, Response
app = App()
@app.get("/users/{id:int}", middleware=["auth"])
async def get_user(request, id):
return Response.json({"id": id})
@app.middleware("auth")
def auth(request):
if request.headers.get("Authorization") is None:
return Response.text("Unauthorized", status=401) # stops here
return None # carries on
pip install "korvex[serve]" # installs uvicorn
uvicorn mymodule:app
- Handlers receive the
Requestplus path params as keyword arguments, and return aResponse. Middleware returns aResponseto answer early, orNoneto continue. Both can be sync or async. Requesthasmethod,path,headers,query_params,path_params,cookies,client((host, port)),scheme, andawait request.body(),await request.json(),await request.form(). A form maps each field to its values; files from a multipart form areUploadedFiles (filename,content_type,data). A body that can't be parsed is answered with a 400.Response(body, status=, headers=),Response.text(...),Response.json(...),Response.redirect(...), andresponse.set_cookie(...)/response.delete_cookie(...).Response.stream(chunks)sends a body piece by piece, from a sync or async generator.Response.file(path, filename=None)sends a file in chunks (withfilename, as a download).app.static("/static", "public")serves a directory; paths that leave it get a 404.HEADrequests are answered by theGETroute, without the body.- Unknown paths get a 404; known paths with the wrong method get a 405
with an
Allowheader. @app.before_requestruns before every request, ahead of routing (so for unknown paths too), and returns aResponseto answer right away orNoneto carry on.@app.after_requestgets every response, errors included, and returns the one to send (orNoneto keep it).raise HTTPException(404, "user not found")in a handler or middleware answers with that error.@app.exception_handler(404)(a status) or@app.exception_handler(ValueError)(an exception class) customizes the response. Any other exception gives a 500 and is logged to thekorvexlogger.app.group(prefix, middleware=[...])works likerouter.group(), with decorators:api = app.group("/api"), then@api.get("/users"). Groups nest.- Routes registered on
app.routerdirectly are linked to a function with@app.handler("name"). @app.on_startupand@app.on_shutdownrun a function (sync or async) when the server starts and stops, for example to open and close a database pool. Shutdown hooks run in reverse order. If a startup hook raises, the server doesn't start. Both@app.on_startupand@app.on_startup()work.
WebSockets
@app.websocket("/ws/{room}")
async def chat(ws, room):
if ws.cookies.get("session") is None:
await ws.close(code=1008) # before accept: refuses it (403)
return
await ws.accept()
async for message in ws: # text or bytes, until the client leaves
await ws.send_text(f"{room}: {message}")
- A
WebSockethas the handshake'sheaders,cookies,query_params,path_params,clientandscheme;accept(subprotocol=...),receive()(raisesWebSocketDisconnect),receive_text/bytes/json,send_text/bytes/jsonandclose(code). - They work the same under ASGI servers and in the built-in server. Groups
support them (
api.websocket(...)); app hooks don't run for them.
Ready-made hooks
korvex.middleware registers hooks for common jobs:
from korvex.middleware import cors
cors(app, allow_origins=["https://example.com"], allow_credentials=True)
cors(app, allow_origins=..., allow_methods=..., allow_headers=..., allow_credentials=False, expose_headers=(), max_age=600)lets browsers call the app from other origins. Preflight requests are answered before routing; every response to an allowed origin, errors included, gets the CORS headers.request_id(app, header="X-Request-ID", trust_incoming=True)gives every request an ID (the incoming one if it's safe, a new one otherwise) and sends it back.current_request_id()returns it anywhere in your code,RequestIdFilteradds it to log records (%(request_id)s), and the built-in server's access logs show it.rate_limit(app, requests=100, per=60, key=...)allows each key (the client's address by default, or an API key, a user ID...) that many requests per period; beyond that, a 429 withRetry-After. Responses carryRateLimit-Limit,RateLimit-RemainingandRateLimit-Reset. Counters live in each worker's memory, so with 3 workers a client can get up to 3 times the limit;store=takes a shared store instead.
More in examples/. To put it in production (behind nginx or
Caddy, in Docker, on AWS Lambda or Vercel), see the
deployment guide.
The built-in server
Korvex can run an App without an ASGI server, on Linux and macOS. On the
same CPU cores, it serves 20 to 36% more requests than uvicorn with about
40% less memory (see Performance).
korvex run main:app --workers 3
or, from Python, app.run(workers=3). The same options exist in both:
| Option | Default | Does |
|---|---|---|
--host, --port |
127.0.0.1, 8000 |
Address to listen on. |
--uds PATH |
Listen on a Unix socket instead, for a proxy on the same machine. | |
--workers N |
1 |
Processes sharing the port. About 3 per 4 CPU cores works best. A worker that crashes is restarted. |
--graceful-timeout S |
30 |
On Ctrl+C or SIGTERM, seconds requests in progress get to finish. |
--max-body BYTES |
1 MiB | Larger request bodies get a 413, larger WebSocket messages close the connection. A route can set its own: @app.post("/upload", max_body=50_000_000). |
--timeout S |
30 |
Seconds a client gets to send the headers, then the body (408 after that). |
--forwarded-allow-ips |
127.0.0.1,::1 |
Proxies whose X-Forwarded-For and X-Forwarded-Proto set request.client and request.scheme. * trusts any. |
--access-log |
off | Log each request. |
How it works: a Rust thread per worker reads each request in full, without touching Python, then hands it to the asyncio loop, which runs your handlers. A slow or huge upload never holds a Python worker.
Things to know:
- Run it behind a reverse proxy (nginx, Caddy, Traefik) in production: it speaks HTTP/1.1 and WebSocket; HTTPS, HTTP/2 and HTTP/3 are the proxy's job.
- The 413 and 408 errors are answered by the server itself, before your
app sees the request, so
@app.exception_handlerdoesn't apply to them. - The
Appis still a plain ASGI app: uvicorn, Granian or a serverless platform keep working, and Windows needs one of them.
Performance
Servers
The same app, served by each server on the same 4 CPU cores, each with its best number of workers:
| Server | Requests/s, 200 clients | 1,000 clients | RAM |
|---|---|---|---|
| Korvex built-in (3 workers) | 126.4k | 130.5k | 113 MB |
| Granian + Korvex app (3 workers) | 111.6k | 113.4k | 196 MB |
| uvicorn + Korvex app (4 workers) | 105.0k | 96.3k | 196 MB |
| Robyn (4 processes, 2 threads each) | 90.3k | 81.9k | 228 MB |
- Granian is a Rust ASGI server too: it does better than uvicorn here, but the built-in server still leads, because it skips the ASGI layer.
- Robyn runs its own version of the app with its own Rust server.
- No request failed.
Reproduce with uv run python benches/servers.py (needs cargo install oha,
takes about 4 minutes).
Under load
The same small app (1,000 routes, one JSON endpoint) in each framework, served the same way (uvicorn, one worker, one CPU core) and flooded with requests to random URLs by oha:
| Framework | Requests/s, 200 clients | p99 latency, 1,000 clients | RAM at rest, peak |
|---|---|---|---|
| Korvex | 33.7k | 26 ms | 35 MB, 46 MB |
| Starlette | 3.0k to 30.6k | 35 to 189 ms | 39 MB, 49 MB |
| Falcon | 30.5k | 31 ms | 60 MB, 63 MB |
| Litestar | 18.2k | 79 ms | 78 MB, 89 MB |
| Sanic | 15.8k | 94 ms | 60 MB, 105 MB |
| FastAPI | 1.6k to 12.4k | 57 to 351 ms | 66 MB, 77 MB |
| BlackSheep | 6.7k | 70 ms | 51 MB, 59 MB |
| Django | 1.1k to 2.2k | 1.3 to 1.9 s | 48 MB, 145 MB |
- Every framework uses a full CPU core under load, so requests per second is also how much work each one gets out of that core.
- Falcon, and Starlette in its best case, come within about 10% of Korvex.
- Starlette, FastAPI and Django try routes one by one: the ranges go from the tested route declared after the 1,000 others to declared first. BlackSheep tries them one by one too, but sorts them itself, deepest first, so here the tested route always comes last.
- No request failed. Throughput holds steady as clients are added; latency grows because requests queue, not because each one gets slower. After the flood, memory stays flat and speed is back to normal.
Robyn isn't in this table, since it can't run on uvicorn: it's compared with Korvex's built-in server above.
Reproduce with uv run python benches/load_test.py (needs
cargo install oha, takes about 11 minutes).
Router alone
Route matching only, without any server:
Median time per lookup, 10,000 routes:
| Router | First time a URL is seen | Same URL again (cached) |
|---|---|---|
| Korvex | 347 ns | 67 ns |
| Litestar | 732 ns | 92 ns |
| Sanic | 3.5 µs | 211 ns |
| Flask | 3.5 µs | (no cache) |
| Django | 1.3 ms | (no cache) |
| Starlette / FastAPI | 1.5 ms | (no cache) |
- Korvex is the fastest in both cases, and its time stays flat as routes are added. Django and Starlette try routes one by one, so they slow down linearly.
- Korvex, Litestar and Sanic cache the last 1,024 lookups. The cache helps
most with static URLs; URLs with parameters (
/users/1,/users/2, ...) are often different, so they hit it less. - With few routes, the server and the handler cost more than the router. With many routes, a router that tries them one by one becomes the main cost (see Under load).
Reproduce with uv run pytest benches/bench_router.py --benchmark-only --benchmark-json=benches/results.json, then uv run python benches/plot.py
to redraw both charts. Results depend on the machine: measure your own
workload before relying on any number.
Development
uv run maturin develop --release # build the Rust extension
uv run pytest # Python tests
cargo test # Rust tests
See CONTRIBUTING.md, and ROADMAP.md for what's planned.
License
Metadata
Release files for korvex 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| korvex-0.6.0.tar.gz | 291.9 kB | With provenance | Details for korvex-0.6.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| korvex-0.6.0-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details for korvex-0.6.0-cp39-abi3-win_amd64.whl |
| korvex-0.6.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details for korvex-0.6.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| korvex-0.6.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ ARM64 | Details for korvex-0.6.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| korvex-0.6.0-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details for korvex-0.6.0-cp39-abi3-macosx_11_0_arm64.whl |
| korvex-0.6.0-cp39-abi3-macosx_10_12_x86_64.whl | CPython 3.9 | abi3 | macOS 10.12+ x86-64 | Details for korvex-0.6.0-cp39-abi3-macosx_10_12_x86_64.whl |
Total release size: 3.6 MB
Release files / korvex-0.6.0.tar.gz
| Download URL | korvex-0.6.0.tar.gz |
|---|---|
| Size | 291.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
586e00774a8b34a62d4f01c4a9c88dbc2eb3265ed9bdf59c358c4f0f6a47fab7
|
|
BLAKE2b-256 checksum How to use checksums |
891ea877d2b37d882b03f25e870febb5ab1eda2d180d153026e07dd9ebb97376
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / korvex-0.6.0-cp39-abi3-win_amd64.whl
| Download URL | korvex-0.6.0-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 199.0 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
be007ab8cc7096f545d62ec429a5b3f0230a56600ece57114838d5459ff1c54a
|
|
BLAKE2b-256 checksum How to use checksums |
043a5ca4207b1289e5d3227246b87e87bd35ac2b9c2d28cd720ffe867d1b9736
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / korvex-0.6.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | korvex-0.6.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 822.5 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f660c2e3d5bda899d25da7676591c80e0e5ef4f42d5b248c4053e5002456b105
|
|
BLAKE2b-256 checksum How to use checksums |
9103fbfa521ef15df5b60ecec73e29c416297ecedb81c001919dab9a215053ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / korvex-0.6.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | korvex-0.6.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 824.6 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
91e39dd8ed22ba9d4d2a3b2655636055648114a5873026eacd6e898034d06dbe
|
|
BLAKE2b-256 checksum How to use checksums |
52e4abced0c79b690ab07a1aa79e9d32e1eb9435ed7f3159dbba0b3fb61143c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / korvex-0.6.0-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | korvex-0.6.0-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 740.1 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8bb6ce663543f85cc601e06694cc6b67bfa5d4af4f6c4f839c081aaa03150d2b
|
|
BLAKE2b-256 checksum How to use checksums |
8a953cbf09aa7d3a1b570fc143d6f1ce6f712a20961a75703641b986fe8faf6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / korvex-0.6.0-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | korvex-0.6.0-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 745.1 kB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
37d17744d6c5c0a5572e457a0c41f786d69fb411e45edbda1b4d8ceff4fc79b1
|
|
BLAKE2b-256 checksum How to use checksums |
c9d42e211275f1d54fbcffda96b2ea6c1485ebfd3ea28f8fef147581c82073b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logSecurity for korvex 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 6 files in this release have been uploaded with provenance metadata.
Attestation for korvex-0.6.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.