A more traditional web server in Python
MiniPyP (pronounced mini·pipe
) is an event-driven web server written in pure Python. However, MiniPyP is not an application framework. It's a full web server, with virtual hosts, reverse proxies, and everything else you need. MiniPyP can replace Apache or NGINX entirely, but can also be used behind a reverse-proxy using TCP/IP or UNIX sockets.
MiniPyP has some more advanced features right out of the box, too. For example, when a user goes to /some/url
on your server, and the directory's static
option is set to False (default), the server will look for the file /some/url
. If it doesn't exist, but the file /some
does, that file will be served. Extensions do not need to be specified with the static
option set to False. In addition, if a file does not exist but a file named catchall
exists, it will be served instead of a 404. This makes creating a single-page application that much more elegant.
First, install MiniPyP via pip.
pip install minipyp
To start a server within a Python program, specify a config like so (you may alternatively give a file location as the config
):
from minipyp import MiniPyP
config = {
'host': '0.0.0.0',
'port': 80,
'root': '/var/www/html',
'timeout': 15,
'error_pages': {
404: {
'html': '<p>The file <code>{uri}</code> could not be found.</p>'
}
}
}
MiniPyP(config=config).start()
You may also start a server via the command line. Unless specified, the config will be created and loaded from /etc/minipyp/minipyp.conf
on Mac/Linux and %APPDATA%\MiniPyP\minipyp.conf
on Windows.
minipyp start [-c CONFIG]
To create a page (e.g. 'https://mysite.com/test'), create a file called test.py
in mysite.com's root with the following:
def render(server, request):
return '<p>You requested the page <code>' + request.uri + '</code>.</p>'
See the full documentation at https://minipyp.readthedocs.io