fastapi-reloader API Reference
fastapi_reloader
¶
auto_refresh_middleware
module-attribute
¶
auto_refresh_middleware = UniversalMiddleware(
patch_for_auto_reloading
)
This middleware combines the two middlewares above to enable the full functionality of this package.
html_injection_middleware
module-attribute
¶
html_injection_middleware = UniversalMiddleware(
lambda app: BaseHTTPMiddleware(
app, _injection_http_middleware
)
)
This middleware injects the HMR client script into HTML responses.
reloader_route_middleware
module-attribute
¶
reloader_route_middleware = UniversalMiddleware(
_wrap_asgi_app
)
This middleware wraps the app with a FastAPI app that handles reload signals.
__all__
module-attribute
¶
__all__ = [
"auto_refresh_middleware",
"html_injection_middleware",
"patch_for_auto_reloading",
"reloader_route_middleware",
"send_reload_signal",
]
send_reload_signal
¶
send_reload_signal()
Broadcast a reload signal to all connected clients and break their long-polling connections.
Source code in packages/fastapi-reloader/fastapi_reloader/core.py
14 15 16 17 18 |
|
patch_for_auto_reloading
¶
patch_for_auto_reloading(app: ASGIApp)
Source code in packages/fastapi-reloader/fastapi_reloader/patcher.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
core
¶
get_id
module-attribute
¶
get_id = __next__
requests
module-attribute
¶
requests: dict[int, list[Queue[Literal[0, 1]]]] = (
defaultdict(list)
)
reload_router
module-attribute
¶
reload_router = APIRouter(
prefix="/---fastapi-reloader---", tags=["hmr"]
)
send_reload_signal
¶
send_reload_signal()
Broadcast a reload signal to all connected clients and break their long-polling connections.
Source code in packages/fastapi-reloader/fastapi_reloader/core.py
14 15 16 17 18 |
|
heartbeat
async
¶
heartbeat()
Source code in packages/fastapi-reloader/fastapi_reloader/core.py
24 25 26 |
|
subscribe
async
¶
subscribe()
Source code in packages/fastapi-reloader/fastapi_reloader/core.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
patcher
¶
INJECTION
module-attribute
¶
INJECTION = encode()
FLAG
module-attribute
¶
FLAG = ' fastapi-reloader-injected '
T
module-attribute
¶
T = TypeVar('T', bound=ASGIApp)
html_injection_middleware
module-attribute
¶
html_injection_middleware = UniversalMiddleware(
lambda app: BaseHTTPMiddleware(
app, _injection_http_middleware
)
)
This middleware injects the HMR client script into HTML responses.
reloader_route_middleware
module-attribute
¶
reloader_route_middleware = UniversalMiddleware(
_wrap_asgi_app
)
This middleware wraps the app with a FastAPI app that handles reload signals.
auto_refresh_middleware
module-attribute
¶
auto_refresh_middleware = UniversalMiddleware(
patch_for_auto_reloading
)
This middleware combines the two middlewares above to enable the full functionality of this package.
UniversalMiddleware
¶
Bases: Middleware, Generic[T]
Adapt an ASGI middleware so it can serve both Starlette/FastAPI middleware slots and plain ASGI usage.
Source code in packages/fastapi-reloader/fastapi_reloader/patcher.py
56 57 58 59 60 61 62 63 64 |
|
fn
instance-attribute
¶
fn = asgi_middleware
__init__
¶
__init__(asgi_middleware: Callable[[ASGIApp], T])
Source code in packages/fastapi-reloader/fastapi_reloader/patcher.py
59 60 61 |
|
__call__
¶
__call__(app)
Source code in packages/fastapi-reloader/fastapi_reloader/patcher.py
63 64 |
|
is_streaming_response
¶
is_streaming_response(
response: Response,
) -> TypeGuard[StreamingResponse]
Source code in packages/fastapi-reloader/fastapi_reloader/patcher.py
21 22 23 |
|
_injection_http_middleware
async
¶
_injection_http_middleware(
request: Request,
call_next: Callable[[Request], Awaitable[Response]],
)
Source code in packages/fastapi-reloader/fastapi_reloader/patcher.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
_wrap_asgi_app
¶
_wrap_asgi_app(app: ASGIApp)
Source code in packages/fastapi-reloader/fastapi_reloader/patcher.py
71 72 73 74 75 76 77 78 79 80 81 |
|
patch_for_auto_reloading
¶
patch_for_auto_reloading(app: ASGIApp)
Source code in packages/fastapi-reloader/fastapi_reloader/patcher.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|