✨ The little ASGI framework that shines. ✨
Documentation:https://starlette.dev
Source Code:https://github.com/Kludex/starlette
Introduction
Starlette is a lightweightASGI framework/toolkit,which is ideal for building async web services in Python.
It is production-ready, and gives you the following:
- A lightweight, low-complexity HTTP web framework.
- WebSocket support.
- In-process background tasks.
- Startup and shutdown events.
- Test client built on
httpx. - CORS, GZip, Static Files, Streaming responses.
- Session and Cookie support.
- 100% test coverage.
- 100% type annotated codebase.
- Few hard dependencies.
- Compatible with
asyncioandtriobackends. - Great overall performanceagainst independent benchmarks.
Sponsorship
Starlette is an open-source project that relies on community support. You can help us maintain and improve the framework bybecoming a sponsor.
🏆 Our Gold Sponsor

Modern, fast web framework for building APIs with Python 3.8+
Installation
pipinstallstarletteYou'll also want to install an ASGI server, such asuvicorn,daphne, orhypercorn.
pipinstalluvicornExample
fromstarlette.applicationsimportStarlettefromstarlette.responsesimportJSONResponsefromstarlette.routingimportRouteasyncdefhomepage(request):returnJSONResponse({'hello':'world'})app=Starlette(debug=True,routes=[Route('/',homepage),])Then run the application...
uvicornmain:appDependencies
Starlette only requiresanyio, and the following dependencies are optional:
httpx- Required if you want to use theTestClient.jinja2- Required if you want to useJinja2Templates.python-multipart- Required if you want to support form parsing, withrequest.form().itsdangerous- Required forSessionMiddlewaresupport.pyyaml- Required forSchemaGeneratorsupport.
You can install all of these withpip install starlette[full].
Framework or Toolkit
Starlette is designed to be used either as a complete framework, or asan ASGI toolkit. You can use any of its components independently.
fromstarlette.responsesimportPlainTextResponseasyncdefapp(scope,receive,send):assertscope['type']=='http'response=PlainTextResponse('Hello, world!')awaitresponse(scope,receive,send)Run theapp application inmain.py:
$uvicornmain:appINFO:Startedserverprocess[11509]INFO:Uvicornrunningonhttp://127.0.0.1:8000(PressCTRL+Ctoquit)Run uvicorn with--reload to enable auto-reloading on code changes.
Modularity
The modularity that Starlette is designed on promotes building re-usablecomponents that can be shared between any ASGI framework. This should enablean ecosystem of shared middleware and mountable applications.
The clean API separation also means it's easier to understand each componentin isolation.
Starlette isBSD licensed code.
Designed & crafted with care.— ⭐️ —