Skip to main content

A microframework based on uvloop, httptools, and learnings of flask

Project description

Join the chat at https://gitter.im/sanic-python/Lobby Build Status PyPI PyPI version

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.

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.

Sanic is developed on GitHub. Contributions are welcome!

If you have a project that utilizes Sanic make sure to comment on the issue that we use to track those projects!

Benchmarks

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.

Server

Implementation

Requests/sec

Avg Latency

Sanic

Python 3.5 + uvloop

33,342

2.96ms

Wheezy

gunicorn + meinheld

20,244

4.94ms

Falcon

gunicorn + meinheld

18,972

5.27ms

Bottle

gunicorn + meinheld

13,596

7.36ms

Flask

gunicorn + meinheld

4,988

20.08ms

Kyoukai

Python 3.5 + uvloop

3,889

27.44ms

Aiohttp

Python 3.5 + uvloop

2,979

33.42ms

Tornado

Python 3.5

2,138

46.66ms

Hello World 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="0.0.0.0", port=8000)

Installation

  • python -m pip install sanic

To install sanic without uvloop or json using bash, you can provide either or both of these environmental variables using any truthy string like ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, ‘1’ and setting the NO_X to true will stop that features installation.

  • SANIC_NO_UVLOOP=true SANIC_NO_UJSON=true python -m pip install sanic

Documentation

Documentation on Readthedocs.

TODO

  • Streamed file processing

  • http2

Limitations

  • No wheels for uvloop and httptools on Windows :(

Final Thoughts

                 ▄▄▄▄▄
        ▀▀▀██████▄▄▄       _______________
      ▄▄▄▄▄  █████████▄  /                 \
     ▀▀▀▀█████▌ ▀▐▄ ▀▐█ |   Gotta go fast!  |
   ▀▀█████▄▄ ▀██████▄██ | _________________/
   ▀▄▄▄▄▄  ▀▀█▄▀█════█▀ |/
        ▀▀▀▄  ▀▀███ ▀       ▄▄
     ▄███▀▀██▄████████▄ ▄▀▀▀▀▀▀█▌
   ██▀▄▄▄██▀▄███▀ ▀▀████      ▄██
▄▀▀▀▄██▄▀▀▌████▒▒▒▒▒▒███     ▌▄▄▀
▌    ▐▀████▐███▒▒▒▒▒▐██▌
▀▄▄▄▄▀   ▀▀████▒▒▒▒▄██▀
          ▀▀█████████▀
        ▄▄██▀██████▀█
      ▄██▀     ▀▀▀  █
     ▄█             ▐▌
 ▄▄▄▄█▌              ▀█▄▄▄▄▀▀▄
▌     ▐                ▀▀▄▄▄▀
 ▀▀▄▄▀

Project details


Release history Release notifications | RSS feed

This version

0.5.4

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sanic-0.5.4.tar.gz (35.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sanic-0.5.4-py3-none-any.whl (43.8 kB view details)

Uploaded Python 3

File details

Details for the file sanic-0.5.4.tar.gz.

File metadata

  • Download URL: sanic-0.5.4.tar.gz
  • Upload date:
  • Size: 35.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sanic-0.5.4.tar.gz
Algorithm Hash digest
SHA256 7afcb04e5b53e9998d5a36b84284da9561bc6008cdaaa3a76195ad74549f774a
MD5 2cddcbde4fd1ff4e53db1ee1e740c916
BLAKE2b-256 ad7db5e4514a5742497c6847746619fad766ab71d954c2802c7e24695b193ba0

See more details on using hashes here.

File details

Details for the file sanic-0.5.4-py3-none-any.whl.

File metadata

File hashes

Hashes for sanic-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ac2b5d73236076c9576e59d2c9bfe06d269c56c059c0d838c863d1768e36b2bb
MD5 be5383937739abfb0d6d1d5edb492a43
BLAKE2b-256 726995c6e688cab59bc75c700585b6f48a7279467a366da240d2382f25a4df42

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page