KEMBAR78
uvicorn · PyPI Skip to main content

The lightning-fast ASGI server.

Project description

uvicorn

An ASGI web server, for Python.


Build Status Package version Supported Python Version Discord


Documentation: https://uvicorn.dev

Source Code: https://www.github.com/Kludex/uvicorn


Uvicorn is an ASGI web server implementation for Python.

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

Uvicorn supports HTTP/1.1 and WebSockets.

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 --reload flag in development mode will use watchfiles.
  • 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

Why ASGI?

Most well established Python Web frameworks started out as WSGI-based frameworks.

WSGI applications are a single, synchronous callable that takes a request and returns a response. This doesn’t allow for long-lived connections, like you get with long-poll HTTP or WebSocket connections, which WSGI doesn't support well.

Having an async concurrency model also allows for options such as lightweight background tasks, and can be less of a limiting factor for endpoints that have long periods being blocked on network I/O such as dealing with slow HTTP requests.


Alternative ASGI servers

A strength of the ASGI protocol is that it decouples the server implementation from the application framework. This allows for an ecosystem of interoperating webservers and application frameworks.

Daphne

The first ASGI server implementation, originally developed to power Django Channels, is the Daphne webserver.

It is run widely in production, and supports HTTP/1.1, HTTP/2, and WebSockets.

Any of the example applications given here can equally well be run using daphne instead.

$ pip install daphne
$ daphne app:App

Hypercorn

Hypercorn was initially part of the Quart web framework, before being separated out into a standalone ASGI server.

Hypercorn supports HTTP/1.1, HTTP/2, and WebSockets.

It also supports the excellent trio async framework, as an alternative to asyncio.

$ pip install hypercorn
$ hypercorn app:App

Mangum

Mangum is an adapter for using ASGI applications with AWS Lambda & API Gateway.

Granian

Granian is an ASGI compatible Rust HTTP server which supports HTTP/2, TLS and WebSockets.


Uvicorn is BSD licensed code.
Designed & crafted with care.

— 🦄 —

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

uvicorn-0.38.0.tar.gz (80.6 kB view details)

Uploaded Source

Built Distribution

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

uvicorn-0.38.0-py3-none-any.whl (68.1 kB view details)

Uploaded Python 3

File details

Details for the file uvicorn-0.38.0.tar.gz.

File metadata

  • Download URL: uvicorn-0.38.0.tar.gz
  • Upload date:
  • Size: 80.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for uvicorn-0.38.0.tar.gz
Algorithm Hash digest
SHA256 fd97093bdd120a2609fc0d3afe931d4d4ad688b6e75f0f929fde1bc36fe0e91d
MD5 ee4fbbe43a1e58e6624adb2763161bee
BLAKE2b-256 cbcef06b84e2697fef4688ca63bdb2fdf113ca0a3be33f94488f2cadb690b0cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for uvicorn-0.38.0.tar.gz:

Publisher: publish.yml on Kludex/uvicorn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file uvicorn-0.38.0-py3-none-any.whl.

File metadata

  • Download URL: uvicorn-0.38.0-py3-none-any.whl
  • Upload date:
  • Size: 68.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for uvicorn-0.38.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48c0afd214ceb59340075b4a052ea1ee91c16fbc2a9b1469cca0e54566977b02
MD5 4d9a728a4545a35dafabc4543c687029
BLAKE2b-256 eed9d88e73ca598f4f6ff671fb5fde8a32925c2e08a637303a1d12883c7305fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for uvicorn-0.38.0-py3-none-any.whl:

Publisher: publish.yml on Kludex/uvicorn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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