What is the Python 3 equivalent of "python -m SimpleHTTPServer"
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
In Python 2, a quick way to serve the current directory over HTTP was python -m SimpleHTTPServer. In Python 3, the equivalent command is python -m http.server, or python3 -m http.server on systems where python still points somewhere else.
The Direct Python 3 Replacement
The simplest form is:
By default, this starts a small HTTP server on port 8000 and serves files from the current working directory.
You can specify a port explicitly:
Then visit http://localhost:9000 in a browser.
The command is meant for convenience: local file sharing, static testing, and quick demos.
Why the Module Name Changed
In Python 3, several modules were reorganized or renamed during the language cleanup from Python 2. SimpleHTTPServer no longer exists as a top-level module in the same way, and its functionality lives under http.server.
That means old instructions like this:
need to be updated rather than “fixed” with package installation. The missing module is expected; the replacement is built into Python 3.
Useful Options
A few flags are worth knowing.
To bind to a specific interface:
To serve a specific directory:
Those options make the server more convenient for local development and safer when you want to limit exposure.
Start It from the Right Directory
Because http.server serves the current working directory by default, the directory you run the command from matters.
If you forget that detail, the server may appear “broken” when it is actually serving a different folder than you expected. For quick local testing, changing into the correct directory first is often clearer than relying on a longer command line.
Open It Deliberately on Shared Networks
If you bind the server to all interfaces, other machines on the same network may be able to access it.
That can be convenient for device testing, but it also means you should think about what directory you are exposing. The server is simple by design, so treat it as a convenience tool, not as a secured file-sharing system.
Know What This Server Is Good For
http.server is excellent for:
- testing static HTML, CSS, or JavaScript locally
- sharing files on a trusted local network
- quickly verifying downloaded build artifacts
- serving a directory during debugging
It is not a production web server. It lacks the hardening, performance features, and operational behavior you would expect from a real deployment stack.
If you need authentication, robust logging, HTTPS termination, or concurrency control, use a proper server rather than stretching http.server beyond its purpose.
Common Pitfalls
- Running
python -m SimpleHTTPServerunder Python 3 and assuming the module should still exist. - Forgetting which interpreter
pythonpoints to on the current machine. - Serving the wrong directory because the shell is in an unexpected working directory.
- Exposing the quick server on a network interface when it was only meant for local use.
- Treating
http.serveras a production-ready web server instead of a development convenience tool.
Summary
- The Python 3 equivalent of
python -m SimpleHTTPServerispython3 -m http.server. - The default port is
8000, but you can choose another port. - '
http.serverserves the current directory unless you specify another path.' - The module rename is normal Python 2 to 3 evolution, not a missing package issue.
- Use it for local development and quick file serving, not for production hosting.
Related reading
- What is the Python 3 equivalent of python -m SimpleHTTPServer
- What is the Python equivalent for a case/switch statement?
- What is the Python equivalent for a case/switch statement?
- What is the Python equivalent of static variables inside a function?
- What is the Python equivalent of static variables inside a function?
- What is the python keyword with used for?
- What is the Python with statement designed for?
- What is the pythonic way to detect the last element in a 'for' loop?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.