skillfed

sanic-routing

Core routing component for Sanic

sanic-routing v23.12.0 1.5M downloads/30d#3,814 on PyPI16
Permissive license MIT DORMANT released

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-routing

uv

uv add sanic-routing

poetry

poetry add sanic-routing

Installing 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

Development Status :: 4 - BetaEnvironment :: Web EnvironmentLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

URL path routing compilerAST-based route matchingdynamic path parameter routingHTTP request routing libraryroute tree compilationregex and static path routingSanic framework routing
routing-engineast-compilationsanic-internal

More Application Frameworks packages