Sanic-Routing is the standalone, high-performance core routing component used by the Sanic web framework. It handles URL parsing, route matching, and parameter extraction, providing a flexible and efficient routing engine. The library maintains an active development pace with frequent updates, typically releasing new versions quarterly.
pip install sanic-routingVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `Router`, add various types of routes (simple, string parameter, path parameter), and then perform route lookups using `router.get()`. It also shows how to handle `NotFound` exceptions for non-existent routes.
Ensure your routes explicitly handle empty string segments if that was desired behavior, or update path definitions to be more specific (e.g., using `/<user_id:uuid>` for UUIDs) and avoid matching empty string segments.
Update route definitions to use the new parameter types: change `<foo:string>` to `<foo:str>` and `<foo:number>` to `<foo:float>`.
Be mindful of how URI parameters are handled and explicitly decode them if necessary, particularly if you rely on parameters always being fully unquoted before processing. For standard string casts via `<param:str>`, unquoting should still occur.
No dependency data recorded yet.