gitmyhub

starlette

Python ★ 12k updated 2d ago

The little ASGI framework that shines. 🌟

Starlette is a lightweight Python library for building fast web APIs and services, it handles routing, WebSockets, middleware, and background tasks, and serves as the foundation that FastAPI is built on.

PythonASGIUvicornJinja2setup: easycomplexity 3/5

Starlette is a lightweight Python library for building web servers and APIs. It runs on a modern Python interface called ASGI, which allows the framework to handle many requests at the same time without blocking, making it well-suited for services that make network calls or do other work that involves a lot of waiting.

You install it with pip, write your routes and handler functions in Python, then run it with a separate server program like Uvicorn. A minimal example involves defining a route (a URL path) and an async function that returns a response, and Starlette handles the plumbing between incoming HTTP requests and those functions.

Starlette can be used in two ways. As a complete framework, it provides routing, request handling, WebSocket support, background tasks, middleware for compression and cross-origin requests, session and cookie support, template rendering with Jinja2, and a built-in test client. As a toolkit, individual components can be pulled out and used on their own without adopting the full framework structure. This modular design is intentional: it makes it possible to share middleware and application components across any ASGI-compatible project.

The library has very few required dependencies. Optional features like templates, form parsing, sessions, and schema generation each require one additional package, but only those that are actually needed have to be installed. Starlette is fully type-annotated and claims 100% test coverage. It serves as the foundation that FastAPI builds on top of. The project is released under the BSD license.

Where it fits