bdraco / aiohttp-fast-url-dispatcher

A faster URL dispatcher for aiohttp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aiohttp-fast-url-dispatcher

CI Status Documentation Status Test coverage percentage

Poetry black pre-commit

PyPI Version Supported Python versions License


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 aio-libs/aiohttp#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.

About

A faster URL dispatcher for aiohttp

License:Apache License 2.0


Languages

Language:Python 96.1%Language:JavaScript 3.9%