A Python HTTP server for serving static content

A Python HTTP server for serving static content

Python has a built-in HTTP server which can be used to serve static content on the local machine or in the local network. It is just a plain web server. Obviously, it does not support server-side scripting.

It turns out that even such a primitive tool can be useful sometimes. When did I use it?

When I had documentation in the form of a web page and wanted to share it conveniently with someone who was connected to my home network without bothering to find a web hosting. After all, I needed it only for a few minutes.

It was also helpful when I had a script to build a static web page and wanted to test the result.

How to run it?

python -m http.server <port number>

for example:

python -m http.server 8080

It will serve the content from the current directory.

Important note: it must not be used in production or when the machine is connected to public networks because it is not very secure.

Remember to share on social media!
If you like this text, please share it on Facebook/Twitter/LinkedIn/Reddit or other social media.

If you watch programming live streams, check out my YouTube channel.
You can also follow me on Twitter: @mikulskibartosz

If you want to hire me, send me a message on LinkedIn or Twitter.

Bartosz Mikulski
Bartosz Mikulski * data scientist / software/data engineer * conference speaker * organizer of School of A.I. meetups in Poznań * co-founder of Software Craftsmanship Poznan & Poznan Scala User Group