From: Marcelo Trylesinski Date: Thu, 31 Oct 2024 07:05:06 +0000 (+0100) Subject: Match httpx documentation style (#2742) X-Git-Tag: 0.41.3~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c2e3a39b09a613553ee03586589ed9cd0fbf07f3;p=thirdparty%2Fstarlette.git Match httpx documentation style (#2742) --- diff --git a/docs/applications.md b/docs/applications.md index 6fb74f19..b90c20f3 100644 --- a/docs/applications.md +++ b/docs/applications.md @@ -3,6 +3,8 @@ Starlette includes an application class `Starlette` that nicely ties together al its other functionality. ```python +from contextlib import asynccontextmanager + from starlette.applications import Starlette from starlette.responses import PlainTextResponse from starlette.routing import Route, Mount, WebSocketRoute @@ -25,8 +27,11 @@ async def websocket_endpoint(websocket): await websocket.send_text('Hello, websocket!') await websocket.close() -def startup(): - print('Ready to go') +@asyncontextmanager +async def lifespan(app): + print('Startup') + yield + print('Shutdown') routes = [ @@ -37,7 +42,7 @@ routes = [ Mount('/static', StaticFiles(directory="static")), ] -app = Starlette(debug=True, routes=routes, on_startup=[startup]) +app = Starlette(debug=True, routes=routes, lifespan=lifespan) ``` ### Instantiating the application diff --git a/docs/index.md b/docs/index.md index cc243b43..faf1c7c5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,7 +1,3 @@ ---- -hide: navigation ---- -

starlette starlette @@ -52,18 +48,18 @@ It is production-ready, and gives you the following: ## Installation ```shell -$ pip install starlette +pip install starlette ``` You'll also want to install an ASGI server, such as [uvicorn](https://www.uvicorn.org/), [daphne](https://github.com/django/daphne/), or [hypercorn](https://hypercorn.readthedocs.io/en/latest/). ```shell -$ pip install uvicorn +pip install uvicorn ``` ## Example -```python title="example.py" +```python title="main.py" from starlette.applications import Starlette from starlette.responses import JSONResponse from starlette.routing import Route @@ -81,11 +77,9 @@ app = Starlette(debug=True, routes=[ Then run the application... ```shell -$ uvicorn example:app +uvicorn main:app ``` -For a more complete example, [see here](https://github.com/encode/starlette-example). - ## Dependencies Starlette only requires `anyio`, and the following dependencies are optional: @@ -103,7 +97,7 @@ You can install all of these with `pip install starlette[full]`. Starlette is designed to be used either as a complete framework, or as an ASGI toolkit. You can use any of its components independently. -```python +```python title="main.py" from starlette.responses import PlainTextResponse @@ -113,10 +107,10 @@ async def app(scope, receive, send): await response(scope, receive, send) ``` -Run the `app` application in `example.py`: +Run the `app` application in `main.py`: ```shell -$ uvicorn example:app +$ uvicorn main:app INFO: Started server process [11509] INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) ``` diff --git a/docs/release-notes.md b/docs/release-notes.md index 1b56b342..66186ebd 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,5 +1,4 @@ --- -hide: navigation toc_depth: 2 --- diff --git a/mkdocs.yml b/mkdocs.yml index ad503317..83d245e0 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -21,7 +21,6 @@ theme: repo: fontawesome/brands/github features: - content.code.copy - - navigation.tabs - toc.follow repo_name: encode/starlette @@ -29,7 +28,7 @@ repo_url: https://github.com/encode/starlette edit_uri: edit/master/docs/ nav: - - Home: "index.md" + - Introduction: "index.md" - Features: - Applications: "applications.md" - Requests: "requests.md"