WSGI Server Examples
Here's a collection of examples using various WSGI servers to run a Pycnic app.
These examples assume you have an application in hello.py
with a main WSGI class called app
.
from pycnic.core import WSGI, Handler class Hello(Handler): def get(self, name="World"): return { "message": "Hello, {name}!".format(name=name) } class app(WSGI): routes = [ ("/", Hello()), ("/([\w]+)", Hello()) ]
Gunicorn
Install
pip install gunicorn
Run
gunicorn -b 0.0.0.0:8080 hello:app
uWSGI
Install
pip install uwsgi
Run
uwsgi --http 0.0.0.0:8080 --module hello:app
wsgiref
Install
pip install wsgiref
Run
First, in hello.py
add
if __name__ == "__main__": from wsgiref.simple_server import make_server print("Serving on 0.0.0.0:8080...") make_server('0.0.0.0', 8080, app).serve_forever()
Then execute that script
python ./hello.py