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.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file aiohttp_fast_url_dispatcher-0.3.1.tar.gz.

File metadata

File hashes

Hashes for aiohttp_fast_url_dispatcher-0.3.1.tar.gz
Algorithm Hash digest
SHA256 5a730a3872503ee5c94c65c6dee2a17b4773e022630f2557cae84f2e74ea26ed
MD5 b5827ee2719639f9c93b047d368a30e9
BLAKE2b-256 0f4a9be8071f66a46f28d599915832ed9a19b0004f2967d3a5398f0a4f29ec82

See more details on using hashes here.

File details

Details for the file aiohttp_fast_url_dispatcher-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aiohttp_fast_url_dispatcher-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f7c0040f466e599e34e5b996ae897d13463ddf34b82d15c9048e8d6c6e00412
MD5 ac6e380a31e4eb844ce32e587ff80196
BLAKE2b-256 92ad2763e6c3334e2e53bd210acec81f41499942327d6de17f1faeb221fbcee9

See more details on using hashes here.

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