2016-05-26 05:52:42 +01:00
# Sanic
2016-11-11 04:11:07 +00:00
[![Join the chat at https://gitter.im/sanic-python/Lobby ](https://badges.gitter.im/sanic-python/Lobby.svg )](https://gitter.im/sanic-python/Lobby?utm_source=badge& utm_medium=badge& utm_campaign=pr-badge& utm_content=badge)
2016-10-16 12:36:36 +01:00
[![Build Status ](https://travis-ci.org/channelcat/sanic.svg?branch=master )](https://travis-ci.org/channelcat/sanic)
[![PyPI ](https://img.shields.io/pypi/v/sanic.svg )](https://pypi.python.org/pypi/sanic/)
[![PyPI ](https://img.shields.io/pypi/pyversions/sanic.svg )](https://pypi.python.org/pypi/sanic/)
2016-10-17 10:30:42 +01:00
Sanic is a Flask-like Python 3.5+ web server that's written to go fast. It's based on the work done by the amazing folks at magicstack, and was inspired by this article: https://magic.io/blog/uvloop-blazing-fast-python-networking/.
2016-10-10 00:00:09 +01:00
2016-10-17 10:30:42 +01:00
On top of being Flask-like, Sanic supports async request handlers. This means you can use the new shiny async/await syntax from Python 3.5, making your code non-blocking and speedy.
2016-10-10 00:00:09 +01:00
## Benchmarks
2016-10-17 21:04:24 +01:00
All tests were run on an AWS medium instance running ubuntu, using 1 process. Each script delivered a small JSON response and was tested with wrk using 100 connections. Pypy was tested for Falcon and Flask but did not speed up requests.
2016-10-17 10:30:42 +01:00
2016-10-10 00:00:09 +01:00
2016-10-14 11:23:48 +01:00
| Server | Implementation | Requests/sec | Avg Latency |
| ------- | ------------------- | ------------:| -----------:|
2016-10-21 08:11:52 +01:00
| Sanic | Python 3.5 + uvloop | 33,342 | 2.96ms |
2016-10-15 07:31:47 +01:00
| Wheezy | gunicorn + meinheld | 20,244 | 4.94ms |
2016-10-14 11:23:48 +01:00
| Falcon | gunicorn + meinheld | 18,972 | 5.27ms |
2016-10-16 08:50:49 +01:00
| Bottle | gunicorn + meinheld | 13,596 | 7.36ms |
2016-10-14 11:23:48 +01:00
| Flask | gunicorn + meinheld | 4,988 | 20.08ms |
2016-10-16 08:50:49 +01:00
| Kyoukai | Python 3.5 + uvloop | 3,889 | 27.44ms |
| Aiohttp | Python 3.5 + uvloop | 2,979 | 33.42ms |
2016-10-19 09:47:12 +01:00
| Tornado | Python 3.5 | 2,138 | 46.66ms |
2016-10-10 00:00:09 +01:00
2016-10-10 00:02:06 +01:00
## Hello World
2016-10-14 12:51:08 +01:00
```python
2016-10-10 00:02:06 +01:00
from sanic import Sanic
from sanic.response import json
2016-12-13 17:35:46 +00:00
2016-11-19 01:22:16 +00:00
app = Sanic()
2016-10-10 00:02:06 +01:00
2016-12-13 17:35:46 +00:00
2016-10-10 00:02:06 +01:00
@app .route("/")
async def test(request):
2016-11-01 06:35:06 +00:00
return json({"hello": "world"})
2016-10-10 00:02:06 +01:00
2016-12-14 17:36:33 +00:00
if __name__ == "__main__":
2016-12-13 17:35:46 +00:00
app.run(host="0.0.0.0", port=8000)
2016-10-10 00:02:06 +01:00
```
2016-10-10 00:00:09 +01:00
## Installation
2016-10-16 10:58:17 +01:00
* `python -m pip install sanic`
2016-10-10 00:00:09 +01:00
2016-10-14 11:23:48 +01:00
## Documentation
* [Getting started ](docs/getting_started.md )
2016-10-14 13:00:43 +01:00
* [Request Data ](docs/request_data.md )
2016-10-14 11:23:48 +01:00
* [Routing ](docs/routing.md )
2016-10-14 22:08:30 +01:00
* [Middleware ](docs/middleware.md )
2016-10-14 11:23:48 +01:00
* [Exceptions ](docs/exceptions.md )
2016-10-16 05:50:10 +01:00
* [Blueprints ](docs/blueprints.md )
2016-11-25 07:14:37 +00:00
* [Class Based Views ](docs/class_based_views.md )
2016-10-23 09:32:16 +01:00
* [Cookies ](docs/cookies.md )
2016-10-24 09:21:06 +01:00
* [Static Files ](docs/static_files.md )
2016-12-17 19:20:07 +00:00
* [Configuration ](docs/config.md )
2016-10-18 09:22:49 +01:00
* [Deploying ](docs/deploying.md )
2016-10-14 11:37:40 +01:00
* [Contributing ](docs/contributing.md )
2016-10-14 11:23:48 +01:00
* [License ](LICENSE )
## TODO:
* Streamed file processing
* File output
* Examples of integrations with 3rd-party modules
* RESTful router
2016-10-14 12:51:08 +01:00
## Limitations:
* No wheels for uvloop and httptools on Windows :(
2016-10-10 00:00:09 +01:00
## Final Thoughts:
2016-05-26 05:52:42 +01:00
2016-09-13 08:20:13 +01:00
▄▄▄▄▄
▀▀▀██████▄▄▄ _______________
▄▄▄▄▄ █████████▄ / \
2016-11-25 07:14:37 +00:00
▀▀▀▀█████▌ ▀▐▄ ▀▐█ | Gotta go fast! |
2016-09-13 08:20:13 +01:00
▀▀█████▄▄ ▀██████▄██ | _________________ /
▀▄▄▄▄▄ ▀▀█▄▀█════█▀ |/
▀▀▀▄ ▀▀███ ▀ ▄▄
▄███▀▀██▄████████▄ ▄▀▀▀▀▀▀█▌
██▀▄▄▄██▀▄███▀ ▀▀████ ▄██
▄▀▀▀▄██▄▀▀▌████▒▒▒▒▒▒███ ▌▄▄▀
▌ ▐▀████▐███▒▒▒▒▒▐██▌
▀▄▄▄▄▀ ▀▀████▒▒▒▒▄██▀
▀▀█████████▀
▄▄██▀██████▀█
▄██▀ ▀▀▀ █
▄█ ▐▌
▄▄▄▄█▌ ▀█▄▄▄▄▀▀▄
▌ ▐ ▀▀▄▄▄▀
2016-10-10 00:00:09 +01:00
▀▀▄▄▀