Skip to main content

ServeStatic

Website


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-Encoding and Vary headers
  • 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 ServeStatic .

Frequently Asked Questions

Isn't serving static files from Python horribly inefficient?

The short answer to this is that if you care about performance and efficiency then you should be using ServeStatic behind a CDN (such as CloudFront). Due to the caching headers ServeStatic sends, the vast majority of static requests will be served directly by the CDN without touching your application, so it really doesn't make much difference how efficient ServeStatic is.

That said, ServeStatic is pretty efficient. Because it only has to serve a fixed set of files it does all the work of finding files and determining the correct headers upfront on initialization. Requests can then be served with little more than a dictionary lookup to find the appropriate response. Also, when used with a file_wrapper compatible WSGI server (e.g. gunicorn) or zerocopysend/pathsend compatible ASGI server (e.g. granian, anycorn, nonecorn) the actual business of pushing the file down the network interface is handled by the kernel's very efficient sendfile syscall, not by Python.

Shouldn't I be pushing my static files to S3 (using Django-Storages)?

A push-based approach adds complexity and fragility to your deployment process: extra libraries specific to your storage backend, extra configuration and authentication keys, and extra tasks that must be run at specific points in the deployment in order for everything to work. With the CDN-as-caching-proxy approach that ServeStatic takes there are just two bits of configuration: the URL of the CDN, and the URL of your application. Everything else is just standard HTTP semantics. This makes your deployments simpler, your life easier, and you happier.

What's the point in ServeStatic when I can use apache/nginx?

There are two answers here. One is that ServeStatic is designed to work in situations where apache, nginx, and the like aren't easily available. But more importantly, it's easy to underestimate what's involved in serving static files correctly. Does your few lines of nginx configuration distinguish which files which will never change and set the cache headers appropriately? Did you add the right CORS headers so that your fonts load correctly when served via a CDN? Did you turn on the special nginx setting which allows it to send gzip content in response to an HTTP/1.0 request? Did you install, enable, and configure support for zstd and brotli compression?

None of this is rocket science, but it's fiddly and annoying and ServeStatic takes care of all it for you.


This project is a fork of WhiteNoise for ASGI support, bug fixes, security updates, new features, and performance upgrades.

Metadata

Release files for servestatic 4.4.1

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

Source distribution (sdist)

Source distribution for servestatic 4.4.1
File Size Uploaded Provenance Actions
servestatic-4.4.1.tar.gz 36.9 kB With provenance Details for servestatic-4.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for servestatic 4.4.1
File Interpreter ABI Platform Actions
servestatic-4.4.1-py3-none-any.whl Python 3 none any Details for servestatic-4.4.1-py3-none-any.whl

Total release size: 80.7 kB

Release files / servestatic-4.4.1.tar.gz

Download URL servestatic-4.4.1.tar.gz
Size 36.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c2fc2705999a612e8efc759d6a05ee9266f2ae82befd4f33056522f43cbb733a
BLAKE2b-256 checksum
How to use checksums
6eece1ccefa0486275259f19e211ad537db666563764ccd5966a8579de691725
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / servestatic-4.4.1-py3-none-any.whl

Download URL servestatic-4.4.1-py3-none-any.whl
Size 43.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
89bc3147387d3a6f06c905d6e2a859a8fec051131614795ce62f63918de7c4c4
BLAKE2b-256 checksum
How to use checksums
17447829f23919345ad2e7c05ff2bdec16ca124c122d0fae403910f5af1294f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Security for servestatic 4.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for servestatic-4.4.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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