How to Start an HTTP Server in Python
What’s the easiest way we can start a local HTTP server in Python?
Once we’re in the terminal at the root directory of our application, we can execute either of these commands, depending on the Python version.
# Python 2 python -m SimpleHTTPServer 8000 # Python 3 python -m http.server 8000
Then, our files will be served from
For the most part, we can use any port we’d like (not just
8000). On Linux, we’ll find that ports below
1024 are privileged ports, meaning the applications listening on these ports should be privileged. They should run as root or have the
So, most ports above
1024 are fair game.
More Python Articles
- How to Get All Keys with the Highest Value in Python
- How to Check if a Tuple Exists in a List in Python
- How to Sort a List of Dictionaries By Field in Python
- How to Sort a Dictionary by Value in Python
- How to Flatten a 2D List in Python
- How to Sort a List of Tuples Based on Multiple Elements
- How to Remove Duplicates from a List in Python
- How to Set Multiple Values of a List in Python
- How to Remove the Last N Elements of a List in Python
- How to Get the ASCII Value of a Character in Python
- How to Loop Over a String in Reverse in Python
- How to Create a Two Dimensional List in Python
- How to Migrate Data from MongoDB to Elasticsearch in Python
- How to Add Key-Value to Dictionary During List Comprehension in Python
- How to Fix "datetime is not JSON serializable" TypeError in Python
- How to Remove a Key From a Dictionary in Python
- Encoding and Decoding Bytes Explained
- How to Paginate/Scroll Elasticsearch Data using Python
- How to Print Without Newline in Python 3
- How to Get the Key with the Maximum Value in Python
- List Comprehension in Python Explained Visually
- How to Check if a String Contains Another String in Python
- What is Enumerate in Python?
- What is the Difference Between List and Tuple in Python?