starlette README

The project's README from github.com/Kludex/starlette. As one markdown file: README.md.

starlette-logo

✨ The little ASGI framework that shines. ✨


Build Status Package version Supported Python Version Discord


Documentation: https://starlette.dev

Source Code: https://github.com/Kludex/starlette


Starlette

Starlette is a lightweight ASGI framework/toolkit, which is ideal for building async web services in Python.

It is production-ready, and gives you the following:

Installation

$ pip install starlette

You'll also want to install an ASGI server, such as uvicorn or any of the other ASGI server implementations.

$ pip install uvicorn

Example

from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route


async def homepage(request):
    return JSONResponse({'hello': 'world'})

routes = [
    Route("/", endpoint=homepage)
]

app = Starlette(debug=True, routes=routes)

Then run the application using Uvicorn:

$ uvicorn main:app

Dependencies

Starlette only requires anyio, and the following are optional:

You can install all of these with pip install starlette[full].

Framework or Toolkit

Starlette is designed to be used either as a complete framework, or as an ASGI toolkit. You can use any of its components independently.

from starlette.responses import PlainTextResponse


async def app(scope, receive, send):
    assert scope['type'] == 'http'
    response = PlainTextResponse('Hello, world!')
    await response(scope, receive, send)

Run the app application in example.py:

$ uvicorn example:app
INFO: Started server process [11509]
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

Run uvicorn with --reload to enable auto-reloading on code changes.

Modularity

The modularity that Starlette is designed on promotes building reusable components that can be shared between any ASGI framework. This should enable an ecosystem of shared middleware and mountable applications.

The clean API separation also means it's easier to understand each component in isolation.


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

— ⭐️ —

starlette (Kludex/starlette)

Searching Database…

12.7K ·GitHub
What is this?Starlette is a lightweight ASGI framework and toolkit for building async web services in Python - small, production-ready, and with few hard dependencies.
Is it a full framework, or a toolkit I can pick pieces from?Both. You can use it as a complete framework or as an ASGI toolkit, and any of its components can be used on its own.
How do I get a basic app running?Install Starlette with pip, serve your app with an ASGI server such as uvicorn (e.g. uvicorn example:app), and pass --reload to auto-reload on code changes while developing.
What does it pull in?Only anyio is required; httpx, jinja2, python-multipart, itsdangerous, pyyaml and opentelemetry-api are optional extras. Install everything with pip install starlette[full].
Is it actually production-ready, or a minimal toy?It is production-ready: 100% test coverage, a fully type-annotated codebase, few hard dependencies and great overall performance in independent benchmarks.
What comes out of the box?WebSocket support, in-process background tasks, startup and shutdown events, a test client, CORS, GZip, static files, streaming responses, plus session and cookie support.
Does it work with asyncio, or can I use trio?Both - Starlette is compatible with asyncio and trio backends, so you can keep whichever async stack you already use.
How fast is it?The README cites great overall performance against independent benchmarks, which fits its lightweight, low-dependency design.
Can I share its middleware and components with other ASGI frameworks?Yes - its modularity promotes reusable components shared between any ASGI framework, and the clean API separation makes each part easy to understand in isolation.
What are similar projects?aiohttp, axum, actix-web, uvicorn, koa, ktor, echo, sanic
Creator
Kludex
Size
8.5 MB
Stars
12.7K
Age
8y
Commits · 90 Days