Skip to content
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

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add `RFC` labels to stale exclusion list (#1737) Dec 23, 2019
changelogs Release v19.12.0 (#1740) Dec 27, 2019
docker Install Python 3.5 and 3.6 on docker container Jan 24, 2018
docs Fix simple typo: viewes -> views (#1783) Feb 17, 2020
examples Reduce nesting for the sample authentication decorator (#1715) Nov 14, 2019
sanic Fix #1788 incorrect url_for for routes with hosts, added tests. (#1789) Feb 21, 2020
scripts Release v19.12.0 (#1740) Dec 27, 2019
tests Use f-strings instead of str.format() (#1793) Feb 25, 2020
.appveyor.yml Py38 tox env (#1752) Feb 5, 2020
.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 misc: bump up pytest version for fixing ci build Oct 7, 2019
.travis.yml Py38 tox env (#1752) Feb 5, 2020
CHANGELOG.rst Corrected changelog for docs move of MD to RST (#1691). Feb 11, 2020
CONDUCT.md Add maintainers email address May 22, 2017
CONTRIBUTING.rst Doc rework (#1698) Nov 14, 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 Update README re: experimental support for Windows (#1778) Feb 3, 2020
SECURITY.md Create SECURITY.md May 23, 2019
environment.yml Swap out requests-async for httpx (#1728) Dec 21, 2019
readthedocs.yml Adding readthedocs file Jan 30, 2017
setup.cfg Release v19.12.0 (#1740) Dec 27, 2019
setup.py Py38 tox env (#1752) Feb 5, 2020
tox.ini Py38 tox env (#1752) Feb 5, 2020

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.

Note

Windows support is currently "experimental" and on a best-effort basis. Multiple workers are also not currently supported on Windows (see Issue #1517), but setting workers=1 should launch the server successfully.

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.