Explore our comprehensive Starlette tutorial to harness this lightweight ASGI framework, ideal for building robust Python async applications. Discover its role as a FastAPI base and learn the essentials with practical examples.
pip install starletteWhat is Starlette and why use it?
Key features and capabilities
Installation instructions
Basic usage examples
Common use cases
Best practices and tips
from starlette.applications import Starlette\nfrom starlette.responses import JSONResponse\nfrom starlette.routing import Route\n\nasync def homepage(request):\n return JSONResponse({'hello': 'world'})\n\napp = Starlette(debug=True, routes=[\n Route('/', homepage),\n])from starlette.applications import Starlette\nfrom starlette.responses import JSONResponse\nfrom starlette.routing import Route\nfrom starlette.middleware.cors import CORSMiddleware\n\nasync def homepage(request):\n return JSONResponse({'message': 'This is an advanced example'})\n\napp = Starlette()\napp.add_middleware(CORSMiddleware, allow_origins=['*'])\napp.add_route('/', homepage)routeRegisters a new route with the application