Python
simpleHTTPserver
Windows
setup
guide

Python SimpleHTTPServer on Windows (python -m http.server)

Codemia Knowledge Hub ·

Python's SimpleHTTPServer module serves the files in a directory over HTTP with a single command. It is part of the standard library, so there is nothing to install. In Python 3 it was merged into the http.server module, so on a current Python install that is the module you run.

It is handy for testing, sharing files on a local network, or standing up a quick web service.

Prerequisites

  1. Python installed: download it from python.org and confirm the install with python --version in the command prompt.
  2. Command prompt access: basic familiarity with running commands.

Starting the server

Step 1: Open the command prompt

Press Win + R, type cmd, and press Enter.

Step 2: Go to the directory to serve

Use cd to move into the directory you want to serve, then start the server:

bat
cd path\to\your\directory
python -m http.server 8000

On Python 2 the command is python -m SimpleHTTPServer 8000.

  • Replace path\to\your\directory with the path of the directory you want to serve. You can copy the path from Windows Explorer.
  • 8000 is the port number. Replace it with any valid port if needed.

Things to know

  • Module name: SimpleHTTPServer was the Python 2 name. In Python 3 it is part of http.server.
  • Which directory is served: the server serves the current directory by default. To serve a different one, cd into it first.
  • Port number: pick a free port (above 1024 if you don't have administrative privileges).
  • Security: the server is meant for quick, temporary use. It lacks robust security features and should not be used in production.
  • Stopping the server: press Ctrl + C in the command prompt where it is running.
  • File access: make sure the files you want to serve are in the served directory, or use relative paths to reach them.
  • Running scripts: you can run a Python script directly by going to its directory and calling python script_name.py.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms