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 want to contact me, send me a message on LinkedIn or Twitter.

Bartosz Mikulski
Bartosz Mikulski * MLOps Engineer / data engineer * conference speaker * co-founder of Software Craft Poznan & Poznan Scala User Group

Subscribe to the newsletter and get access to my free email course on building trustworthy data pipelines.