Make sure you have both pip and at
least version 3.5 of Python before starting. Sanic uses the new
syntax, so earlier versions of python won't work.
- Install Sanic:
python3 -m pip install sanic
- Create a file called
main.pywith the following code:
from sanic import Sanic from sanic.response import text app = Sanic(__name__) @app.route("/") async def test(request): return text('Hello world!') app.run(host="0.0.0.0", port=8000, debug=True)
- Run the server:
- Open the address
http://0.0.0.0:8000in your web browser. You should see the message Hello world!.
You now have a working Sanic server!