spakky-fastapi¶
FastAPI 통합 — 라우트 데코레이터, 자동 엔드포인트 등록, 인증 경계 통합
spakky-fastapi는 HTTP Authorization: Bearer <token>과 WebSocket
Authorization: Bearer <token> 또는 access_token=<token> connection query를
CredentialCarrier로 추출하고, 사용자 handler 호출 전에 AuthContext를
request/context scope에 seed합니다. 보호된 handler는 인증만을 위해 FastAPI
Request 또는 WebSocket 파라미터를 선언할 필요가 없습니다. HTTP auth failure는
CHALLENGE=401, DENY=403, ERROR=500으로 매핑되고, WebSocket auth failure는
connection close로 처리됩니다.
스테레오타입¶
API controller stereotype for FastAPI route grouping.
Provides the @ApiController stereotype for marking classes as FastAPI REST controllers with automatic route registration and prefix configuration.
ApiController(prefix, tags=None, *, name='', scope=Scope.SINGLETON)
dataclass
¶
Bases: Controller
Stereotype for FastAPI REST API controllers.
Marks a class as an API controller with automatic route registration. Methods decorated with @get, @post, etc. will be registered as FastAPI endpoints with the specified prefix.
Attributes:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
URL prefix for all routes in this controller. |
tags |
list[str | Enum] | None
|
OpenAPI tags for grouping endpoints in documentation. |
라우트¶
Base route decorator and configuration for FastAPI endpoints.
Provides the core @route decorator and Route annotation class that can be used to mark controller methods as API endpoints with full FastAPI configuration.
HTTPMethod
¶
Route(path, response_model=None, status_code=None, tags=None, dependencies=None, summary=None, description=None, response_description='Successful Response', responses=None, deprecated=None, methods=None, operation_id=None, response_model_include=None, response_model_exclude=None, response_model_by_alias=True, response_model_exclude_unset=False, response_model_exclude_defaults=False, response_model_exclude_none=False, include_in_schema=True, response_class=JSONResponse, name=None, route_class_override=None, callbacks=None, openapi_extra=None)
dataclass
¶
Bases: FunctionAnnotation
Function annotation for marking methods as API routes.
Stores all FastAPI route configuration including path, HTTP methods, response models, and OpenAPI documentation settings.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
The URL path for this route. |
response_model |
type[Any] | None
|
Pydantic model for response serialization. |
status_code |
int | None
|
HTTP status code for successful responses. |
tags |
list[str] | None
|
OpenAPI tags for grouping endpoints. |
dependencies |
Sequence[Depends] | None
|
FastAPI dependencies to inject. |
summary |
str | None
|
Short summary for OpenAPI documentation. |
description |
str | None
|
Detailed description for OpenAPI documentation. |
response_description |
str
|
Description of successful response. |
responses |
dict[int | str, dict[str, Any]] | None
|
Additional response schemas for OpenAPI. |
deprecated |
bool | None
|
Whether this endpoint is deprecated. |
methods |
set[HTTPMethod] | list[HTTPMethod] | None
|
HTTP methods this route handles. |
operation_id |
str | None
|
Custom OpenAPI operation ID. |
response_model_include |
SetIntStr | DictIntStrAny | None
|
Fields to include in response model. |
response_model_exclude |
SetIntStr | DictIntStrAny | None
|
Fields to exclude from response model. |
response_model_by_alias |
bool
|
Use field aliases in response. |
response_model_exclude_unset |
bool
|
Exclude unset fields from response. |
response_model_exclude_defaults |
bool
|
Exclude fields with default values. |
response_model_exclude_none |
bool
|
Exclude None values from response. |
include_in_schema |
bool
|
Include in OpenAPI schema. |
response_class |
type[Response]
|
FastAPI response class to use. |
name |
str | None
|
Display name for the route. |
route_class_override |
type[APIRoute] | None
|
Custom APIRoute class. |
callbacks |
list[Route] | None
|
OpenAPI callbacks configuration. |
openapi_extra |
dict[str, Any] | None
|
Additional OpenAPI schema data. |
route(path, response_model=None, status_code=None, tags=None, dependencies=None, summary=None, description=None, response_description='Successful Response', responses=None, deprecated=None, methods=None, operation_id=None, response_model_include=None, response_model_exclude=None, response_model_by_alias=True, response_model_exclude_unset=False, response_model_exclude_defaults=False, response_model_exclude_none=False, include_in_schema=True, response_class=JSONResponse, name=None, route_class_override=None, callbacks=None, openapi_extra=None)
¶
Decorator to mark a controller method as an API route.
Attaches route configuration to the method which will be registered by the RegisterRoutesPostProcessor during container initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The URL path for this route. |
required |
response_model
|
type[Any] | None
|
Pydantic model for response serialization. |
None
|
status_code
|
int | None
|
HTTP status code for successful responses. |
None
|
tags
|
list[str] | None
|
OpenAPI tags for grouping endpoints. |
None
|
dependencies
|
Sequence[Depends] | None
|
FastAPI dependencies to inject. |
None
|
summary
|
str | None
|
Short summary for OpenAPI documentation. |
None
|
description
|
str | None
|
Detailed description for OpenAPI documentation. |
None
|
response_description
|
str
|
Description of successful response. |
'Successful Response'
|
responses
|
dict[int | str, dict[str, Any]] | None
|
Additional response schemas for OpenAPI. |
None
|
deprecated
|
bool | None
|
Whether this endpoint is deprecated. |
None
|
methods
|
set[HTTPMethod] | list[HTTPMethod] | None
|
HTTP methods this route handles. |
None
|
operation_id
|
str | None
|
Custom OpenAPI operation ID. |
None
|
response_model_include
|
SetIntStr | DictIntStrAny | None
|
Fields to include in response model. |
None
|
response_model_exclude
|
SetIntStr | DictIntStrAny | None
|
Fields to exclude from response model. |
None
|
response_model_by_alias
|
bool
|
Use field aliases in response. |
True
|
response_model_exclude_unset
|
bool
|
Exclude unset fields from response. |
False
|
response_model_exclude_defaults
|
bool
|
Exclude fields with default values. |
False
|
response_model_exclude_none
|
bool
|
Exclude None values from response. |
False
|
include_in_schema
|
bool
|
Include in OpenAPI schema. |
True
|
response_class
|
type[Response]
|
FastAPI response class to use. |
JSONResponse
|
name
|
str | None
|
Display name for the route. |
None
|
route_class_override
|
type[APIRoute] | None
|
Custom APIRoute class. |
None
|
callbacks
|
list[Route] | None
|
OpenAPI callbacks configuration. |
None
|
openapi_extra
|
dict[str, Any] | None
|
Additional OpenAPI schema data. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
A decorator function that attaches the route configuration. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/routes/route.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
GET route decorator for FastAPI controllers.
Provides a convenience decorator for marking controller methods as HTTP GET endpoints with full FastAPI configuration support.
get(path, response_model=None, status_code=None, tags=None, dependencies=None, summary=None, description=None, response_description='Successful Response', responses=None, deprecated=None, operation_id=None, response_model_include=None, response_model_exclude=None, response_model_by_alias=True, response_model_exclude_unset=False, response_model_exclude_defaults=False, response_model_exclude_none=False, include_in_schema=True, response_class=JSONResponse, name=None, route_class_override=None, callbacks=None, openapi_extra=None)
¶
Decorator to mark a controller method as an HTTP GET endpoint.
Convenience wrapper around @route that automatically sets the HTTP method to GET. Supports all FastAPI route configuration options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The URL path for this route. |
required |
response_model
|
type[Any] | None
|
Pydantic model for response serialization. |
None
|
status_code
|
int | None
|
HTTP status code for successful responses. |
None
|
tags
|
list[str] | None
|
OpenAPI tags for grouping endpoints. |
None
|
dependencies
|
Sequence[Depends] | None
|
FastAPI dependencies to inject. |
None
|
summary
|
str | None
|
Short summary for OpenAPI documentation. |
None
|
description
|
str | None
|
Detailed description for OpenAPI documentation. |
None
|
response_description
|
str
|
Description of successful response. |
'Successful Response'
|
responses
|
dict[int | str, dict[str, Any]] | None
|
Additional response schemas for OpenAPI. |
None
|
deprecated
|
bool | None
|
Whether this endpoint is deprecated. |
None
|
operation_id
|
str | None
|
Custom OpenAPI operation ID. |
None
|
response_model_include
|
SetIntStr | DictIntStrAny | None
|
Fields to include in response model. |
None
|
response_model_exclude
|
SetIntStr | DictIntStrAny | None
|
Fields to exclude from response model. |
None
|
response_model_by_alias
|
bool
|
Use field aliases in response. |
True
|
response_model_exclude_unset
|
bool
|
Exclude unset fields from response. |
False
|
response_model_exclude_defaults
|
bool
|
Exclude fields with default values. |
False
|
response_model_exclude_none
|
bool
|
Exclude None values from response. |
False
|
include_in_schema
|
bool
|
Include in OpenAPI schema. |
True
|
response_class
|
type[Response]
|
FastAPI response class to use. |
JSONResponse
|
name
|
str | None
|
Display name for the route. |
None
|
route_class_override
|
type[APIRoute] | None
|
Custom APIRoute class. |
None
|
callbacks
|
list[Route] | None
|
OpenAPI callbacks configuration. |
None
|
openapi_extra
|
dict[str, Any] | None
|
Additional OpenAPI schema data. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
A decorator function that marks the method as a GET endpoint. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/routes/get.py
POST route decorator for FastAPI controllers.
Provides a convenience decorator for marking controller methods as HTTP POST endpoints with full FastAPI configuration support.
post(path, response_model=None, status_code=None, tags=None, dependencies=None, summary=None, description=None, response_description='Successful Response', responses=None, deprecated=None, operation_id=None, response_model_include=None, response_model_exclude=None, response_model_by_alias=True, response_model_exclude_unset=False, response_model_exclude_defaults=False, response_model_exclude_none=False, include_in_schema=True, response_class=JSONResponse, name=None, route_class_override=None, callbacks=None, openapi_extra=None)
¶
Decorator to mark a controller method as an HTTP POST endpoint.
Convenience wrapper around @route that automatically sets the HTTP method to POST. Supports all FastAPI route configuration options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The URL path for this route. |
required |
response_model
|
type[Any] | None
|
Pydantic model for response serialization. |
None
|
status_code
|
int | None
|
HTTP status code for successful responses. |
None
|
tags
|
list[str] | None
|
OpenAPI tags for grouping endpoints. |
None
|
dependencies
|
Sequence[Depends] | None
|
FastAPI dependencies to inject. |
None
|
summary
|
str | None
|
Short summary for OpenAPI documentation. |
None
|
description
|
str | None
|
Detailed description for OpenAPI documentation. |
None
|
response_description
|
str
|
Description of successful response. |
'Successful Response'
|
responses
|
dict[int | str, dict[str, Any]] | None
|
Additional response schemas for OpenAPI. |
None
|
deprecated
|
bool | None
|
Whether this endpoint is deprecated. |
None
|
operation_id
|
str | None
|
Custom OpenAPI operation ID. |
None
|
response_model_include
|
SetIntStr | DictIntStrAny | None
|
Fields to include in response model. |
None
|
response_model_exclude
|
SetIntStr | DictIntStrAny | None
|
Fields to exclude from response model. |
None
|
response_model_by_alias
|
bool
|
Use field aliases in response. |
True
|
response_model_exclude_unset
|
bool
|
Exclude unset fields from response. |
False
|
response_model_exclude_defaults
|
bool
|
Exclude fields with default values. |
False
|
response_model_exclude_none
|
bool
|
Exclude None values from response. |
False
|
include_in_schema
|
bool
|
Include in OpenAPI schema. |
True
|
response_class
|
type[Response]
|
FastAPI response class to use. |
JSONResponse
|
name
|
str | None
|
Display name for the route. |
None
|
route_class_override
|
type[APIRoute] | None
|
Custom APIRoute class. |
None
|
callbacks
|
list[Route] | None
|
OpenAPI callbacks configuration. |
None
|
openapi_extra
|
dict[str, Any] | None
|
Additional OpenAPI schema data. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
A decorator function that marks the method as a POST endpoint. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/routes/post.py
PUT route decorator for FastAPI controllers.
Provides a convenience decorator for marking controller methods as HTTP PUT endpoints with full FastAPI configuration support.
put(path, response_model=None, status_code=None, tags=None, dependencies=None, summary=None, description=None, response_description='Successful Response', responses=None, deprecated=None, operation_id=None, response_model_include=None, response_model_exclude=None, response_model_by_alias=True, response_model_exclude_unset=False, response_model_exclude_defaults=False, response_model_exclude_none=False, include_in_schema=True, response_class=JSONResponse, name=None, route_class_override=None, callbacks=None, openapi_extra=None)
¶
Decorator to mark a controller method as an HTTP PUT endpoint.
Convenience wrapper around @route that automatically sets the HTTP method to PUT. Supports all FastAPI route configuration options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The URL path for this route. |
required |
response_model
|
type[Any] | None
|
Pydantic model for response serialization. |
None
|
status_code
|
int | None
|
HTTP status code for successful responses. |
None
|
tags
|
list[str] | None
|
OpenAPI tags for grouping endpoints. |
None
|
dependencies
|
Sequence[Depends] | None
|
FastAPI dependencies to inject. |
None
|
summary
|
str | None
|
Short summary for OpenAPI documentation. |
None
|
description
|
str | None
|
Detailed description for OpenAPI documentation. |
None
|
response_description
|
str
|
Description of successful response. |
'Successful Response'
|
responses
|
dict[int | str, dict[str, Any]] | None
|
Additional response schemas for OpenAPI. |
None
|
deprecated
|
bool | None
|
Whether this endpoint is deprecated. |
None
|
operation_id
|
str | None
|
Custom OpenAPI operation ID. |
None
|
response_model_include
|
SetIntStr | DictIntStrAny | None
|
Fields to include in response model. |
None
|
response_model_exclude
|
SetIntStr | DictIntStrAny | None
|
Fields to exclude from response model. |
None
|
response_model_by_alias
|
bool
|
Use field aliases in response. |
True
|
response_model_exclude_unset
|
bool
|
Exclude unset fields from response. |
False
|
response_model_exclude_defaults
|
bool
|
Exclude fields with default values. |
False
|
response_model_exclude_none
|
bool
|
Exclude None values from response. |
False
|
include_in_schema
|
bool
|
Include in OpenAPI schema. |
True
|
response_class
|
type[Response]
|
FastAPI response class to use. |
JSONResponse
|
name
|
str | None
|
Display name for the route. |
None
|
route_class_override
|
type[APIRoute] | None
|
Custom APIRoute class. |
None
|
callbacks
|
list[Route] | None
|
OpenAPI callbacks configuration. |
None
|
openapi_extra
|
dict[str, Any] | None
|
Additional OpenAPI schema data. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
A decorator function that marks the method as a PUT endpoint. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/routes/put.py
PATCH route decorator for FastAPI controllers.
Provides a convenience decorator for marking controller methods as HTTP PATCH endpoints with full FastAPI configuration support.
patch(path, response_model=None, status_code=None, tags=None, dependencies=None, summary=None, description=None, response_description='Successful Response', responses=None, deprecated=None, operation_id=None, response_model_include=None, response_model_exclude=None, response_model_by_alias=True, response_model_exclude_unset=False, response_model_exclude_defaults=False, response_model_exclude_none=False, include_in_schema=True, response_class=JSONResponse, name=None, route_class_override=None, callbacks=None, openapi_extra=None)
¶
Decorator to mark a controller method as an HTTP PATCH endpoint.
Convenience wrapper around @route that automatically sets the HTTP method to PATCH. Supports all FastAPI route configuration options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The URL path for this route. |
required |
response_model
|
type[Any] | None
|
Pydantic model for response serialization. |
None
|
status_code
|
int | None
|
HTTP status code for successful responses. |
None
|
tags
|
list[str] | None
|
OpenAPI tags for grouping endpoints. |
None
|
dependencies
|
Sequence[Depends] | None
|
FastAPI dependencies to inject. |
None
|
summary
|
str | None
|
Short summary for OpenAPI documentation. |
None
|
description
|
str | None
|
Detailed description for OpenAPI documentation. |
None
|
response_description
|
str
|
Description of successful response. |
'Successful Response'
|
responses
|
dict[int | str, dict[str, Any]] | None
|
Additional response schemas for OpenAPI. |
None
|
deprecated
|
bool | None
|
Whether this endpoint is deprecated. |
None
|
operation_id
|
str | None
|
Custom OpenAPI operation ID. |
None
|
response_model_include
|
SetIntStr | DictIntStrAny | None
|
Fields to include in response model. |
None
|
response_model_exclude
|
SetIntStr | DictIntStrAny | None
|
Fields to exclude from response model. |
None
|
response_model_by_alias
|
bool
|
Use field aliases in response. |
True
|
response_model_exclude_unset
|
bool
|
Exclude unset fields from response. |
False
|
response_model_exclude_defaults
|
bool
|
Exclude fields with default values. |
False
|
response_model_exclude_none
|
bool
|
Exclude None values from response. |
False
|
include_in_schema
|
bool
|
Include in OpenAPI schema. |
True
|
response_class
|
type[Response]
|
FastAPI response class to use. |
JSONResponse
|
name
|
str | None
|
Display name for the route. |
None
|
route_class_override
|
type[APIRoute] | None
|
Custom APIRoute class. |
None
|
callbacks
|
list[Route] | None
|
OpenAPI callbacks configuration. |
None
|
openapi_extra
|
dict[str, Any] | None
|
Additional OpenAPI schema data. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
A decorator function that marks the method as a PATCH endpoint. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/routes/patch.py
DELETE route decorator for FastAPI controllers.
Provides a convenience decorator for marking controller methods as HTTP DELETE endpoints with full FastAPI configuration support.
delete(path, response_model=None, status_code=None, tags=None, dependencies=None, summary=None, description=None, response_description='Successful Response', responses=None, deprecated=None, operation_id=None, response_model_include=None, response_model_exclude=None, response_model_by_alias=True, response_model_exclude_unset=False, response_model_exclude_defaults=False, response_model_exclude_none=False, include_in_schema=True, response_class=JSONResponse, name=None, route_class_override=None, callbacks=None, openapi_extra=None)
¶
Decorator to mark a controller method as an HTTP DELETE endpoint.
Convenience wrapper around @route that automatically sets the HTTP method to DELETE. Supports all FastAPI route configuration options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The URL path for this route. |
required |
response_model
|
type[Any] | None
|
Pydantic model for response serialization. |
None
|
status_code
|
int | None
|
HTTP status code for successful responses. |
None
|
tags
|
list[str] | None
|
OpenAPI tags for grouping endpoints. |
None
|
dependencies
|
Sequence[Depends] | None
|
FastAPI dependencies to inject. |
None
|
summary
|
str | None
|
Short summary for OpenAPI documentation. |
None
|
description
|
str | None
|
Detailed description for OpenAPI documentation. |
None
|
response_description
|
str
|
Description of successful response. |
'Successful Response'
|
responses
|
dict[int | str, dict[str, Any]] | None
|
Additional response schemas for OpenAPI. |
None
|
deprecated
|
bool | None
|
Whether this endpoint is deprecated. |
None
|
operation_id
|
str | None
|
Custom OpenAPI operation ID. |
None
|
response_model_include
|
SetIntStr | DictIntStrAny | None
|
Fields to include in response model. |
None
|
response_model_exclude
|
SetIntStr | DictIntStrAny | None
|
Fields to exclude from response model. |
None
|
response_model_by_alias
|
bool
|
Use field aliases in response. |
True
|
response_model_exclude_unset
|
bool
|
Exclude unset fields from response. |
False
|
response_model_exclude_defaults
|
bool
|
Exclude fields with default values. |
False
|
response_model_exclude_none
|
bool
|
Exclude None values from response. |
False
|
include_in_schema
|
bool
|
Include in OpenAPI schema. |
True
|
response_class
|
type[Response]
|
FastAPI response class to use. |
JSONResponse
|
name
|
str | None
|
Display name for the route. |
None
|
route_class_override
|
type[APIRoute] | None
|
Custom APIRoute class. |
None
|
callbacks
|
list[Route] | None
|
OpenAPI callbacks configuration. |
None
|
openapi_extra
|
dict[str, Any] | None
|
Additional OpenAPI schema data. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
A decorator function that marks the method as a DELETE endpoint. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/routes/delete.py
HEAD route decorator for FastAPI controllers.
Provides a convenience decorator for marking controller methods as HTTP HEAD endpoints with full FastAPI configuration support.
head(path, response_model=None, status_code=None, tags=None, dependencies=None, summary=None, description=None, response_description='Successful Response', responses=None, deprecated=None, operation_id=None, response_model_include=None, response_model_exclude=None, response_model_by_alias=True, response_model_exclude_unset=False, response_model_exclude_defaults=False, response_model_exclude_none=False, include_in_schema=True, response_class=JSONResponse, name=None, route_class_override=None, callbacks=None, openapi_extra=None)
¶
Decorator to mark a controller method as an HTTP HEAD endpoint.
Convenience wrapper around @route that automatically sets the HTTP method to HEAD. Supports all FastAPI route configuration options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The URL path for this route. |
required |
response_model
|
type[Any] | None
|
Pydantic model for response serialization. |
None
|
status_code
|
int | None
|
HTTP status code for successful responses. |
None
|
tags
|
list[str] | None
|
OpenAPI tags for grouping endpoints. |
None
|
dependencies
|
Sequence[Depends] | None
|
FastAPI dependencies to inject. |
None
|
summary
|
str | None
|
Short summary for OpenAPI documentation. |
None
|
description
|
str | None
|
Detailed description for OpenAPI documentation. |
None
|
response_description
|
str
|
Description of successful response. |
'Successful Response'
|
responses
|
dict[int | str, dict[str, Any]] | None
|
Additional response schemas for OpenAPI. |
None
|
deprecated
|
bool | None
|
Whether this endpoint is deprecated. |
None
|
operation_id
|
str | None
|
Custom OpenAPI operation ID. |
None
|
response_model_include
|
SetIntStr | DictIntStrAny | None
|
Fields to include in response model. |
None
|
response_model_exclude
|
SetIntStr | DictIntStrAny | None
|
Fields to exclude from response model. |
None
|
response_model_by_alias
|
bool
|
Use field aliases in response. |
True
|
response_model_exclude_unset
|
bool
|
Exclude unset fields from response. |
False
|
response_model_exclude_defaults
|
bool
|
Exclude fields with default values. |
False
|
response_model_exclude_none
|
bool
|
Exclude None values from response. |
False
|
include_in_schema
|
bool
|
Include in OpenAPI schema. |
True
|
response_class
|
type[Response]
|
FastAPI response class to use. |
JSONResponse
|
name
|
str | None
|
Display name for the route. |
None
|
route_class_override
|
type[APIRoute] | None
|
Custom APIRoute class. |
None
|
callbacks
|
list[Route] | None
|
OpenAPI callbacks configuration. |
None
|
openapi_extra
|
dict[str, Any] | None
|
Additional OpenAPI schema data. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
A decorator function that marks the method as a HEAD endpoint. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/routes/head.py
OPTIONS route decorator for FastAPI controllers.
Provides a convenience decorator for marking controller methods as HTTP OPTIONS endpoints with full FastAPI configuration support.
options(path, response_model=None, status_code=None, tags=None, dependencies=None, summary=None, description=None, response_description='Successful Response', responses=None, deprecated=None, operation_id=None, response_model_include=None, response_model_exclude=None, response_model_by_alias=True, response_model_exclude_unset=False, response_model_exclude_defaults=False, response_model_exclude_none=False, include_in_schema=True, response_class=JSONResponse, name=None, route_class_override=None, callbacks=None, openapi_extra=None)
¶
Decorator to mark a controller method as an HTTP OPTIONS endpoint.
Convenience wrapper around @route that automatically sets the HTTP method to OPTIONS. Supports all FastAPI route configuration options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The URL path for this route. |
required |
response_model
|
type[Any] | None
|
Pydantic model for response serialization. |
None
|
status_code
|
int | None
|
HTTP status code for successful responses. |
None
|
tags
|
list[str] | None
|
OpenAPI tags for grouping endpoints. |
None
|
dependencies
|
Sequence[Depends] | None
|
FastAPI dependencies to inject. |
None
|
summary
|
str | None
|
Short summary for OpenAPI documentation. |
None
|
description
|
str | None
|
Detailed description for OpenAPI documentation. |
None
|
response_description
|
str
|
Description of successful response. |
'Successful Response'
|
responses
|
dict[int | str, dict[str, Any]] | None
|
Additional response schemas for OpenAPI. |
None
|
deprecated
|
bool | None
|
Whether this endpoint is deprecated. |
None
|
operation_id
|
str | None
|
Custom OpenAPI operation ID. |
None
|
response_model_include
|
SetIntStr | DictIntStrAny | None
|
Fields to include in response model. |
None
|
response_model_exclude
|
SetIntStr | DictIntStrAny | None
|
Fields to exclude from response model. |
None
|
response_model_by_alias
|
bool
|
Use field aliases in response. |
True
|
response_model_exclude_unset
|
bool
|
Exclude unset fields from response. |
False
|
response_model_exclude_defaults
|
bool
|
Exclude fields with default values. |
False
|
response_model_exclude_none
|
bool
|
Exclude None values from response. |
False
|
include_in_schema
|
bool
|
Include in OpenAPI schema. |
True
|
response_class
|
type[Response]
|
FastAPI response class to use. |
JSONResponse
|
name
|
str | None
|
Display name for the route. |
None
|
route_class_override
|
type[APIRoute] | None
|
Custom APIRoute class. |
None
|
callbacks
|
list[Route] | None
|
OpenAPI callbacks configuration. |
None
|
openapi_extra
|
dict[str, Any] | None
|
Additional OpenAPI schema data. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
A decorator function that marks the method as an OPTIONS endpoint. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/routes/options.py
WebSocket route decorator for FastAPI controllers.
Provides a decorator for marking controller methods as WebSocket endpoints with support for FastAPI WebSocket configuration.
WebSocketRoute(path, name=None, dependencies=None)
dataclass
¶
Bases: FunctionAnnotation
Function annotation for marking methods as WebSocket endpoints.
Stores WebSocket route configuration including path and dependencies.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
The URL path for this WebSocket endpoint. |
name |
str | None
|
Display name for the WebSocket route. |
dependencies |
Sequence[Depends] | None
|
FastAPI dependencies to inject. |
websocket(path, name=None, dependencies=None)
¶
Decorator to mark a controller method as a WebSocket endpoint.
Attaches WebSocket route configuration to the method which will be registered by the RegisterRoutesPostProcessor during container initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The URL path for this WebSocket endpoint. |
required |
name
|
str | None
|
Display name for the WebSocket route. |
None
|
dependencies
|
Sequence[Depends] | None
|
FastAPI dependencies to inject. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
A decorator function that attaches the WebSocket route configuration. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/routes/websocket.py
Server-Sent Events route decorator for FastAPI controllers.
Provides the @sse decorator for marking controller generator methods as
text/event-stream endpoints backed by FastAPI's native fastapi.sse support.
A coroutine method that returns an async iterator opens the stream in two
phases: the coroutine runs before the response starts, so its errors are
ordinary HTTP error responses, and the returned iterator is then streamed.
SseEndpointNotGeneratorError
¶
Bases: AbstractSpakkyFastAPIError
Raised when @sse decorates a method that is neither a generator nor a coroutine.
SseStreamNotAsyncIterableError
¶
Bases: AbstractSpakkyFastAPIError
Raised when a coroutine @sse method does not return an async iterator.
SseStreamOpener()
dataclass
¶
Bases: FunctionAnnotation
Marks a coroutine @sse method whose awaited result is the event stream.
The route registration awaits the method before the response starts and streams the async iterator it returns.
sse(path, methods=None, status_code=None, tags=None, dependencies=None, summary=None, description=None, response_description='Successful Response', responses=None, deprecated=None, operation_id=None, include_in_schema=True, name=None, openapi_extra=None)
¶
Decorator to mark a controller generator method as an SSE stream.
The decorated method must be an async generator (or a sync generator, which
FastAPI iterates in its thread pool), or a coroutine that returns an async
iterator. A coroutine runs before the response starts: an exception it
raises becomes the same HTTP error response as in a regular route, and the
returned iterator is then streamed. Each yielded ServerSentEvent is
written with its event/id/retry/comment fields; any other yielded
value is JSON-encoded into the data: field. Keep-alive comments and
cancellation on client disconnect are handled by FastAPI. Once the server
starts shutting down (ServerShutdownSignal), the stream ends normally
and the generator is closed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The URL path for this route. |
required |
methods
|
set[HTTPMethod] | list[HTTPMethod] | None
|
HTTP methods this stream handles. None means GET only. |
None
|
status_code
|
int | None
|
HTTP status code for successful responses. |
None
|
tags
|
list[str] | None
|
OpenAPI tags for grouping endpoints. |
None
|
dependencies
|
Sequence[Depends] | None
|
FastAPI dependencies to inject. |
None
|
summary
|
str | None
|
Short summary for OpenAPI documentation. |
None
|
description
|
str | None
|
Detailed description for OpenAPI documentation. |
None
|
response_description
|
str
|
Description of successful response. |
'Successful Response'
|
responses
|
dict[int | str, dict[str, Any]] | None
|
Additional response schemas for OpenAPI. |
None
|
deprecated
|
bool | None
|
Whether this endpoint is deprecated. |
None
|
operation_id
|
str | None
|
Custom OpenAPI operation ID. |
None
|
include_in_schema
|
bool
|
Include in OpenAPI schema. |
True
|
name
|
str | None
|
Display name for the route. |
None
|
openapi_extra
|
dict[str, Any] | None
|
Additional OpenAPI schema data. |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
A decorator function that attaches the SSE route configuration. |
Raises:
| Type | Description |
|---|---|
SseEndpointNotGeneratorError
|
If the method is neither a generator function nor a coroutine function. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/routes/sse.py
서버 종료 신호¶
Server shutdown signal that ends open Server-Sent Events streams.
On SIGTERM uvicorn stops accepting connections and then waits for every open
response to finish before it runs the ASGI lifespan shutdown. A stream that
never ends by itself therefore holds the process until
timeout_graceful_shutdown cancels it, and the lifespan shutdown is too late
to tell the stream to stop. ShutdownSignalRelay chains the server's own
SIGTERM/SIGINT handlers while the application serves, so the signal fires as
soon as the server starts shutting down, and every @sse stream registered by
the plugin ends normally once it fires.
SHUTDOWN_SIGNALS = (Signals.SIGTERM, Signals.SIGINT)
module-attribute
¶
Signals the server handles as a request to shut down gracefully.
SignalHandler = Callable[[int, FrameType | None], object]
¶
A Python-level signal handler as signal.signal installs it.
ShutdownGuardOutsideTaskError
¶
ServerShutdownSignal()
¶
Fires once when the server starts shutting down.
The plugin fires it from the server's SIGTERM/SIGINT handling and again from the lifespan shutdown, and re-arms it when the lifespan starts. A controller can inject it to stop its own long-running work, and every @sse stream ends normally once it fires, so the client reconnects with the SSE retry to another server.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/shutdown.py
triggered
property
¶
Whether the server has started shutting down.
trigger()
¶
Mark the server as shutting down and wake every waiter.
Safe to call from any thread: each waiter is released on its own event loop. A waiter whose loop is already closed can never resume, so it is skipped and the remaining waiters are still released.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/shutdown.py
reset()
¶
wait()
async
¶
Return once the server has started shutting down.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/shutdown.py
stream_until_shutdown(stream)
async
¶
Yield the stream's items until it ends or the server shuts down.
The stream is driven in the consuming task itself, so task-bound
constructs that span a yield in the stream (anyio cancel scopes and
task groups, asyncio.timeout, current_task()-scoped sessions,
context variable tokens) behave as they do without this guard. When
the signal fires while the task waits for the next item, that wait is
cancelled with an asyncio cancellation, which an anyio shield does not
stop: a shielded await or an anyio.to_thread.run_sync or Starlette
run_in_threadpool wait inside the stream is interrupted too, while
the worker thread keeps running. The stream's finally therefore
must not close or change a resource the worker thread may still use.
An item the stream still produces is dropped. The stream is then
closed, so a started generator's finally runs, and this generator
returns normally. A cancellation requested by anyone else at the same
time is propagated, not swallowed.
The interrupt is requested once. When a cancel scope inside the stream is cancelled in the same loop turn, the scope can absorb the interrupt with its own cancellation; if the stream then waits again without producing an item, it stays open until its next item or until the server's graceful shutdown timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream
|
AsyncIterator[T]
|
The event stream an @sse method produced. |
required |
Yields:
| Type | Description |
|---|---|
AsyncGenerator[T]
|
The stream's items, in order. |
Raises:
| Type | Description |
|---|---|
ShutdownGuardOutsideTaskError
|
Iterated outside an asyncio task. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/shutdown.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
iterate_until_shutdown(iterator)
¶
Yield the iterator's items until it ends or the server shuts down.
A sync @sse generator runs in a worker thread that cannot be
interrupted, so the signal is checked whenever the generator produces
an item or asks for the next one. The iterator is then closed, so a
generator's finally runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterator
|
Iterator[T]
|
The event iterator a sync @sse method produced. |
required |
Yields:
| Type | Description |
|---|---|
Generator[T]
|
The iterator's items, in order. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/shutdown.py
ShutdownSignalRelay(shutdown, loop)
¶
Chains the server's shutdown signal handlers to a ServerShutdownSignal.
ASGI has no event for the start of a server shutdown, so the relay wraps
the Python-level SIGTERM/SIGINT handlers the server installed (uvicorn
installs them before it starts the lifespan). Each signal first fires the
shutdown signal on the server's event loop and then runs the server's
handler unchanged. Signals whose handler is SIG_DFL or SIG_IGN are
not touched; any callable handler is wrapped, including Python's
default_int_handler for SIGINT.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/shutdown.py
install()
¶
Chain the server's handlers; only the main thread can do this.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/shutdown.py
uninstall()
¶
Restore each handler this relay replaced and still owns.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/shutdown.py
relay(signal_number, frame)
¶
Fire the shutdown signal, then run the server's own handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_number
|
int
|
The received signal. |
required |
frame
|
FrameType | None
|
The interrupted stack frame. |
required |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/shutdown.py
미들웨어¶
Error handling middleware for FastAPI applications.
Provides global exception handling that converts Spakky FastAPI errors to appropriate JSON responses and handles unexpected exceptions gracefully.
ErrorHandlingMiddleware(app, dispatch=None, debug=False)
¶
Bases: BaseHTTPMiddleware
Middleware that catches and converts exceptions to JSON responses.
Handles both Spakky FastAPI errors and unexpected exceptions, converting them to appropriate JSON responses with correct HTTP status codes.
Initialize the error handling middleware.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
ASGIApp
|
The ASGI application. |
required |
dispatch
|
DispatchFunction | None
|
Optional custom dispatch function. |
None
|
debug
|
bool
|
Whether to include tracebacks in error responses. |
False
|
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/middlewares/error_handling.py
dispatch(request, call_next)
async
¶
Process the request with error handling.
Catches exceptions during request processing and converts them to appropriate JSON responses. Spakky FastAPI errors are converted using their to_response() method, while unexpected exceptions return 500.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming HTTP request. |
required |
call_next
|
Next
|
Function to call the next middleware or route handler. |
required |
Returns:
| Type | Description |
|---|---|
Response
|
The HTTP response, either from successful processing or error handling. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/middlewares/error_handling.py
Tracing middleware for W3C Trace Context propagation.
Extracts trace context from incoming HTTP request headers, activates a child span for the request lifetime, and injects trace context into response headers.
TracingMiddleware(app, dispatch=None, *, propagator)
¶
Bases: BaseHTTPMiddleware
Middleware that propagates W3C Trace Context across HTTP boundaries.
Extracts traceparent from request headers, activates a child span
for the request lifetime, and injects traceparent into response
headers. When no incoming trace context is present, a new root trace
is started.
Initialize the tracing middleware.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
ASGIApp
|
The ASGI application. |
required |
dispatch
|
DispatchFunction | None
|
Optional custom dispatch function. |
None
|
propagator
|
ITracePropagator
|
Trace context propagator for extract/inject. |
required |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/middlewares/tracing.py
dispatch(request, call_next)
async
¶
Extract trace context, process request, and inject into response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming HTTP request. |
required |
call_next
|
Next
|
Function to call the next middleware or route handler. |
required |
Returns:
| Type | Description |
|---|---|
Response
|
The HTTP response with trace context headers injected. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/middlewares/tracing.py
설정¶
FastAPI application configuration.
SPAKKY_FASTAPI_CONFIG_ENV_PREFIX = 'SPAKKY_FASTAPI_'
module-attribute
¶
Environment prefix for the default FastAPI application settings.
후처리기¶
Post-processor for binding FastAPI lifespan to ApplicationContext lifecycle.
Automatically wraps FastAPI lifespan to ensure ApplicationContext.stop() is called when FastAPI shuts down, enabling graceful shutdown of background services like RabbitMQ consumers.
BindLifespanPostProcessor
¶
Bases: IPostProcessor, IApplicationContextAware
Post-processor that binds FastAPI lifespan to ApplicationContext lifecycle.
Wraps the FastAPI lifespan handler to ensure ApplicationContext.stop() is called when FastAPI shuts down. This enables graceful shutdown of all background services registered with the application context.
While the lifespan runs, the server's SIGTERM/SIGINT handlers are chained
to the ServerShutdownSignal, so open @sse streams end as soon as the
server starts shutting down. The signal also fires when the lifespan ends
and is re-armed when it starts again.
User-defined lifespan handlers are preserved and executed normally.
set_application_context(application_context)
¶
Set the application context for lifecycle binding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
application_context
|
IApplicationContext
|
The application context to stop on shutdown. |
required |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/post_processors/bind_lifespan.py
post_process(pod)
¶
Wrap FastAPI lifespan to bind ApplicationContext lifecycle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
object
|
The Pod to process. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The Pod with lifespan wrapped if it's a FastAPI instance. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/post_processors/bind_lifespan.py
Post-processor for adding built-in middleware to FastAPI applications.
Automatically injects error handling and context management middleware into FastAPI instances registered in the container. When the tracing plugin is loaded, tracing middleware is also added.
AddBuiltInMiddlewaresPostProcessor
¶
Bases: IPostProcessor, IApplicationContextAware
Post-processor that adds built-in middleware to FastAPI instances.
Injects error handling and tracing middleware into any FastAPI instance created as a Pod. Tracing middleware is only added when the tracing plugin is loaded. Runs early in the post-processor chain (Order 0).
set_application_context(application_context)
¶
Set the application context for middleware injection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
application_context
|
IApplicationContext
|
The application context to use for middleware. |
required |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/post_processors/add_builtin_middlewares.py
post_process(pod)
¶
Add built-in middleware to FastAPI instances.
If the Pod is a FastAPI instance, adds error handling middleware and optionally tracing middleware. Non-FastAPI Pods are returned unchanged.
Middleware execution order (outermost first):
1. TracingMiddleware — extract/inject W3C Trace Context
2. ErrorHandlingMiddleware — catch exceptions → JSON responses
add_middleware prepends, so the last added middleware executes first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
object
|
The Pod to process. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The Pod, potentially with middleware added if it's a FastAPI instance. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/post_processors/add_builtin_middlewares.py
Post-processor for registering API controller routes.
Automatically discovers and registers routes from @ApiController decorated classes, creating FastAPI endpoints with proper dependency injection.
OPENED_STREAM_PARAMETER = '__spakky_opened_event_stream__'
module-attribute
¶
Endpoint parameter that receives the stream a coroutine @sse method opened.
RegisterRoutesPostProcessor
¶
Bases: IPostProcessor, IContainerAware, IApplicationContextAware
Post-processor that registers routes from API controllers.
Scans @ApiController decorated classes for @route decorated methods and automatically registers them as FastAPI endpoints with proper dependency injection and response model inference.
set_container(container)
¶
Set the container for dependency injection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
IContainer
|
The IoC container. |
required |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/post_processors/register_routes.py
set_application_context(application_context)
¶
Set the application context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
application_context
|
IApplicationContext
|
The application context. |
required |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/post_processors/register_routes.py
__fastapi_apps()
¶
Return all FastAPI application Pods currently registered.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/post_processors/register_routes.py
post_process(pod)
¶
Register routes from API controllers.
Scans the controller for methods decorated with @route or @websocket and registers them as FastAPI endpoints. Automatically infers response models from return type annotations and sets up dependency injection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
object
|
The Pod to process, potentially an API controller. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The Pod, with routes registered if it's an API controller. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/post_processors/register_routes.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
__add_event_stream_route(router, controller, name, method, declared_method, route)
¶
Register a generator method as a native FastAPI SSE stream.
FastAPI recognizes a generator endpoint through functools.wraps
(__wrapped__ is the generator function declared on the class) and calls it in the request handler before the response starts. The plain
function below therefore resolves the controller and authenticates
eagerly, so an auth failure is still an HTTP error response, and then
hands the generator, guarded by the ServerShutdownSignal so it ends
normally once the server starts shutting down, to FastAPI, which
encodes the events, sends keep-alive comments and cancels the
generator when the client leaves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
router
|
APIRouter
|
Router collecting the controller routes. |
required |
controller
|
ApiController
|
Controller stereotype of the Pod being processed. |
required |
name
|
str
|
Attribute name of the generator method on the controller. |
required |
method
|
Callable[..., Any]
|
The generator method found on the controller Pod. |
required |
declared_method
|
Callable[..., Any]
|
The same method as declared on the controller class, which FastAPI inspects to recognize a generator endpoint. |
required |
route
|
Route
|
Route configuration whose response class is an SSE response. |
required |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/post_processors/register_routes.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
__add_opened_event_stream_route(router, controller, name, method, route)
¶
Register a coroutine @sse method as a two-phase SSE stream.
The coroutine runs as a FastAPI dependency of the stream endpoint. FastAPI resolves dependencies before it calls the endpoint and starts the response, so an exception from the coroutine (including an auth failure) becomes the same HTTP error response as in a regular route. The endpoint is an async generator that streams the iterator the coroutine returned, so FastAPI still encodes the events, sends keep-alive comments and cancels the stream when the client leaves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
router
|
APIRouter
|
Router collecting the controller routes. |
required |
controller
|
ApiController
|
Controller stereotype of the Pod being processed. |
required |
name
|
str
|
Attribute name of the coroutine method on the controller. |
required |
method
|
Callable[..., Any]
|
The coroutine method found on the controller Pod. |
required |
route
|
Route
|
Route configuration whose response class is an SSE response. |
required |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/post_processors/register_routes.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
Post-processor for registering actuator HTTP endpoints.
RegisterActuatorPostProcessor
¶
Bases: IPostProcessor, IContainerAware
Register actuator endpoints when the actuator service is available.
set_container(container)
¶
Set the container used to resolve actuator dependencies.
post_process(pod)
¶
Register actuator routes on FastAPI instances.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/post_processors/register_actuator.py
Actuator¶
에러¶
HTTP error classes for FastAPI integration.
Provides base error classes and common HTTP error responses that integrate with FastAPI's error handling system. All errors can be converted to JSON responses with appropriate HTTP status codes.
AbstractSpakkyFastAPIError
¶
Bases: AbstractSpakkyFrameworkError, ABC
Base error class for FastAPI-related exceptions.
Provides automatic conversion to FastAPI JSON responses with appropriate HTTP status codes. Subclasses should define a status_code class variable.
Attributes:
| Name | Type | Description |
|---|---|---|
status_code |
int
|
HTTP status code for this error type. |
message |
str
|
Human-readable error message. |
status_code
class-attribute
¶
HTTP status code returned for this error type.
to_response(show_traceback=False)
¶
Convert the error to a FastAPI JSON response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show_traceback
|
bool
|
Whether to include the full traceback in the response. |
False
|
Returns:
| Type | Description |
|---|---|
JSONResponse
|
A JSON response containing the error message, args, and optional traceback. |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/error.py
BadRequest
¶
Unauthorized
¶
Forbidden
¶
NotFound
¶
Conflict
¶
InternalServerError
¶
플러그인 진입점¶
Plugin initialization for FastAPI integration.
Registers post-processors that enable automatic route registration and built-in middleware injection for FastAPI applications.
fastapi_app(config)
¶
Create the default FastAPI application managed by the plugin.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/main.py
initialize(app)
¶
Initialize the FastAPI plugin.
Registers post-processors for automatic route registration and middleware injection. This function is called automatically by the Spakky framework during plugin loading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
SpakkyApplication
|
The Spakky application instance. |
required |
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/main.py
추가 모듈¶
Authentication boundary helpers for FastAPI routes.
HANDLER_ATTRIBUTE_NAME = 'handler'
module-attribute
¶
AuthInvocation attribute carrying the handler's qualified name.
HTTP_HEADER_ATTRIBUTE_PREFIX = 'http.header.'
module-attribute
¶
AuthInvocation attribute prefix for request headers (lowercase names).
HTTP_PATH_ATTRIBUTE_PREFIX = 'http.path.'
module-attribute
¶
AuthInvocation attribute prefix for matched path parameters.
HTTP_QUERY_ATTRIBUTE_PREFIX = 'http.query.'
module-attribute
¶
AuthInvocation attribute prefix for query parameters.
CREDENTIAL_HEADER_NAMES = frozenset({'authorization', 'cookie', 'proxy-authorization'})
module-attribute
¶
Headers kept out of AuthInvocation attributes because they carry credentials.
FastAPIAuthBoundary(container, application_context)
¶
Seed AuthContext and map auth failures at FastAPI boundaries.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/auth.py
seed_http_auth_context(request, boundary)
¶
Authenticate an HTTP credential and seed AuthContext when present.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/auth.py
seed_websocket_auth_context(websocket, boundary)
¶
Authenticate a WebSocket credential and seed AuthContext when present.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/auth.py
map_http_auth_error(error)
¶
Raise the FastAPI HTTP error corresponding to an auth failure.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/auth.py
close_websocket_for_auth_error(websocket, error)
async
¶
Close a WebSocket with the code matching the auth failure class.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/auth.py
signature_with_request(boundary)
¶
Return a FastAPI signature that injects Request without user handlers.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/auth.py
signature_with_websocket(boundary)
¶
Return a FastAPI signature that injects WebSocket without auth-only args.
Source code in plugins/spakky-fastapi/src/spakky/plugins/fastapi/auth.py
request_argument_names(boundary)
¶
Return user handler parameter names that expect FastAPI Request.
websocket_argument_names(boundary)
¶
Return user handler parameter names that expect FastAPI WebSocket.