aiohttp-fast-url-dispatcher
Documentation: https://aiohttp-fast-url-dispatcher.readthedocs.io
Source Code: https://github.com/bdraco/aiohttp-fast-url-dispatcher
A faster URL dispatcher for aiohttp
The default UrlDispatcher
implementation does a linear search every which can have a significant TimeComplexity when dispatching urls when there are a lot of routes. FastUrlDispatcher
keeps an index of the urls which allows for fast dispatch.
This library will become obsolete with aiohttp 3.10 as the changes
are expected to merge upstream via https://github.com/aio-libs/aiohttp/pull/7829
Installation
Install this via pip (or your favourite package manager):
pip install aiohttp-fast-url-dispatcher
Usage
Attach to a web.Application
before any resources are registered.
dispatcher = FastUrlDispatcher()
app = web.Application()
attach_fast_url_dispatcher(app, dispatcher)
Create with a new web.Application
dispatcher = FastUrlDispatcher()
app = web.Application(router=dispatcher)
Caveats
If you have multiple handlers that resolve to the same URL, this module will always prefer the static name over a dynamic name. For example:
app.router.add_get(r"/second/{user}/info", handler)
app.router.add_get("/second/bob/info", handler)
"/second/bob/info"
will always be matched before r"/second/{user}/info"
Contributors ✨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
Credits
This package was created with
Copier and the
browniebroke/pypackage-template
project template.