servestatic


Nameservestatic JSON
Version 2.1.1 PyPI version JSON
download
home_pageNone
SummaryProduction-grade static file server for Python web apps.
upload_time2024-10-27 22:03:40
maintainerNone
docs_urlNone
authorMark Bakhit
requires_python>=3.9
licenseNone
keywords asgi django http server static staticfiles wsgi
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!--desc-start-->

# ServeStatic

<p>
    <a href="https://github.com/Archmonger/ServeStatic/actions?query=workflow%3ACI+branch%3Amain">
        <img src="https://github.com/Archmonger/ServeStatic/actions/workflows/ci.yml/badge.svg">
    </a>
    <a href="https://pypi.python.org/pypi/servestatic">
        <img src="https://img.shields.io/pypi/v/servestatic.svg?label=PyPI">
    </a>
    <a href="https://github.com/Archmonger/ServeStatic/blob/main/LICENSE.md">
        <img src="https://img.shields.io/badge/License-MIT-purple.svg">
    </a>
    <a href="https://archmonger.github.io/ServeStatic/">
        <img alt="Website" src="https://img.shields.io/website?url=https%3A%2F%2Farchmonger.github.io%2FServeStatic%2F&up_message=online&logo=readthedocs&logoColor=white&label=docs">
    </a>
</p>

_Production-grade static file server for Python web apps._

