fastapi/fastapi
Public Python API
The names exported from fastapi/__init__.py are the official public surface. Everything else under fastapi.* is documented but more likely to change.
from fastapi import ...
| Name | Source module | Used for |
|---|---|---|
FastAPI |
fastapi.applications |
The application class. |
APIRouter |
fastapi.routing |
Sub-routing primitive. |
Depends, Security |
fastapi.param_functions |
Dependency injection markers. |
Body, Cookie, File, Form, Header, Path, Query |
fastapi.param_functions |
Parameter location markers. |
Request, Response |
fastapi.requests, fastapi.responses (re-exports of Starlette) |
Direct request/response access. |
WebSocket, WebSocketDisconnect |
fastapi.websockets (re-export of Starlette) |
WebSocket handling. |
BackgroundTasks |
fastapi.background |
Per-request background work. |
HTTPException, WebSocketException |
fastapi.exceptions |
Application-raised errors. |
UploadFile |
fastapi.datastructures |
File uploads. |
status |
starlette.status (re-export) |
HTTP status code constants. |
These are the only names guaranteed stable across patch releases.
Sub-modules with stable API
| Sub-module | Public items |
|---|---|
fastapi.security |
APIKeyQuery, APIKeyHeader, APIKeyCookie, HTTPBasic, HTTPBasicCredentials, HTTPBearer, HTTPDigest, HTTPAuthorizationCredentials, OAuth2, OAuth2PasswordBearer, OAuth2AuthorizationCodeBearer, OAuth2PasswordRequestForm, OAuth2PasswordRequestFormStrict, SecurityScopes, OpenIdConnect. |
fastapi.encoders |
jsonable_encoder. |
fastapi.exceptions |
The exception classes listed above plus RequestValidationError, WebSocketRequestValidationError, ResponseValidationError, FastAPIError. |
fastapi.exception_handlers |
The default async handlers (http_exception_handler, request_validation_exception_handler, websocket_request_validation_exception_handler). |
fastapi.responses |
Re-exports JSONResponse, HTMLResponse, PlainTextResponse, RedirectResponse, StreamingResponse, FileResponse, Response (all Starlette). Also exports EventSourceResponse from fastapi.sse and the deprecated UJSONResponse and ORJSONResponse. |
fastapi.middleware.* |
cors, gzip, httpsredirect, trustedhost, wsgi — re-exports of the Starlette middleware classes. |
fastapi.staticfiles, fastapi.templating, fastapi.testclient |
One-line re-exports of Starlette equivalents. |
fastapi.openapi.docs |
get_swagger_ui_html, get_redoc_html, get_swagger_ui_oauth2_redirect_html, swagger_ui_default_parameters. |
fastapi.openapi.utils |
get_openapi. |
fastapi.openapi.models |
The OpenAPI Pydantic models — useful for tools that build schemas. |
fastapi.sse |
EventSourceResponse, ServerSentEvent, format_sse_event. |
Internal modules (likely to change)
These are used internally and not intended for direct import:
fastapi._compat.*— Pydantic abstraction layer.fastapi.dependencies.*—Dependantandsolve_dependencies. The names are public, but their signatures evolve to track Pydantic.fastapi.params— class versions of the parameter markers. User code should use the function wrappers fromfastapi.param_functions(which is whatfrom fastapi import Pathresolves to).fastapi.utils— internal helpers (generate_unique_id,is_body_allowed_for_status_code,get_path_param_names,deep_dict_update).
Code that imports from these internal modules is allowed to break across patch releases.
Deprecated names still importable
| Name | Replacement |
|---|---|
fastapi.responses.UJSONResponse, ORJSONResponse |
Set response_model and let Pydantic dump. |
Param(..., regex=...) |
Param(..., pattern=...). |
fastapi.utils.generate_operation_id_for_path |
fastapi.utils.generate_unique_id (called automatically). |
on_startup= / on_shutdown= |
lifespan= (an async context manager). |
Each fires FastAPIDeprecationWarning at runtime. The classes/functions remain importable for backwards compatibility.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.
Previous
Auto-served routes
Next
Reference