Skip to content
Related Articles

Related Articles

Setting up a simple HTTP server using Python

View Discussion
Improve Article
Save Article
  • Last Updated : 02 Sep, 2020
View Discussion
Improve Article
Save Article

In this article, we are going to learn how to set up a simple and local HTTP server using Python. An HTTP server can be very useful for testing Android, PC or Web apps locally during development. It can also be used to share files between two devices connected over the same LAN or WLAN network.


On the terminal run the following statement:

python3 -m http.server


python -m http.server
The python3 server command

Python3 server command

Accessing the server locally

For accessing the server locally you need to visit http://localhost:8000/. Here you can see all the directories of your local storage along with all the data. You can also access an HTML page, It will be rendered by your web browser as you access it.

The localhost Page

The localhost page

Accessing the server over a Network

Before going into application make a note that the device on which you have run the above commands is called a Server or a Host and the second device that you will be using to access the Server over the network is called Client. For accessing the server over a Network make sure that both the device(Server and the Client) are connected over the same LAN or WLAN network. To access the Server you need the IP address of the server.

For obtaining the IP address the following steps are to be followed on your Server device:

On the Windows command prompt, execute the following statement:


On the Linux, Unix or macOS terminal, execute the following statement:


Note the IP address returned by the above command. We will use this IP address further.

ifconfig command

The result of ‘ifconfig’ command in Linux.

Once you know the IP address open any web browser on the Client device and type in the IP address of the first machine(Server device), along with port 8000: http://[ip address]:8000

Congratulations!! Now you know how to host a simple HTTP server using Python.

Note: This HTTP server has limited security only so use it only for development purposes or sharing files locally it’s not recommended for use over a production environment.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!