_A fork of [WhiteNoise](https://github.com/evansd/whitenoise) for continued [maintenance and feature updates](https://archmonger.github.io/ServeStatic/latest/changelog/)._

---

With a couple of lines of configuration `ServeStatic` allows your web app to serve its own static files, making it a self-contained unit that can be deployed anywhere without relying on nginx, Amazon S3, or any other external service. This is especially useful on Heroku, OpenShift, and other PaaS providers.

It's designed to work nicely with a CDN for high-traffic sites so you don't have to sacrifice performance to benefit from simplicity.

`ServeStatic` works with any ASGI or WSGI compatible app but has some special auto-configuration features for Django.

`ServeStatic` automatically takes care of best-practices for you, for instance:

-   Serving compressed content (gzip and Brotli formats, handling Accept-Encoding and Vary headers correctly)
-   Setting far-future cache headers on content which won't change

Worried that serving static files with Python is horribly inefficient? Still think you should be using Amazon S3? Have a look at the FAQ below.

## 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. If you're doing _that_ then, because of 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 something like 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 either the venerable gzip or the more modern brotli algorithms) can make dramatic reductions in the bandwidth required for your CSS and JavaScript. 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 do the same thing in a few lines of `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.

<!--desc-end-->

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "servestatic",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "asgi, django, http, server, static, staticfiles, wsgi",
    "author": "Mark Bakhit",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/cc/65/11fc0c32d7936212b59fccefed9d00b9b3070f700e931416ccf80f7b69a7/servestatic-2.1.1.tar.gz",
    "platform": null,
    "description": "<!--desc-start-->\n\n# ServeStatic\n\n<p>\n    <a href=\"https://github.com/Archmonger/ServeStatic/actions?query=workflow%3ACI+branch%3Amain\">\n        <img src=\"https://github.com/Archmonger/ServeStatic/actions/workflows/ci.yml/badge.svg\">\n    </a>\n    <a href=\"https://pypi.python.org/pypi/servestatic\">\n        <img src=\"https://img.shields.io/pypi/v/servestatic.svg?label=PyPI\">\n    </a>\n    <a href=\"https://github.com/Archmonger/ServeStatic/blob/main/LICENSE.md\">\n        <img src=\"https://img.shields.io/badge/License-MIT-purple.svg\">\n    </a>\n    <a href=\"https://archmonger.github.io/ServeStatic/\">\n        <img alt=\"Website\" src=\"https://img.shields.io/website?url=https%3A%2F%2Farchmonger.github.io%2FServeStatic%2F&up_message=online&logo=readthedocs&logoColor=white&label=docs\">\n    </a>\n</p>\n\n_Production-grade static file server for Python web apps._\n\n_A fork of [WhiteNoise](https://github.com/evansd/whitenoise) for continued [maintenance and feature updates](https://archmonger.github.io/ServeStatic/latest/changelog/)._\n\n---\n\nWith a couple of lines of configuration `ServeStatic` allows your web app to serve its own static files, making it a self-contained unit that can be deployed anywhere without relying on nginx, Amazon S3, or any other external service. This is especially useful on Heroku, OpenShift, and other PaaS providers.\n\nIt's designed to work nicely with a CDN for high-traffic sites so you don't have to sacrifice performance to benefit from simplicity.\n\n`ServeStatic` works with any ASGI or WSGI compatible app but has some special auto-configuration features for Django.\n\n`ServeStatic` automatically takes care of best-practices for you, for instance:\n\n-   Serving compressed content (gzip and Brotli formats, handling Accept-Encoding and Vary headers correctly)\n-   Setting far-future cache headers on content which won't change\n\nWorried that serving static files with Python is horribly inefficient? Still think you should be using Amazon S3? Have a look at the FAQ below.\n\n## Frequently Asked Questions\n\n### Isn't serving static files from Python horribly inefficient?\n\nThe short answer to this is that if you care about performance and efficiency then you should be using `ServeStatic` behind a CDN like CloudFront. If you're doing _that_ then, because of 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.\n\nThat 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.\n\n### Shouldn't I be pushing my static files to S3 using something like Django-Storages?\n\nNo, you shouldn't. The main problem with this approach is that Amazon S3 cannot currently selectively serve compressed content to your users. Compression (using either the venerable gzip or the more modern brotli algorithms) can make dramatic reductions in the bandwidth required for your CSS and JavaScript. 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.\n\nThe 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.\n\n### What's the point in `ServeStatic` when I can do the same thing in a few lines of `apache`/`nginx`?\n\nThere 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?\n\nNone of this is rocket science, but it's fiddly and annoying and `ServeStatic` takes care of all it for you.\n\n<!--desc-end-->\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Production-grade static file server for Python web apps.",
    "version": "2.1.1",
    "project_urls": {
        "Changelog": "https://archmonger.github.io/ServeStatic/latest/changelog/",
        "Documentation": "https://archmonger.github.io/ServeStatic/",
        "Homepage": "https://github.com/Archmonger/ServeStatic"
    },
    "split_keywords": [
        "asgi",
        " django",
        " http",
        " server",
        " static",
        " staticfiles",
        " wsgi"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b1d581f54010db70d7e9f2b1d74478e07edaf439359cc125b628e4ceecec46e1",
                "md5": "95bd5e8356c38169c836cfceaddeb0cf",
                "sha256": "01cc02192a7b234950da9b9c4d8290f1edfb744fff8866ce4735ae70fb95bc3e"
            },
            "downloads": -1,
            "filename": "servestatic-2.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "95bd5e8356c38169c836cfceaddeb0cf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 27242,
            "upload_time": "2024-10-27T22:03:38",
            "upload_time_iso_8601": "2024-10-27T22:03:38.587318Z",
            "url": "https://files.pythonhosted.org/packages/b1/d5/81f54010db70d7e9f2b1d74478e07edaf439359cc125b628e4ceecec46e1/servestatic-2.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cc6511fc0c32d7936212b59fccefed9d00b9b3070f700e931416ccf80f7b69a7",
                "md5": "f1cab279d3e299272eaf1e1dc71c5c6c",
                "sha256": "1aaedcfac9c8fa5123bb28fa72c0713fd073391aa0e120b60c9b713ae5ca3af2"
            },
            "downloads": -1,
            "filename": "servestatic-2.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f1cab279d3e299272eaf1e1dc71c5c6c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 23481,
            "upload_time": "2024-10-27T22:03:40",
            "upload_time_iso_8601": "2024-10-27T22:03:40.291702Z",
            "url": "https://files.pythonhosted.org/packages/cc/65/11fc0c32d7936212b59fccefed9d00b9b3070f700e931416ccf80f7b69a7/servestatic-2.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-27 22:03:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Archmonger",
    "github_project": "ServeStatic",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "servestatic"
}
        
Elapsed time: 0.39891s