sanic

A web server and web framework that's written to go fast. Build fast. Run fast.

MIT 84 个版本 Python >=3.10
Sanic Community <admhpkns@gmail.com>
安装
pip install sanic
poetry add sanic
pipenv install sanic
conda install sanic
描述

.. image:: https://raw.githubusercontent.com/sanic-org/sanic-assets/master/png/sanic-framework-logo-400x97.png :alt: Sanic | Build fast. Run fast.

Sanic | Build fast. Run fast.

.. start-badges

.. list-table:: :widths: 15 85 :stub-columns: 1

* - Build
  - | |Tests|
* - Docs
  - | |UserGuide| |Documentation|
* - Package
  - | |PyPI| |PyPI version| |Wheel| |Supported implementations| |Code style ruff|
* - Support
  - | |Forums| |Discord| |Awesome|
* - Stats
  - | |Monthly Downloads| |Weekly Downloads| |Conda downloads|

.. |UserGuide| image:: https://img.shields.io/badge/user%20guide-sanic-ff0068 :target: https://sanic.dev/ .. |Forums| image:: https://img.shields.io/badge/forums-community-ff0068.svg :target: https://community.sanicframework.org/ .. |Discord| image:: https://img.shields.io/discord/812221182594121728?logo=discord&label=Discord&color=5865F2 :target: https://discord.gg/FARQzAEMAA .. |Tests| image:: https://github.com/sanic-org/sanic/actions/workflows/tests.yml/badge.svg?branch=main :target: https://github.com/sanic-org/sanic/actions/workflows/tests.yml .. |Documentation| image:: https://readthedocs.org/projects/sanic/badge/?version=latest :target: http://sanic.readthedocs.io/en/latest/?badge=latest .. |PyPI| image:: https://img.shields.io/pypi/v/sanic.svg :target: https://pypi.python.org/pypi/sanic/ .. |PyPI version| image:: https://img.shields.io/pypi/pyversions/sanic.svg :target: https://pypi.python.org/pypi/sanic/ .. |Code style ruff| image:: https://img.shields.io/badge/code%20style-ruff-000000.svg :target: https://docs.astral.sh/ruff/ .. |Wheel| image:: https://img.shields.io/pypi/wheel/sanic.svg :alt: PyPI Wheel :target: https://pypi.python.org/pypi/sanic .. |Supported implementations| image:: https://img.shields.io/pypi/implementation/sanic.svg :alt: Supported implementations :target: https://pypi.python.org/pypi/sanic .. |Awesome| image:: https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg :alt: Awesome Sanic List :target: https://github.com/mekicha/awesome-sanic .. |Monthly Downloads| image:: https://img.shields.io/pypi/dm/sanic.svg :alt: Downloads :target: https://pepy.tech/project/sanic .. |Weekly Downloads| image:: https://img.shields.io/pypi/dw/sanic.svg :alt: Downloads :target: https://pepy.tech/project/sanic .. |Conda downloads| image:: https://img.shields.io/conda/dn/conda-forge/sanic.svg :alt: Downloads :target: https://anaconda.org/conda-forge/sanic

.. end-badges

Sanic is a Python 3.10+ 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.

Sanic is also ASGI compliant, so you can deploy it with an alternative ASGI webserver <https://sanicframework.org/en/guide/deployment/running.html#asgi>_.

Source code on GitHub <https://github.com/sanic-org/sanic/>_ | Help and discussion board <https://community.sanicframework.org/>_ | User Guide <https://sanicframework.org>_ | Chat on Discord <https://discord.gg/FARQzAEMAA>_

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.

Check out open collective <https://opencollective.com/sanic-org>_ to learn more about helping to fund Sanic.

Installation

pip 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.

.. code:: shell

   $ export SANIC_NO_UVLOOP=true
   $ export SANIC_NO_UJSON=true
   $ pip 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

.. code:: python

from sanic import Sanic
from sanic.response import json

app = Sanic("my-hello-world-app")

@app.route('/')
async def test(request):
    return json({'hello': 'world'})

Sanic can now be easily run from CLI using sanic hello.app.

.. code::

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

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

.. code::

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!

Minimum Python version is 3.10.

Documentation

User Guide, Changelog, and API Documentation can be found at sanic.dev <https://sanic.dev>__.

Questions and Discussion

Ask a question or join the conversation <https://community.sanicframework.org/>__.

Contribution

We are always happy to have new contributions. We have marked issues good for anyone looking to get started <https://github.com/sanic-org/sanic/issues?q=is%3Aopen+is%3Aissue+label%3Abeginner>, and welcome questions on the forums <https://community.sanicframework.org/>. Please take a look at our Contribution guidelines <https://github.com/sanic-org/sanic/blob/master/CONTRIBUTING.md>_.

版本列表
25.12.1 2026-05-31
25.12.0 2025-12-31
25.3.0 2025-03-31
24.12.1 2026-05-31
24.12.0 2024-12-31
24.6.0 2024-06-30
23.12.2 2024-06-30
23.12.1 2024-01-09
23.12.0 2023-12-31
23.6.0 2023-07-25
23.3.0 2023-03-26
22.12.0 2022-12-27
22.9.1 2022-10-31
22.9.0 2022-09-29
22.6.2 2022-08-11
22.6.1 2022-07-31
22.6.0 2022-06-30
22.3.2 2022-05-11
22.3.1 2022-04-17
22.3.0 2022-03-31
21.12.2 2022-07-31
21.12.1 2022-01-06
21.12.0 2021-12-26
21.9.3 2021-11-21
21.9.2 2021-11-21
21.9.1 2021-10-02
21.9.0 2021-09-30
21.6.2 2021-08-02
21.6.1 2021-07-28
21.6.0 2021-06-27
21.3.4 2021-04-19
21.3.2 2021-03-23
21.3.1 2021-03-21
21.3.0 2021-03-21
20.12.7 2022-07-31
20.12.6 2022-02-16
20.12.5 2022-01-16
20.12.4 2021-10-02
20.12.3 2021-03-21
20.12.2 2021-02-16
20.12.1 2021-01-05
20.12.0 2020-12-28
20.9.1 2020-10-25
20.9.0 2020-09-30
20.6.3 2020-06-29
20.6.2 2020-06-29
20.6.1 2020-06-28
20.6.0 2020-06-28
20.3.0 2020-05-14
19.12.5 2021-02-16
19.12.4 2020-11-05
19.12.3 2020-10-25
19.12.2 2020-01-02
19.12.0 2019-12-27
19.9.0 2019-10-12
19.6.3 2019-08-22
19.6.2 2019-07-08
19.6.0 2019-06-21
19.3.1 2019-03-23
18.12.0 2018-12-27
0.8.3 2018-09-13
0.8.2 2018-09-13
0.8.1 2018-09-06
0.8.0 2018-09-06
0.7.0 2017-12-06
0.6.0 2017-08-03
0.5.4 2017-05-09
0.5.2 2017-05-09
0.5.1 2017-04-14
0.5.0 2017-04-11
0.4.1 2017-02-28
0.4.0 2017-02-25
0.3.1 2017-02-09
0.3.0 2017-01-28
0.2.0 2017-01-14
0.1.9 2016-12-25
0.1.8 2016-11-29
0.1.7 2016-10-25
0.1.6 2016-10-25
0.1.5 2016-10-23
0.1.4 2016-10-18
0.1.3 2016-10-16
0.1.1 2016-10-15
0.1.0 2016-10-15