Installation & Dependencies
Relevant source files
The following files were used as context for generating this wiki page:
Starlette is a lightweight ASGI framework and toolkit designed for building high-performance asyncio web services in Python. It is characterized by its low complexity, 100% type annotation, and minimal hard dependencies, making it suitable for use as both a full-stack framework or a modular toolkit.
The project emphasizes modularity, allowing developers to use components like routing, middleware, and responses independently. To function as a web service, Starlette requires an external ASGI server to handle the interface between the web server and the application.
Sources: README.md:19-35, README.md:61-63
Installation Methods
Standard Installation
The core Starlette package can be installed via pip. This installation includes only the essential components required to run the framework.
$ pip install starlette
Sources: README.md:39-41
Full Installation
For developers requiring the complete suite of features (including testing tools, template support, and form parsing), Starlette provides a "full" extra that installs all optional dependencies.
$ pip install starlette[full]
Sources: README.md:65-65, pyproject.toml:50-56
ASGI Server Requirement
Since Starlette is an ASGI framework, it does not include a built-in web server for production. Users must install an ASGI server such as Uvicorn, Daphne, or Hypercorn.
$ pip install uvicorn
Sources: README.md:43-47
Dependency Management
Starlette distinguishes between mandatory dependencies required for core functionality and optional dependencies required for specific features.
Core Dependencies
The project maintains a small footprint with only one primary runtime dependency.
| Package | Version | Description |
|---|---|---|
anyio | >=3.6.2, <5 | Core library for asynchronous concurrency. |
typing_extensions | >=4.10.0 | Required for Python versions earlier than 3.13. |
Sources: pyproject.toml:44-47, README.md:61-61
Optional Dependencies
Specific modules within Starlette require additional packages to be installed. If these are missing, Starlette will raise an error when the related feature is accessed.
| Feature | Dependency | Purpose |
|---|---|---|
| Test Client | httpx | Used by starlette.testclient to simulate requests. |
| Templates | jinja2 | Required for Jinja2Templates support. |
| Form Parsing | python-multipart | Required for request.form() support. |
| Sessions | itsdangerous | Required for SessionMiddleware signed cookies. |
| API Schemas | pyyaml | Required for SchemaGenerator and OpenAPI support. |
Sources: README.md:61-65, pyproject.toml:50-56, starlette/schemas.py:10-13
Dependency Flow for Optional Features
The following diagram illustrates how Starlette handles optional feature requests based on the presence of specific dependencies.
Development and Environment Setup
Supported Python Versions
Starlette requires Python 3.10 or higher.
Sources: pyproject.toml:16
Internal Development Scripts
The repository includes a set of scripts for contributors to manage the development environment, following the "Scripts to Rule Them All" pattern.
scripts/install: Installs all dependencies in a virtual environment.scripts/test: Executes the test suite.scripts/lint: Runs automated formatting and linting tools (Ruff, Mypy).scripts/build: Generates source and wheel packages for distribution.
Sources: scripts/README.md:3-8
Build System
Starlette uses hatchling as the build backend and hatch for versioning management.
Sources: pyproject.toml:2-3, pyproject.toml:86-87
Summary of Components
Starlette's architecture allows for high modularity. The Starlette class itself acts as a coordinator for routing and middleware.
Sources: starlette/applications.py:21-65
Final verification of the installation can be performed by running a simple application with an ASGI server like Uvicorn.
Sources: README.md:58-59