The lightning-fast ASGI server.
Project description
An ASGI web serverfor Python.
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 gapand 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
uvloopwill be installed and used if possible. - the http protocol will be handled by
httptoolsif possible.
Moreover"optional extras" means that:
- the websocket protocol will be handled by
websockets(should you want to usewsprotoyou'd need to install it manually) if possible. - the
--reloadflag in development mode will usewatchfiles. - windows users will have
coloramainstalled for the colored logs. python-dotenvwill be installed should you want to use the--env-fileoption.PyYAMLwill be installed to allow you to provide a.yamlfile to--log-configif desired.
Create an applicationin 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'Helloworld!',
})
Run the server:
$ uvicorn example:app
Why ASGI?
Most well established Python Web frameworks started out as WSGI-based frameworks.
WSGI applications are a singlesynchronous callable that takes a request and returns a response. This doesn’t allow for long-lived connectionslike 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 implementationoriginally developed to power Django Channelsis the Daphne webserver.
It is run widely in productionand supports HTTP/1.1HTTP/2and 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 frameworkbefore being separated out into a standalone ASGI server.
Hypercorn supports HTTP/1.1HTTP/2and WebSockets.
It also supports the excellent trio async frameworkas 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/2TLS 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 chooselearn more about installing packages.
Source Distribution
Built Distribution
Filter files by nameinterpreterABIand platform.
If you're not sure about the file name formatlearn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uvicorn-0.45.0.tar.gz.
File metadata
- Download URL: uvicorn-0.45.0.tar.gz
- Upload date:
- Size: 87.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fe650df136c5bd2b9b06efc5980636344a2fbb840e9ddd86437d53144fa335d
|
|
| MD5 |
02700ca86cc45ae04986ad56234822a2
|
|
| BLAKE2b-256 |
eb2e62b0d9a2cfc8b4de6771322dae30f2db76c66dae9ec32e94e176a44ad563
|
Provenance
The following attestation bundles were made for uvicorn-0.45.0.tar.gz:
Publisher:
publish.yml on Kludex/uvicorn
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
uvicorn-0.45.0.tar.gz -
Subject digest:
3fe650df136c5bd2b9b06efc5980636344a2fbb840e9ddd86437d53144fa335d - Sigstore transparency entry: 1348240179
- Sigstore integration time:
-
Permalink:
Kludex/uvicorn@2c423bd82be169459ea254a61476de34767e0326 -
Branch / Tag:
refs/tags/0.45.0 - Owner: https://github.com/Kludex
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2c423bd82be169459ea254a61476de34767e0326 -
Trigger Event:
push
-
Statement type:
File details
Details for the file uvicorn-0.45.0-py3-none-any.whl.
File metadata
- Download URL: uvicorn-0.45.0-py3-none-any.whl
- Upload date:
- Size: 69.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2db26f588131aeec7439de00f2dd52d5f210710c1f01e407a52c90b880d1fd4f
|
|
| MD5 |
c37379097c7c683b69f1cc6f5284646b
|
|
| BLAKE2b-256 |
c188d0f7512465b166a4e931ccf7e77792be60fb88466a43964c7566cbaff752
|
Provenance
The following attestation bundles were made for uvicorn-0.45.0-py3-none-any.whl:
Publisher:
publish.yml on Kludex/uvicorn
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
uvicorn-0.45.0-py3-none-any.whl -
Subject digest:
2db26f588131aeec7439de00f2dd52d5f210710c1f01e407a52c90b880d1fd4f - Sigstore transparency entry: 1348240228
- Sigstore integration time:
-
Permalink:
Kludex/uvicorn@2c423bd82be169459ea254a61476de34767e0326 -
Branch / Tag:
refs/tags/0.45.0 - Owner: https://github.com/Kludex
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2c423bd82be169459ea254a61476de34767e0326 -
Trigger Event:
push
-
Statement type: