Question
Python 3 http.server: Equivalent of SimpleHTTPServer
Question
What is the Python 3 equivalent of the following Python 2 command for starting a simple local HTTP server?
python -m SimpleHTTPServer
Short Answer
You will learn why SimpleHTTPServer changed in Python 3 and how to start a local file server with python -m http.server. You will also see how to select a port, serve a different directory, and use the command safely during development.
Concept
In Python 2, the SimpleHTTPServer module could expose files in the current directory over HTTP:
python -m SimpleHTTPServer
In Python 3, this functionality was moved into the http.server module. The direct equivalent is:
python3 -m http.server
The command starts a small HTTP server that serves the files in your current working directory. By default, it listens on port 8000, so you can open this address in a browser:
http://localhost:8000/
This server is useful for local development, previewing static HTML files, testing browser requests, or sharing files temporarily on a trusted local network.
http.server is intentionally simple. It is not designed for production deployment because it does not provide the security, performance, logging, or configuration expected from a production web server.
Mental Model
Think of your current folder as a small public library and python3 -m http.server as the librarian at its entrance.
- The folder you start in is the library's collection.
- The server gives the collection a local web address.
- A browser visits that address and asks for a file.
- The server finds the matching file and sends it back.
For example, if the folder contains index.html, visiting http://localhost:8000/ lets the server hand that file to the browser.
Syntax and Examples
The basic Python 3 command is:
python3 -m http.server
On systems where python already means Python 3, this also works:
python -m http.server
To use a specific port, place the port number after the module name:
python3 -m http.server 8080
Then visit:
http://localhost:8080/
To serve files from a directory other than your current one, use --directory:
python3 -m http.server 8000 --directory ./public
Example workflow:
cd my-static-site
python3 -m http.server
If my-static-site contains:
index.html
styles.css
images/logo.png
the server makes those files available beneath http://localhost:8000/. A request for http://localhost:8000/styles.css returns .
Step by Step Execution
Consider this terminal session:
cd portfolio
python3 -m http.server 8000
Suppose the portfolio folder contains an index.html file.
cd portfoliochanges the terminal's current directory toportfolio.python3starts the Python 3 interpreter.-m http.servertells Python to run the built-inhttp.servermodule as a program.8000tells the module to listen on TCP port 8000.- The terminal displays a message similar to:
Serving HTTP on 0.0.0.0 port 8000 ...
- When you open
http://localhost:8000/, your browser sends an HTTP request to the server on your own computer. - The server looks in
portfoliofor a suitable file, commonlyindex.html, and returns it. - When finished, press
Ctrl+Cin the terminal to stop the server.
A browser request may produce a log line such as:
Real World Use Cases
Common uses for python3 -m http.server include:
- Previewing a static website: Open local HTML, CSS, and JavaScript through HTTP instead of directly opening an HTML file with
file://. - Testing JavaScript modules: Browser ES modules often require an HTTP origin rather than a local file URL.
- Checking API mock files: Serve JSON fixtures such as
products.jsonwhile building a frontend. - Demonstrating a prototype: Quickly let colleagues on a trusted network view static assets.
- Inspecting generated documentation: Serve a folder created by a documentation tool and navigate it in a browser.
- Testing downloads: Verify that files have the expected URLs and download behavior during local development.
Real Codebase Usage
In real projects, developers commonly run a lightweight local server as part of a development workflow.
For a simple static prototype, the built-in server can be enough:
python3 -m http.server 8000 --directory dist
Here, dist is a build output folder containing generated HTML, JavaScript, CSS, and images.
For larger applications, teams usually use framework-specific development servers instead, such as a server provided by Vite, Django, Flask, React tooling, or another build system. Those tools can add features that http.server does not provide, including:
- Automatic reload when files change
- Routing fallback for single-page applications
- API proxying
- HTTPS development certificates
- Asset transformations and bundling
Even in these projects, http.server remains convenient for quickly inspecting a directory or reproducing a static-file issue without installing dependencies.
Common Mistakes
Using the Python 2 module name in Python 3
This Python 2 command fails in Python 3 because the module was renamed:
python3 -m SimpleHTTPServer
Use this instead:
python3 -m http.server
Serving the wrong folder
The server exposes the directory where you run the command, not necessarily the folder containing your site.
# This serves the current directory, which may be the wrong one.
python3 -m http.server
Move into the intended folder first, or specify it explicitly:
python3 -m http.server --directory ./public
Forgetting the port in the browser URL
If you start the server on port 8080, this URL is incorrect:
http://localhost:8000/
Use the same port you passed to the command:
http://localhost:8080/
Expecting backend application behavior
http.server serves files. It does not run a Flask, Django, FastAPI, Node.js, or PHP application just because their source files are in the folder.
Using it as a public production server
Comparisons
| Topic | Python 2 | Python 3 |
|---|---|---|
| Module name | SimpleHTTPServer | http.server |
| Basic command | python -m SimpleHTTPServer | python3 -m http.server |
| Default port | 8000 | 8000 |
| Main purpose | Serve current-directory files | Serve current-directory files |
| Option | When to use it |
|---|---|
python3 -m http.server |
Cheat Sheet
# Python 3 equivalent of Python 2 SimpleHTTPServer
python3 -m http.server
# Use a custom port
python3 -m http.server 8080
# Serve another directory
python3 -m http.server --directory ./public
# Combine a port and directory
python3 -m http.server 8080 --directory ./public
- Default port:
8000 - Default served directory: the current terminal directory
- Local URL:
http://localhost:<port>/ - Stop the server: press
Ctrl+C - Python 2 name:
SimpleHTTPServer - Python 3 name:
http.server - Use for local development and trusted temporary sharing, not production hosting.
FAQ
What replaced SimpleHTTPServer in Python 3?
Use the http.server module:
python3 -m http.server
What port does Python's HTTP server use by default?
It uses port 8000. Open http://localhost:8000/ in a browser.
How do I run the server on port 3000 or 8080?
Pass the port as an argument:
python3 -m http.server 3000
How do I serve a specific folder with http.server?
Use --directory:
python3 -m http.server --directory ./public
Why does python3 -m SimpleHTTPServer fail?
SimpleHTTPServer is the Python 2 module name. Python 3 moved this feature to http.server.
How do I stop python3 -m http.server?
Focus the terminal running the server and press .
Mini Project
Description
Create a small static profile page and serve it locally with Python's built-in HTTP server. This demonstrates how a directory becomes a locally accessible website without installing a web framework.
Goal
Serve a static HTML page from a project folder and view it at http://localhost:8000/.
Requirements
Create a folder named profile-site.
Add an index.html file with a name, short description, and link.
Start Python's HTTP server from the project folder.
Open the page in a browser using the server URL.
Keep learning
Related questions
@staticmethod vs @classmethod in Python Explained
Learn the difference between @staticmethod and @classmethod in Python with clear examples, use cases, mistakes, and a mini project.
Add Rows to a Pandas DataFrame in Python
Learn how to add rows to a Pandas DataFrame, why repeated row appends are slow, and when to use loc, concat, or record lists.
Call a Function by Name in a Python Module
Learn how to call a function by name in a Python module using strings, getattr, and safe patterns for dynamic function dispatch.