The little ASGI library that shines.
--- Starlette is a small library for working with [ASGI](https://asgi.readthedocs.io/en/latest/). It gives you `Request` and `Response` classes, a test client, and a decorator for writing super-minimal applications. **Requirements:** Python 3.6+ **Installation:** ```shell pip3 install starlette ``` **Example:** ```python from starlette import Response class App: def __init__(self, scope): self.scope = scope async def __call__(self, receive, send): response = Response('Hello, world!', media_type='text/plain') await response(receive, send) ``` You can run the application with any ASGI server, including [uvicorn](http://www.uvicorn.org/), [daphne](https://github.com/django/daphne/), or [hypercorn](https://pgjones.gitlab.io/hypercorn/),— ⭐️ —
## Responses Starlette includes a few response classes that handle sending back the appropriate ASGI messages on the `send` channel. ### Response Signature: `Response(content=b'', status_code=200, headers=None, media_type=None)` * `content` - A string or bytestring. * `status_code` - An integer HTTP status code. * `headers` - A dictionary of strings or list of pairs of strings. * `media_type` - A string giving the content type. Starlette will automatically include a content-length header. It will also set the content-type header, including a charset for text types. Once you've instantiated a response, you can send it by calling it as an ASGI application instance. ```python class App: def __init__(self, scope): self.scope = scope async def __call__(self, receive, send): response = Response('Hello, world!', media_type='text/plain') await response(receive, send) ``` ### HTMLResponse Takes some text or bytes and returns an HTML response. ```python from starlette import HTMLResponse class App: def __init__(self, scope): self.scope = scope async def __call__(self, receive, send): response = HTMLResponse('