Production-grade static file server for Python WSGI & ASGI.
Actively maintained. Last release 7 days ago, commits in 9 of the last 26 weeks. A safe choice.
pip install servestaticServeStatic
ServeStatic simplifies static file serving with minimal lines of configuration. It enables you to create a self-contained unit without requiring external services like Nginx or Amazon S3. This can simplify any production deployment, but is especially useful for platforms like Heroku, OpenShift, and other PaaS providers.
This project is designed to work seamlessly with CDNs to ensure high performance for traffic-intensive sites. It can be run in "standalone" mode, or alongside any preexisting ASGI/WSGI app. A command-line interface is provided to perform common tasks such as multi-format compression, file-name hashing, and manifest generation. Extra features and auto-configuration are available for Django users.
When using ServeStatic, best practices are automatically handled such as:
- Automatically serving compressed content
- Proper handling of
Accept-EncodingandVaryheaders - Setting far-future cache headers for immutable static files.
Quick Start
Here is a short example of ASGI standalone mode:
# filename: my_project.py
from servestatic import ServeStaticASGI
asgi_app = ServeStaticASGI(
application=None, # `application=None` will run ServeStatic in standalone mode.
root="/path/to/static/files",
)
Now, use any webserver CLI to serve static files. Since this example uses ASGI, here is a sample command for uvicorn (a popular ASGI webserver):
uvicorn my_project:asgi_app
Visit the documentation to get started, or learn more about .