---
title: "A Python HTTP server for serving static content"
description: "How to easily serve static content on localhost or in the local network"
author: "Bartosz Mikulski"
author_bio: "Principal AI Engineer & MLOps Architect. I bridge the gap between \"it works in a notebook\" and \"it works for 200 million users.\""
author_url: https://mikulskibartosz.name
author_linkedin: https://www.linkedin.com/in/mikulskibartosz/
author_github: https://github.com/mikulskibartosz
canonical_url: https://mikulskibartosz.name/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.