simple-sanic—A blazing fast HTTP server using Sanic

└─ 2017-11-26 • Reading time: ~1 minutes

I recently showed how one can implement something equivalent to http.server from Python in Haskell. The solution turned out to be reasonably simple, and surprisingly fast.

Unfortunately, we cannot say that http.server is fast… It works fine to serve simple files and is very convenient to use, but will quickly reach its limit when more files need to be served. To be clear, you should not use sanic or http.server in production to serve static files; nginx is a much more robust solution for that. But sometimes you need to work locally on some static files, and it makes sense to have a reasonably fast and easy way to achieve that!

I decided to go with sanic, an “Async Python 3.5+ web server that’s written to go fast”. It can be configured to behave like http.server, except much faster…

from sanic import Sanic

def main():
    app = Sanic(__name__, log_config=None)
    app.static('/', './index.html')
    app.static('/', './')

if __name__ == '__main__':

To make it even easier to use, I bundled this code into a package: simple-sanic, which is a drop-in replacement for http.server. It allows to serve the content of the current directory over http with a single command:

$ python -m simple-sanic

The package is available on Pypi and Github. To install:

$ pip install simple-sanic

You can customize the host and port as well:

$ python -m simple-sanic --help
    simple-sanic [options]
    simple-sanic -h | --help

    -p --port PORT      Specify alternate port [default: 8000]
    -b --bind ADDRESS   Specify alternate bind address [default:]
    -h, --help          Show this help message and exit.