Skip to main content

A local HTTP server for compressed content.

Project description

This Python module provides a modified version of the ThreadingHTTPServer class from the http.server module in the standard library. This server is designed to serve a static web site, such as documentation for a python project generated by Sphinx and installed with the software. It serves the files locally, on a random port of the loopback interface, and hence works off line. The server runs in its own daemon thread of the python process, so it terminates when the python program exits and thus will not leave zombie processes running.

The server has been modified to allow any file in the site to be gzip compressed and served with a Content-Encoding header set to “gzip”. The compressed file will be automatically decompressed by the browser, with no noticeable performance loss. This is more efficient than the typical case of serving compressed content over the internet since the compression is done in advance. It also takes significantly less space on the user’s disk. (Brotli compression would be even more efficient in both ways, but web browsers still tend to only support Brotli compression over https, due to the prevalence of broken proxy servers on the internet.)

Source code is available on Github. The git repository includes a script (compress_site.py) for compressing all of the .html, .css, .js, .woff and .svg files below a given site root directory. The tool is aware of Sphinx’s tendency to produce many identical copies of the same (large) _static directory. So it also collects the contents of all of the _static subdirectories into one _static directory in the root, replacing the others by symlinks.

The server can be installed by running: python3 -m pip install cocoserver.

To use the server:

>>> from cocoserver import StaticServer
>>> s = StaticServer('my/site/root')
>>> s.visit('mypage')

The pip package also installs a console script named coco which can be used to view your static site, for example by running: coco /usr/local/share/doc/myproject.

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

cocoserver-1.0.9.tar.gz (12.1 kB view hashes)

Uploaded Source

Built Distribution

cocoserver-1.0.9-py3-none-any.whl (12.7 kB view hashes)

Uploaded Python 3

Supported by

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