Skip to main content

Korvex

CI License: MIT

A fast router for Python, written in Rust, with an optional ASGI app on top.

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

Captured values are always strings. 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.

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 Request plus path params as keyword arguments, and return a Response. Middleware returns a Response to answer early, or None to continue. Both can be sync or async.
  • Request has method, path, headers, query_params, path_params, and await request.body() / await request.json().
  • Response(body, status=, headers=), Response.text(...), Response.json(...), Response.redirect(...).
  • Unknown paths get a 404; known paths with the wrong method get a 405 with an Allow header.
  • Routes registered on app.router directly (for example through a group) are linked to a function with @app.handler("name").

More in examples/.

Performance

Time per route lookup: Korvex 372 ns, Litestar 711 ns, Sanic 3.4 µs, Flask 3.5 µs, Django 1.3 ms, Starlette 1.4 ms at 10,000 routes. With their LRU cache and repeated URLs, Litestar takes 88 ns and Sanic 210 ns.

Median time per lookup, 10,000 routes:

Router Without cache With the router's cache, same URLs repeated
Korvex 372 ns (no cache)
Litestar 711 ns 88 ns
Sanic 3.4 µs 210 ns
Flask 3.5 µs
Django 1.3 ms
Starlette / FastAPI 1.4 ms
  • Korvex does the actual matching fastest, and its time stays flat as routes are added. Django and Starlette try routes one by one, so they slow down linearly.
  • Litestar and Sanic cache the last 1,024 lookups. When the same URLs come back, that cache beats Korvex. It helps less with parameters (/users/1, /users/2, ... are all different URLs).
  • This measures routing only. In a full app, the handler and the ASGI server cost more than the router.

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 the chart. 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.

License

MIT

Metadata

Release files for korvex 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for korvex 0.2.0
File Size Uploaded Provenance Actions
korvex-0.2.0.tar.gz 134.7 kB With provenance Details for korvex-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for korvex 0.2.0
File Actions
korvex-0.2.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for korvex-0.2.0-cp39-abi3-win_amd64.whl
korvex-0.2.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.2.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
korvex-0.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for korvex-0.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
korvex-0.2.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for korvex-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
korvex-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for korvex-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 1.5 MB

Release files / korvex-0.2.0.tar.gz

Download URL korvex-0.2.0.tar.gz
Size 134.7 kB
Tags Source
SHA-256 checksum
How to use checksums
266b7e0caa00a048cb10c4218bd1f1d8b54ecf261768993c841fc511f692d605
BLAKE2b-256 checksum
How to use checksums
49d5fc24866989645cd3afe3b401394fdb937611300fa437936179a12a6b9df5
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 4, 2026.

Transparency log

Release files / korvex-0.2.0-cp39-abi3-win_amd64.whl

Download URL korvex-0.2.0-cp39-abi3-win_amd64.whl
Size 171.5 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
7e1541ac38b2f522d7e992fc09ccb29c8affa6af36f30ec4f0b7841315059b47
BLAKE2b-256 checksum
How to use checksums
c198df8f375d6a971d433a58b6f3bd7927a3c1028d55f399992d0dc4b9ac8eff
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 4, 2026.

Transparency log

Release files / korvex-0.2.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL korvex-0.2.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 318.9 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
3250264027ecdc4a3e0b7c68e13448b69b7b1935aa418fb864029be70d6bea6b
BLAKE2b-256 checksum
How to use checksums
be561e2ad74c0a5897b66bebe63e563067a93530d85cb0b5649bd5e35d133578
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 4, 2026.

Transparency log

Release files / korvex-0.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL korvex-0.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 311.9 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
627985d128c791afa63b110b87661c4ec6d18a71b1e575e5d22c75ee23a54df0
BLAKE2b-256 checksum
How to use checksums
2e9b6436d3bad4818d79c4361429c7064ecc594f03b7ba87efcec277ab4c78c3
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 4, 2026.

Transparency log

Release files / korvex-0.2.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL korvex-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Size 277.8 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
bc40797aacdc747b4e666a2224cf0fc6143acf2c8312267a244d12c2c9abe844
BLAKE2b-256 checksum
How to use checksums
4b4ed2438cf60f668dea2b54078ab720a241975584a2928f90d60f33c486d015
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 4, 2026.

Transparency log

Release files / korvex-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL korvex-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 277.6 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
211726db957ad8414bf7a7f9ef4e1d58d16183eaa7dc05db2229e9dc88cb7980
BLAKE2b-256 checksum
How to use checksums
49b1983179f5bb3540cc8a2a169dc37ebb90583ae25c984abf3c64e8a316ef68
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 4, 2026.

Transparency log

Security for korvex 0.2.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.

Select from 6 files

Attestation for korvex-0.2.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 4, 2026.

Transparency log

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

Release history Release notifications | RSS feed

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