Python ships with a tiny but useful tool called `http.server` (the modern name for the older `SimpleHTTPServer`). With one command you can turn any folder into a basic web server. That is enough to test a static site, share files with a phone on the same Wi-Fi, or debug an Android app over the local network. No installs, no daemons, no config.
Key facts:
- Python's built-in `http.server` module is included on most Linux and macOS systems.
- The default port is 8000.
- Local access: `http://localhost:8000/`.
- Network access: replace `localhost` with the host machine's IP.
- Not for production. No authentication, no HTTPS, minimal security.
The single command that starts it all
From the folder you want to expose, run:
- Python 3: `python -m http.server 8000`
- Python 2 (legacy): `python -m SimpleHTTPServer 8000`
The terminal prints a log line for every request. Hit `Ctrl+C` to stop the server.
Why use a local server at all?
Double-clicking an HTML file works for plain pages, but the moment you use `fetch()`, AJAX, or modules that care about origin, the `file://` protocol breaks. Browsers treat local files as cross-origin and block many common requests. Serving over `http://localhost` removes the restriction.
Who should care
- Web developers** debugging fetch calls or testing service workers that require an origin.
- Mobile developers** previewing web or Android apps on real devices without deploying.
- Teams** sharing build artifacts or datasets over a LAN without cloud storage.
- Educators** demonstrating HTTP concepts without installing Apache or Nginx.
Sharing files over the LAN
Once the server runs on your laptop, the same folder is reachable from any device on the same Wi-Fi.
- Find your IP. On Linux or macOS, run `ifconfig` or `ip a`. On Windows, run `ipconfig`.
- Note the IPv4 address, usually something like `192.168.1.42`.
- On the other device, open `http://192.168.1.42:8000/`.
- You see a directory listing and can download any file.
Change the port if you need to
Port 8000 conflicts with something else? Pass a different number:
- `python -m http.server 9779`
A worked example
Say you are building a small web app and want to test it on your phone.
- Run `python -m http.server 8000` from the project folder.
- Your laptop's IP is `192.168.1.50`.
- Open Chrome on your phone and go to `http://192.168.1.50:8000/`.
- You see the page, click around, and `fetch()` calls work.
If something breaks, the terminal shows the failing request and stack trace.
Our analysis
`http.server` trades every production feature for zero friction. No TLS, no authentication, no thread pooling, no server-side execution. This is a deliberate design, not a bug. It makes the tool instantly accessible but limits it to controlled environments.
The real trade-off is mental: many developers spin up full web servers for tasks that do not need them. Running `python -m http.server` in a project folder gives you the origin you need for testing without the config overhead. The insight is that this tool shifts the bottleneck from "how do I start a server" to "is my code correct."
What it is great for: prototyping, teaching, quick device tests, and ad-hoc file sharing. What it is bad for: anything that touches the open internet, anything with secrets, or anything that needs to stay up reliably. For production, layer Nginx or Caddy in front of your static files. The mental model transfers directly: serve a directory over HTTP, then harden from there.
Key takeaways
- `python -m http.server 8000` is the one command you need.
- Serve over `http://localhost` to unblock fetch and AJAX testing blocked by `file://` origin policies.
- Share files across the LAN by pointing another device at your IP address.
- Never expose this server publicly. It lacks auth and encryption by design.
Frequently asked questions
Is `SimpleHTTPServer` still the right name?
In Python 3, the module is `http.server`. The old `SimpleHTTPServer` name only applies to Python 2, which is end-of-life.
How do I run it on a specific port?
Pass the port as an argument: `python -m http.server 9000`.
Can I serve files over HTTPS with this tool?
Not directly. For local HTTPS, use a tool like `mkcert` with a wrapper script, or route through Caddy.
Why does my browser block requests on a `file://` page but not on `localhost`?
Browsers treat `file://` as a unique opaque origin and block most cross-origin requests. Serving over `http://localhost` gives the page a proper origin and unblocks fetch calls.