--- id: sanic-routing version: "23.12.0" license: MIT license_treatment: permissive maintenance: dormant --- # sanic-routing — Core routing component for Sanic License: permissive · Maintenance: dormant · Downloads: 1.5M/mo ## 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 ``), and regex-based paths including the special `` 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 above — 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 pip install sanic-routing uv add sanic-routing 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: unspecified - Install friction: low - Maintenance: dormant - Downloads: 1.5M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags URL path routing compiler, AST-based route matching, dynamic path parameter routing, HTTP request routing library, route tree compilation, regex and static path routing, Sanic framework routing, routing-engine, ast-compilation, sanic-internal [View on SkillFed](https://skillfed.io/packages/sanic-routing) · [View on PyPI](https://pypi.org/project/sanic-routing/)