• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

starlette/H17-Nov-2021-5,4254,382

starlette.egg-info/H03-May-2022-198145

LICENSE.mdH A D17-Nov-20211.5 KiB2822

MANIFEST.inH A D17-Nov-202170 43

PKG-INFOH A D17-Nov-20217.1 KiB198145

README.mdH A D17-Nov-20214.9 KiB173121

setup.cfgH A D17-Nov-2021896 3628

setup.pyH A D17-Nov-20211.9 KiB7059

README.md

1<p align="center">
2  <a href="https://www.starlette.io/"><img width="420px" src="https://raw.githubusercontent.com/encode/starlette/master/docs/img/starlette.png" alt='starlette'></a>
3</p>
4<p align="center">
5    <em>✨ The little ASGI framework that shines. ✨</em>
6</p>
7<p align="center">
8<a href="https://github.com/encode/starlette/actions">
9    <img src="https://github.com/encode/starlette/workflows/Test%20Suite/badge.svg" alt="Build Status">
10</a>
11<a href="https://pypi.org/project/starlette/">
12    <img src="https://badge.fury.io/py/starlette.svg" alt="Package version">
13</a>
14</p>
15
16---
17
18**Documentation**: [https://www.starlette.io/](https://www.starlette.io/)
19
20---
21
22# Starlette
23
24Starlette is a lightweight [ASGI](https://asgi.readthedocs.io/en/latest/) framework/toolkit,
25which is ideal for building high performance async services.
26
27It is production-ready, and gives you the following:
28
29* Seriously impressive performance.
30* WebSocket support.
31* In-process background tasks.
32* Startup and shutdown events.
33* Test client built on `requests`.
34* CORS, GZip, Static Files, Streaming responses.
35* Session and Cookie support.
36* 100% test coverage.
37* 100% type annotated codebase.
38* Few hard dependencies.
39* Compatible with `asyncio` and `trio` backends.
40
41## Requirements
42
43Python 3.6+
44
45## Installation
46
47```shell
48$ pip3 install starlette
49```
50
51You'll also want to install an ASGI server, such as [uvicorn](http://www.uvicorn.org/), [daphne](https://github.com/django/daphne/), or [hypercorn](https://pgjones.gitlab.io/hypercorn/).
52
53```shell
54$ pip3 install uvicorn
55```
56
57## Example
58
59**example.py**:
60
61```python
62from starlette.applications import Starlette
63from starlette.responses import JSONResponse
64from starlette.routing import Route
65
66
67async def homepage(request):
68    return JSONResponse({'hello': 'world'})
69
70routes = [
71    Route("/", endpoint=homepage)
72]
73
74app = Starlette(debug=True, routes=routes)
75```
76
77Then run the application using Uvicorn:
78
79```shell
80$ uvicorn example:app
81```
82
83For a more complete example, see [encode/starlette-example](https://github.com/encode/starlette-example).
84
85## Dependencies
86
87Starlette only requires `anyio`, and the following are optional:
88
89* [`requests`][requests] - Required if you want to use the `TestClient`.
90* [`jinja2`][jinja2] - Required if you want to use `Jinja2Templates`.
91* [`python-multipart`][python-multipart] - Required if you want to support form parsing, with `request.form()`.
92* [`itsdangerous`][itsdangerous] - Required for `SessionMiddleware` support.
93* [`pyyaml`][pyyaml] - Required for `SchemaGenerator` support.
94
95You can install all of these with `pip3 install starlette[full]`.
96
97## Framework or Toolkit
98
99Starlette is designed to be used either as a complete framework, or as
100an ASGI toolkit. You can use any of its components independently.
101
102```python
103from starlette.responses import PlainTextResponse
104
105
106async def app(scope, receive, send):
107    assert scope['type'] == 'http'
108    response = PlainTextResponse('Hello, world!')
109    await response(scope, receive, send)
110```
111
112Run the `app` application in `example.py`:
113
114```shell
115$ uvicorn example:app
116INFO: Started server process [11509]
117INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
118```
119
120Run uvicorn with `--reload` to enable auto-reloading on code changes.
121
122## Modularity
123
124The modularity that Starlette is designed on promotes building re-usable
125components that can be shared between any ASGI framework. This should enable
126an ecosystem of shared middleware and mountable applications.
127
128The clean API separation also means it's easier to understand each component
129in isolation.
130
131## Performance
132
133Independent TechEmpower benchmarks show Starlette applications running under Uvicorn
134as [one of the fastest Python frameworks available](https://www.techempower.com/benchmarks/#section=data-r17&hw=ph&test=fortune&l=zijzen-1). *(\*)*
135
136For high throughput loads you should:
137
138* Run using gunicorn using the `uvicorn` worker class.
139* Use one or two workers per-CPU core. (You might need to experiment with this.)
140* Disable access logging.
141
142Eg.
143
144```shell
145gunicorn -w 4 -k uvicorn.workers.UvicornWorker --log-level warning example:app
146```
147
148Several of the ASGI servers also have pure Python implementations available,
149so you can also run under `PyPy` if your application code has parts that are
150CPU constrained.
151
152Either programatically:
153
154```python
155uvicorn.run(..., http='h11', loop='asyncio')
156```
157
158Or using Gunicorn:
159
160```shell
161gunicorn -k uvicorn.workers.UvicornH11Worker ...
162```
163
164<p align="center">&mdash; ⭐️ &mdash;</p>
165<p align="center"><i>Starlette is <a href="https://github.com/encode/starlette/blob/master/LICENSE.md">BSD licensed</a> code. Designed & built in Brighton, England.</i></p>
166
167[requests]: http://docs.python-requests.org/en/master/
168[jinja2]: http://jinja.pocoo.org/
169[python-multipart]: https://andrew-d.github.io/python-multipart/
170[itsdangerous]: https://pythonhosted.org/itsdangerous/
171[sqlalchemy]: https://www.sqlalchemy.org
172[pyyaml]: https://pyyaml.org/wiki/PyYAMLDocumentation
173