Skip to main content

asgi-dispatcher-middleware

Middleware to Dispatch to multiple ASGI applications, extracted from hypercorn.

Dispatch to multiple ASGI applications

It is often useful serve multiple ASGI applications at once, under differing root paths. This middleware allows multiple applications to be served on different mounts.

The DispatcherMiddleware takes a dictionary of applications keyed by the root path. The order of entry in this dictionary is important, as the root paths will be checked in this order. Hence it is important to add /a/b before /a or the latter will match everything first. Also note that the root path should not include the trailing slash.

An example usage is to to serve a graphql application alongside a static file serving application. Using the graphql app is called graphql_app serving everything with the root path /graphql and a static file app called static_app serving everything else i.e. a root path of / the DispatcherMiddleware can be setup as,

from asgi_dispatcher_middleware import DispatcherMiddleware

dispatcher_app = DispatcherMiddleware({
    "/graphql": graphql_app,
    "/": static_app,
})

which can then be served by any asgi framework,

$ hypercorn module:dispatcher_app
$ uvicorn module:dispatcher_app

See also

Release files for asgi-dispatcher-middleware 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asgi-dispatcher-middleware 1.0.0
File Size Uploaded
asgi-dispatcher-middleware-1.0.0.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for asgi-dispatcher-middleware 1.0.0
File Interpreter ABI Platform
asgi_dispatcher_middleware-1.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 12.0 kB

Release files / asgi-dispatcher-middleware-1.0.0.tar.gz

Download URL asgi-dispatcher-middleware-1.0.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
765048e09351fc0e3dface205ff0b4358e063f1b0c09ce50c5080e8d0f1560d8
BLAKE2b-256 checksum
How to use checksums
125d84dbcece5ad2fd0d61581e528530b6f7e82364a5f88dc3bff8299cf52bdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

Release files / asgi_dispatcher_middleware-1.0.0-py2.py3-none-any.whl

Download URL asgi_dispatcher_middleware-1.0.0-py2.py3-none-any.whl
Size 6.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
635a89e327912e951afedec20cbb493a6c3ba27fcf1b2bb5bc6ae72a8bf1fda4
BLAKE2b-256 checksum
How to use checksums
4075bfc08fc185e49d57f3b9b1979fe8b944d484743869c07afb27310e310c09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page