Sanic
#
Find similar titles
Structured data
- Category
- Programming
- URL
- https://github.com/channelcat/sanic
Table of Contents
Sanic #
Overview #
Sanic
is a Python 3.5 web server which is so fast. Sanic is asynchronous request handler. Meaning, we can use new async/await
syntax from Python 3.5 with making our code non-blocking and very fast.
Installation #
Sanic
like other Python packages can be installed via pip
.
$ pip install sanic
Usage example #
To figure out how to get started quickly we can write very simple example.
from sanic import Sanic
from sanic.response import json
app = Sanic()
@app.route("/")
async def test(request):
return json({"hello": "world"})
if __name__ == "__main__":
app.run(host="127.0.0.1", port=8000)
Features #
Sanic
offers these basic features like other frameworks.
- Request handling
- Routing
- Middleware
- Exceptions
- Blueprints
- Class based views
- Cookies
- Static file serving
Benchmarks #
Benchmarks have done with other Python web servers.
Server | Implementation | Requests/sec | Avg. Latency |
---|---|---|---|
Sanic | Python 3.5 + uvloop | 33,342 | 2.96 ms |
Wheezy | Gunicorn + Meinheld | 20,244 | 4.97 ms |
Falcon | Gunicorn + Meinheld | 18,972 | 5.27 ms |
Bottle | Gunicorn + Meinheld | 13,596 | 7.36 ms |
Flask | Gunicorn + Meinheld | 4,988 | 20.08 ms |
Kyoukai | Python 3.5 + uvloop | 3,889 | 27.44 ms |
Aiohttp | Python 3.5 + uvloop | 2,979 | 33.42 ms |
Tornado | Python 3.5 | 2,138 | 46.66 ms |