Use Python 3’s replacement for SimpleHTTPServer

Serve a local directory with python -m http.server, choose the bind address and directory explicitly, and understand its development-only scope.

Best practices
Python programming and application logging

Python 3 replaces the Python 2 SimpleHTTPServer command with http.server. For a local preview, bind it to loopback explicitly:

python3 -m http.server 8000 --bind 127.0.0.1

Open http://127.0.0.1:8000. It serves the current directory and logs requests to the terminal. Stop a foreground server with Ctrl+C.

Choose a port or directory

python3 -m http.server 8080 --bind 127.0.0.1
python3 -m http.server 8000 --bind 127.0.0.1 --directory /srv/files

The --directory/-d option is available from Python 3.7. Replace /srv/files with the directory you intend to expose.

Without --bind, the command normally listens on all interfaces. --bind 0.0.0.0 explicitly selects all IPv4 interfaces; it does not itself open a firewall or make an address reachable from another machine. Use the machine's actual address from a client, not 0.0.0.0 as the destination.

Python 2 module migrations

Python 2 name Python 3 counterpart
SimpleHTTPServer http.server
BaseHTTPServer http.server
urllib2 Primarily urllib.request and urllib.error
ConfigParser configparser
Queue queue

These are migration pointers, not a guarantee that every API is unchanged. Python 2 itself is obsolete; use a supported interpreter for new work.

Understand what the server provides

The command is useful for local testing and deliberate temporary file sharing. Modern Python's command-line server is threaded; describing it as universally single-threaded is outdated. Python 3.14 also added built-in HTTPS classes and command-line TLS options. Those additions do not turn http.server into a production application server.

The simple file-serving command does not provide application authentication. It can list directories and follows filesystem symlinks, potentially exposing files outside the selected directory through a link. Serve a directory containing only material you intend to make available, and use a production server when deployment requirements call for stronger access control and operational hardening.

FAQ

Why use python3 instead of python? Executable names vary by installation. Check python --version or python3 --version and invoke the intended Python 3 interpreter; Windows installations may use the py launcher.

Where are the access logs? The default request handler writes request messages to stderr, usually displayed in the terminal. Redirect or collect that stream if you need to retain a controlled test's output.

Can it execute a Python web application? The static-file command is not a WSGI or ASGI application runner. Use the server expected by that application's framework.

References

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting