### Install Starlette Source: https://www.starlette.io Install Starlette using pip. It is recommended to also install an ASGI server like uvicorn. ```bash pip install starlette ``` ```bash pip install uvicorn ``` -------------------------------- ### Run minimal ASGI application with uvicorn Source: https://www.starlette.io Example output of running a minimal ASGI application with uvicorn, showing server startup information. ```bash $ uvicorn main:app INFO: Started server process [11509] INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) ``` -------------------------------- ### Create a minimal ASGI application Source: https://www.starlette.io A minimal ASGI application that responds with plain text. This can be run directly by an ASGI server. ```python from starlette.responses import PlainTextResponse async def app(scope, receive, send): assert scope['type'] == 'http' response = PlainTextResponse('Hello, world!') await response(scope, receive, send) ``` -------------------------------- ### Create a basic Starlette application Source: https://www.starlette.io A simple Starlette application that defines a homepage route returning a JSON response. This requires Starlette and an ASGI server like uvicorn to run. ```python from starlette.applications import Starlette from starlette.responses import JSONResponse from starlette.routing import Route async def homepage(request): return JSONResponse({'hello': 'world'}) app = Starlette(debug=True, routes=[ Route('/', homepage), ]) ``` -------------------------------- ### Run Starlette application with uvicorn Source: https://www.starlette.io Command to run the Starlette application using the uvicorn ASGI server. ```bash uvicorn main:app ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.