Skip to main content

A faster URL dispatcher for aiohttp

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiohttp_fast_url_dispatcher-0.3.0.tar.gz (9.2 kB view hashes)

Uploaded Source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page