Using ServeStatic with ASGI apps¶
Tip
ServeStaticASGI inherits its interface and features from the WSGI variant.
To enable ServeStatic on an existing ASGI application, wrap it in a ServeStaticASGI instance and tell it where to find your static files. For example:
1 2 3 4 5 6 7 | |
Alternatively, you can use ServeStatic as a standalone file server by not providing a WSGI app. For example:
asgi_app = ServeStaticASGI(application=None, root="/path/to/static/files")
On initialization, ServeStatic walks over all the files in the directories that have been added (descending into sub-directories) and builds a list of available static files. Any requests which match a static file get served by ServeStatic, all others are passed through to the original application.
After configuring ServeStatic, you can use your favourite ASGI server (such as uvicorn or hypercorn) to run your application.
uvicorn my_project:asgi_app
See the API reference documentation for detailed usage and features.