chinying / uvicorn

The lightning-fast ASGI server. πŸ¦„

Home Page:https://www.uvicorn.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

uvicorn

The lightning-fast ASGI server.


Build Status Package version

Documentation: https://www.uvicorn.org

Community: https://discuss.encode.io/c/uvicorn

Requirements: Python 3.6+ (For Python 3.5 support, install version 0.8.6.)

Uvicorn is a lightning-fast ASGI server implementation, using uvloop and httptools.

Until recently Python has lacked a minimal low-level server/application interface for asyncio frameworks. The ASGI specification fills this gap, and means we're now able to start building a common set of tooling usable across all asyncio frameworks.

Uvicorn currently supports HTTP/1.1 and WebSockets. Support for HTTP/2 is planned.

Quickstart

Install using pip:

$ pip install uvicorn

This will install uvicorn with minimal (pure Python) dependencies.

$ pip install uvicorn[standard]

This will install uvicorn with "Cython-based" dependencies (where possible) and other "optional extras".

In this context, "Cython-based" means the following:

  • the event loop uvloop will be installed and used if possible.
  • the http protocol will be handled by httptools if possible.

Moreover, "optional extras" means that:

  • the websocket protocol will be handled by websockets (should you want to use wsproto you'd need to install it manually) if possible.
  • the --reloader flag in development mode will use watchgod.
  • windows users will have colorama installed for the colored logs.
  • python-dotenv will be installed should you want to use the --env-file option.
  • PyYAML will be installed to allow you to provide a .yaml file to --log-config, if desired.

Create an application, in example.py:

async def app(scope, receive, send):
    assert scope['type'] == 'http'

    await send({
        'type': 'http.response.start',
        'status': 200,
        'headers': [
            [b'content-type', b'text/plain'],
        ],
    })
    await send({
        'type': 'http.response.body',
        'body': b'Hello, world!',
    })

Run the server:

$ uvicorn example:app

Uvicorn is BSD licensed code.
Designed & built in Brighton, England.

β€” πŸ¦„ β€”

About

The lightning-fast ASGI server. πŸ¦„

https://www.uvicorn.org/

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Python 99.0%Language:Shell 1.0%