sanic-routing
Core routing component for Sanic
What it is and what it does
Sanic-routing is a specialized routing library that takes URL path patterns and compiles them into an optimized abstract syntax tree (AST), then generates executable Python code to match incoming requests. It handles three types of routes: fully static paths (matched via key/value lookup), dynamic paths with typed parameters (like `<id:int>`), and regex-based paths including the special `<foo:path>` type that can span multiple path segments. The router groups similar routes together, arranges them into a hierarchical tree of nodes, and generates a single `find_route` function that efficiently dispatches requests without iterating through a list.
This is a low-level component designed to be subclassed for specific use cases—Sanic itself uses it for both HTTP request routing and signal routing. Most Sanic users never interact with it directly; it is embedded in the framework. External projects that need custom routing logic or want to understand how Sanic's routing works internally may subclass `BaseRouter` and customize the resolution behavior.
Use it for:
- Build a custom HTTP router for a web framework by subclassing BaseRouter and defining a get() method.
- Understand how Sanic compiles URL patterns into optimized dispatch code by inspecting router.find_route_src.
- Implement event or signal routing with dynamic parameter extraction using the same AST-based tree structure.
- Benchmark or profile route matching performance by generating and analyzing the compiled routing function.
- Extend Sanic's routing behavior for specialized path-matching rules beyond standard HTTP routing.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Sanic-routing is a low-level AST-style router that compiles URL path patterns into optimized lookup code, used internally by the Sanic web framework for request routing and signal dispatch.
No, unless you are extending Sanic's routing internals or building a custom router from scratch. This package is a low-level component intended for framework developers, not application developers. Sanic users should install Sanic itself, which includes this package as a dependency. The dormant maintenance status (last update 2023-12-31) and lack of active development make it unsuitable for new external projects.
Install
sanic-routing on PyPI
pip
pip install sanic-routinguv
uv add sanic-routingpoetry
poetry add sanic-routingInstalling sanic-routing
Before you install
Low install friction with no runtime dependencies. Maintenance is dormant—last release was 2023-12-31 and the repository has not been updated since, though it remains unarchived. Suitable for stable, embedded use within Sanic itself, but external adoption should expect no active development.
License in practice
MIT license (permissive) places no restrictions on use, modification, or distribution. Safe for commercial and proprietary projects.
Quickstart
from sanic_routing import BaseRouter
class Router(BaseRouter):
def get(self, path, *args, **kwargs):
return self.resolve(path, *args, **kwargs)
router = Router()
router.add("/", lambda: ...)
router.finalize()
route, handler, params = router.get("/", method="BASE", extra=None)
Requires subclassing BaseRouter; the router must be finalized before use. Not intended for direct end-user application.
Verify before relying
- Whether external projects commonly depend on this package or if it is primarily used as an internal Sanic dependency.
- Performance characteristics and scalability limits for large route sets.
- Compatibility with Python versions beyond 3.10 (classifiers list 3.7–3.10 only).
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 957 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,525,817/month — #3,814 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: sanic_routing-23.12.0-py3-none-any.whl
Tags
More Application Frameworks packages
FastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
textualTextual is a Python framework for building…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
mcpBuild and connect to Model Context Protocol…
permissive · top 1,000 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
repathConverts Express-style path strings (like…
permissive · top 15,000 on PyPI
aiohttp-fast-url-dispatcherReplaces aiohttp's default URL dispatcher with…
permissive · top 15,000 on PyPI
trame-routerAdds multi-page navigation to trame…
permissive · top 15,000 on PyPI
sglang-routerA high-performance Rust-based load balancer and…
permissive · top 15,000 on PyPI
semantic-routerSemantic Router routes LLM requests to…
permissive · top 15,000 on PyPI
Sanic-CorsSanic-CORS is a Sanic extension that adds…
permissive · top 15,000 on PyPI
sanic-extSanic Extensions adds OpenAPI documentation,…
permissive · top 15,000 on PyPI
jupyter-ai-routerProvides the core message routing layer for…
permissive · top 15,000 on PyPI
sanicSanic is an async Python web framework and…
permissive · top 5,000 on PyPI
nab-indexA typed PyPI Simple-API client with on-disk…
permissive · top 15,000 on PyPI