Skip to main content

Production-grade static file server for Python WSGI & ASGI.

Project description

ServeStatic

Website

Production-grade static file server for Python WSGI & ASGI.

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


ServeStatic simplifies static file serving with minimal lines of configuration. It can operate standalone or transform your existing app into a self-contained unit, without relying on 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.

It is designed to work seamlessly with CDNs to ensure high performance for traffic-intensive sites, and is compatible with any ASGI/WSGI app. Extra features and auto-configuration are available for Django users.

Best practices are automatically handled by ServeStatic, such as:

  • Automatically serving compressed content
  • Proper handling of Accept-Encoding and Vary headers
  • Setting far-future cache headers for immutable static files.

To get started or learn more about ServeStatic, visit the documentation.

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 like 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 gunicorn (and most other WSGI servers) 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)?

No, you shouldn't. The main problem with this approach is that Amazon S3 cannot currently selectively serve compressed content to your users. Compression using the gzip or the modern brotli algorithm can make dramatic reductions in load time and bandwidth usage. But, in order to do this correctly the server needs to examine the Accept-Encoding header of the request to determine which compression formats are supported, and return an appropriate Vary header so that intermediate caches know to do the same. This is exactly what ServeStatic does, but Amazon S3 currently provides no means of doing this.

The second problem with a push-based approach to handling static files is that it 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: your application needs the URL of the CDN, and the CDN needs 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 between files which might change and 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, which for some reason CloudFront still uses? Did you install the extension which allows you to serve brotli-encoded content to modern browsers?

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

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

servestatic-4.0.0.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

servestatic-4.0.0-py3-none-any.whl (32.5 kB view details)

Uploaded Python 3

File details

Details for the file servestatic-4.0.0.tar.gz.

File metadata

  • Download URL: servestatic-4.0.0.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for servestatic-4.0.0.tar.gz
Algorithm Hash digest
SHA256 212b80d4b0d07b2ab10e2e4419ed984f5e6ec2fee61b64e9ed1d7740b3c367a5
MD5 2ee1741f9963420d1f11ada9c9b4c4ee
BLAKE2b-256 6be6cba9e145d41408d67e73eacdd3dc606317132c66bc536eb336bb3aea504d

See more details on using hashes here.

Provenance

The following attestation bundles were made for servestatic-4.0.0.tar.gz:

Publisher: ci.yml on Archmonger/ServeStatic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file servestatic-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: servestatic-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 32.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for servestatic-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78756de57908f75a08e5838306f515924c4257434bc72596b8a5c95bc7396b2b
MD5 bb1d03c4e1937b154b1abcda0726cb76
BLAKE2b-256 3f37b9a329c6fb8c77c7ff8b3119b64fcd8ee91a668fd66b24d4924ed84386d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for servestatic-4.0.0-py3-none-any.whl:

Publisher: ci.yml on Archmonger/ServeStatic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page