Skip to content
Please note that GitHub no longer supports your web browser.

We recommend upgrading to the latest Google Chrome or Firefox.

Learn more
Async Python 3.6+ web server/framework | Build fast. Run fast.
Python Other
  1. Python 99.1%
  2. Other 0.9%
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github add help wanted in stale.yml May 22, 2019
changelogs Bumping up version from 19.6.2 to 19.6.3 Aug 21, 2019
docker Install Python 3.5 and 3.6 on docker container Jan 24, 2018
docs fix: #1631: add common contribution guidelines and towncrier detail t… Jul 13, 2019
examples Add placement of before_server_start and after_server_stop Jun 4, 2019
sanic Merge pull request #1657 from huge-success/release-19.6.3 Aug 22, 2019
scripts feat: #1631: enable change log as part of release script Jul 24, 2019
tests Add content-type headers in response in ASGI mode Aug 11, 2019
.appveyor.yml Create requests-async based TestClient, remove aiohttp dependency, dr… Apr 30, 2019
.black.toml Create requests-async based TestClient, remove aiohttp dependency, dr… Apr 30, 2019
.coveragerc Increase testing coverage for ASGI Jun 18, 2019
.gitattributes Introduce end-of-line normalization Oct 15, 2016
.gitignore Fix #1528 (#1549) Apr 12, 2019
.travis.yml fix: #1631: add doc test for travis CI Jul 13, 2019
CHANGELOG.rst Bumping up version from 19.6.2 to 19.6.3 Aug 21, 2019
CONDUCT.md Add maintainers email address May 22, 2017
CONTRIBUTING.rst fix: #1631: add common contribution guidelines and towncrier detail t… Jul 13, 2019
LICENSE Create requests-async based TestClient, remove aiohttp dependency, dr… Apr 30, 2019
MANIFEST.in add code beautification task to makefile Dec 28, 2018
Makefile feat: #1631: enable change log as part of release script Jul 24, 2019
README.rst fix: #1631: add common contribution guidelines and towncrier detail t… Jul 13, 2019
SECURITY.md Create SECURITY.md May 23, 2019
environment.yml bump request-async version for fixing build time issue May 16, 2019
readthedocs.yml Adding readthedocs file Jan 30, 2017
setup.cfg Bumping up version from 19.6.2 to 19.6.3 Aug 21, 2019
setup.py Merge pull request #1635 from huge-success/upgrade-websockets Aug 12, 2019
tox.ini Merge pull request #1635 from huge-success/upgrade-websockets Aug 12, 2019

README.rst

Sanic | Build fast. Run fast.

Sanic | Build fast. Run fast.

Build
Docs Documentation
Package
Support
Stats

Sanic is a Python 3.6+ web server and web framework that's written to go fast. It allows the usage of the async/await syntax added in Python 3.5, which makes your code non-blocking and speedy.

Source code on GitHub | Help and discussion board.

The project is maintained by the community, for the community. Contributions are welcome!

The goal of the project is to provide a simple way to get up and running a highly performant HTTP server that is easy to build, to expand, and ultimately to scale.

Installation

pip3 install sanic

Sanic makes use of uvloop and ujson to help with performance. If you do not want to use those packages, simply add an environmental variable SANIC_NO_UVLOOP=true or SANIC_NO_UJSON=true at install time.

$ export SANIC_NO_UVLOOP=true
$ export SANIC_NO_UJSON=true
$ pip3 install --no-binary :all: sanic

Note

If you are running on a clean install of Fedora 28 or above, please make sure you have the redhat-rpm-config package installed in case if you want to use sanic with ujson dependency.

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)

Sanic can now be easily run using python3 hello.py.

[2018-12-30 11:37:41 +0200] [13564] [INFO] Goin' Fast @ http://0.0.0.0:8000
[2018-12-30 11:37:41 +0200] [13564] [INFO] Starting worker [13564]

And, we can verify it is working: curl localhost:8000 -i

HTTP/1.1 200 OK
Connection: keep-alive
Keep-Alive: 5
Content-Length: 17
Content-Type: application/json

{"hello":"world"}

Now, let's go build something fast!

Documentation

Documentation on Readthedocs.

Changelog

Release Changelogs.

Questions and Discussion

Ask a question or join the conversation.

Contribution

We are always happy to have new contributions. We have marked issues good for anyone looking to get started, and welcome questions on the forums. Please take a look at our Contribution guidelines.

You can’t perform that action at this time.