Movatterモバイル変換


[0]ホーム

URL:


Skip to content
❤️ Support Starlette viasponsors! 📚 Do you like the new docs?Let us know!

starlettestarlette

✨ The little ASGI framework that shines. ✨

Build StatusPackage versionSupported Python versionsDiscord


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 onhttpx.
  • CORS, GZip, Static Files, Streaming responses.
  • Session and Cookie support.
  • 100% test coverage.
  • 100% type annotated codebase.
  • Few hard dependencies.
  • Compatible withasyncio andtrio backends.
  • 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

FastAPI

Modern, fast web framework for building APIs with Python 3.8+

Installation

pipinstallstarlette

You'll also want to install an ASGI server, such asuvicorn,daphne, orhypercorn.

pipinstalluvicorn

Example

main.py
fromstarlette.applicationsimportStarlettefromstarlette.responsesimportJSONResponsefromstarlette.routingimportRouteasyncdefhomepage(request):returnJSONResponse({'hello':'world'})app=Starlette(debug=True,routes=[Route('/',homepage),])

Then run the application...

uvicornmain:app

Dependencies

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 forSessionMiddleware support.
  • pyyaml - Required forSchemaGenerator support.

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.

main.py
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.

— ⭐️ —


[8]ページ先頭

©2009-2026 Movatter.jp