As everyone has mentioned http.server module is equivalent to python -m SimpleHTTPServer
.
But as a warning from https://docs.python.org/3/library/http.server.html#module-http.server
Warning:
http.server
is not recommended for production. It only implements basic security checks.
http.server can also be invoked directly using the -m
switch of the interpreter.
python -m http.server
The above command will run a server by default on port number 8000
. You can also give the port number explicitly while running the server
python -m http.server 9000
The above command will run an HTTP server on port 9000 instead of 8000.
By default, server binds itself to all interfaces. The option -b/--bind specifies a specific address to which it should bind. Both IPv4 and IPv6 addresses are supported. For example, the following command causes the server to bind to localhost only:
python -m http.server 8000 --bind 127.0.0.1
or
python -m http.server 8000 -b 127.0.0.1
Python 3.8 version also supports IPv6 in the bind argument.
By default, server uses the current directory. The option -d/--directory
specifies a directory to which it should serve the files. For example, the following command uses a specific directory:
python -m http.server --directory /tmp/
Directory binding is introduced in python 3.7