fastapi/fastapi
Fastapi
FastAPI is a web framework for building APIs with Python. It leverages standard language type hints to provide automatic data validation, request parsing, and interactive API documentation generation. The framework supports asynchronous request handling and manages execution contexts to prevent blocking the main event loop.
The project includes a dependency injection system that allows for the resolution and injection of reusable components into request handlers. This system supports request-scoped caching, lifecycle management, and integration with security mechanisms like OAuth2 and JSON Web Tokens. Developers can organize applications into modular routers and mount sub-applications to manage complex routing logic.
Infrastructure features include middleware support for cross-origin resource sharing, background task management, and static file serving. The framework automatically generates OpenAPI specifications for defined endpoints, which can be customized through metadata and schema extensions. Testing utilities are provided to simulate HTTP and WebSocket connections, allowing for isolated verification of application behavior.
Features
- Application Core Classes - The core class provides the primary interface for defining API routes, managing application state, and integrating with web frameworks for request handling.
- Request Body Validations - Use of models to define, validate, and document request body data, enabling automatic type checking and interactive documentation generation.
- ASGI Middleware Registrations - A standardized method to register middleware classes, ensuring proper integration with internal error handling and exception management systems.
- Query Parameter Validations - A parameter-validation utility for extracting and validating query string parameters, supporting default values, aliases, and validation constraints.
- OpenAPI Response Definitions - Support for defining additional API response status codes and schemas by passing a dictionary to decorators, requiring manual response object returns.
- Resource Replacement Strategies - Support for full resource replacement using the HTTP PUT method, allowing developers to update entire data objects.
- Background Task Managers - A background task management system allowing developers to offload slow operations to run after the HTTP response is returned to the client.
- Asynchronous Request Processing - The request object provides asynchronous methods for streaming the request body as bytes or parsing it as JSON, facilitating efficient handling of large payloads.
- Authenticated User Injection - A dependency-based mechanism for retrieving and injecting authenticated user models into request handlers, using schema-based validation for type-safe data handling.
- Model Attribute Validations - Use of field utilities within data models to declare validation, metadata, and default values for attributes.
- Type Hint Integrations - Leveraging standard language type hints to provide automatic editor support, data validation, request parsing, and API documentation generation.
- Asynchronous Dependencies - Automatic handling of both synchronous and asynchronous dependency functions, allowing them to be mixed within any request handler.
- Result Caching - Caching of dependency results per request by default, ensuring that shared sub-dependencies are executed only once, with an option to disable caching.