MCPcopy
hub / github.com/encode/starlette

github.com/encode/starlette @1.3.1 sqlite

repository ↗ · DeepWiki ↗ · release 1.3.1 ↗
1,436 symbols 6,397 edges 67 files 90 documented · 6%
README
<img alt="starlette-logo" src="https://raw.githubusercontent.com/Kludex/starlette/main/docs/img/starlette.svg">










<em>✨ The little ASGI framework that shines. ✨</em>

Build Status Package version Supported Python Version Discord


Documentation: https://starlette.dev

Source Code: https://github.com/Kludex/starlette


Starlette

Starlette is a lightweight ASGI 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 asyncio and trio backends.
  • Great overall performance against independent benchmarks.

Installation

$ pip install starlette

You'll also want to install an ASGI server, such as uvicorn or any of the other ASGI server implementations.

$ pip install uvicorn

Example

```python title="main.py" from starlette.applications import Starlette from starlette.responses import JSONResponse from starlette.routing import Route

async def homepage(request): return JSONResponse({'hello': 'world'})

routes = [ Route("/", endpoint=homepage) ]

app = Starlette(debug=True, routes=routes)


Then run the application using Uvicorn:

```shell
$ uvicorn main:app

Dependencies

Starlette only requires anyio, and the following are optional:

  • httpx2 - Required if you want to use the TestClient.
  • jinja2 - Required if you want to use Jinja2Templates.
  • python-multipart - Required if you want to support form parsing, with request.form().
  • itsdangerous - Required for SessionMiddleware support.
  • pyyaml - Required for SchemaGenerator support.

You can install all of these with pip install starlette[full].

Framework or Toolkit

Starlette is designed to be used either as a complete framework, or as an ASGI toolkit. You can use any of its components independently.

from starlette.responses import PlainTextResponse


async def app(scope, receive, send):
    assert scope['type'] == 'http'
    response = PlainTextResponse('Hello, world!')
    await response(scope, receive, send)

Run the app application in example.py:

$ uvicorn example:app
INFO: Started server process [11509]
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

Run uvicorn with --reload to enable auto-reloading on code changes.

Modularity

The modularity that Starlette is designed on promotes building reusable components that can be shared between any ASGI framework. This should enable an ecosystem of shared middleware and mountable applications.

The clean API separation also means it's easier to understand each component in isolation.


Starlette is BSD licensed code.

Designed & crafted with care.

— ⭐️ —

Core symbols most depended-on inside this repo

json
called by 116
starlette/requests.py
get
called by 77
starlette/config.py
append
called by 72
starlette/datastructures.py
accept
called by 46
starlette/websockets.py
decode
called by 44
starlette/endpoints.py
app
called by 35
starlette/routing.py
items
called by 35
starlette/datastructures.py
url_path_for
called by 30
starlette/routing.py

Shape

Function 732
Method 526
Class 162
Route 16

Languages

Python100%

Modules by API surface

starlette/datastructures.py112 symbols
tests/test_routing.py106 symbols
tests/middleware/test_base.py90 symbols
tests/test_responses.py88 symbols
tests/test_formparsers.py68 symbols
starlette/routing.py67 symbols
tests/test_applications.py66 symbols
tests/test_websockets.py48 symbols
starlette/testclient.py47 symbols
tests/test_requests.py39 symbols
tests/test_staticfiles.py38 symbols
starlette/responses.py38 symbols

For agents

$ claude mcp add starlette \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact