# How to start an HTTP server in Python?

You can create an HTTP server in python using the `http.server` module.

## Starting server from the command line

To start a server from a command line, navigate to your projects directory

```bash
cd /dev/myproject
```

Then start an HTTP server using the following command:

```bash
python3 -m http.server
```

By default, this will run the contents of the directory on a local web server, on port 8000. You can go to this server by going to the URL `localhost:8000` in your web browser.

## Starting server programmatically

To start an HTTP server from within the python script, you can use `socketerserver` along with `http.server`. The `SimpleHTTPRequestHandler` class can be used in the following manner in order to create a very basic webserver serving files relative to the current directory:

```python
import http.server
import socketserver

PORT = 8000

Handler = http.server.SimpleHTTPRequestHandler

with socketserver.TCPServer(("", PORT), Handler) as httpd:
    print("serving at port", PORT)
    httpd.serve_forever()
```

This will run the contents of the directory on a local web server, on port 8000. You can go to this server by going to the URL `localhost:8000` in your web browser.