Beginner's Guide: Running a Local Python Web Server

Beginner's Guide: Running a Local Python Web Server
Photo by Brecht Corbeel / Unsplash

Sometimes you don't need a framework — you just need to serve a folder of files, or test something quickly, without leaving your terminal. Here are three levels of “local Python web server,” from zero setup to a real minimal server.

Level 1 — Serve static files instantly

Python ships with a built-in HTTP server. From any folder:

python3 -m http.server 8000

Visit http://localhost:8000 and you'll see a directory listing of whatever folder you ran it from. No installs, no config — useful for quickly previewing a static build, sharing a file with another device on your network, or testing a downloadable asset before it goes live.

Level 2 — A minimal custom handler

If you need actual logic (not just serving files), http.server also gives you a base class to build on:

from http.server import BaseHTTPRequestHandler, HTTPServer

class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header("Content-type", "text/plain")
        self.end_headers()
        self.wfile.write(b"Hello from a plain Python server\n")

HTTPServer(("0.0.0.0", 8000), Handler).serve_forever()

This is a real HTTP server with zero dependencies — good for understanding what a framework is actually doing underneath, or for a tiny health-check endpoint you don't want to pull a dependency in for.

Level 3 — When to reach for a framework instead

http.server is single-threaded and not meant for production traffic or anything with real routing, JSON handling, or concurrency. The moment you need more than one or two routes, move to Flask for something simple and synchronous, or FastAPI for async support and automatic request validation.

pip install fastapi uvicorn
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"status": "ok"}
uvicorn main:app --reload

Rule of thumb: http.server for “I just need to serve or debug something right now,” a real framework for anything you'll keep running.

Read more