Skip to main content

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

Project description

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

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

asgi-dispatcher-middleware-1.0.0.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

asgi_dispatcher_middleware-1.0.0-py2.py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 2 Python 3

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