fastapi_tools
¶
fastapi_tools package.
Modules:
-
auth–Authentication service modules.
-
config–Configuration module for the fastapi_tools package.
-
data_models–fastapi_tools package.
-
dependencies–FastAPI dependency injection functions.
-
exceptions–Custom HTTP exceptions for the webapp.
-
factory–FastAPI application factory.
-
metaclasses–Configuration module for the fastapi_tools package.
-
middleware–Custom middleware for the webapp.
-
params–fastapi_tools package.
-
routers–Router modules for fastapi_tools.
-
schemas–Schema modules for fastapi_tools.
-
security–Security utilities for the webapp.
-
templating–Jinja2 template engine configuration.
-
utils–Utility modules for fastapi_tools.
Classes:
-
GoogleOAuthConfig–Google OAuth 2.0 configuration.
-
NotAuthenticatedException–Raised when a request requires authentication but none was provided.
-
NotAuthorizedException–Raised when the authenticated user lacks required permissions.
-
RateLimitExceededException–Raised when a client exceeds the configured rate limit.
-
SessionConfig–Session management configuration.
-
WebappConfig–Main webapp configuration aggregating all sub-configs.
Functions:
-
create_app–Create and configure a FastAPI application.
-
get_current_user–Require an authenticated user; raises NotAuthenticatedException otherwise.
-
get_optional_user–Get the current user if authenticated, or None.
GoogleOAuthConfig
¶
NotAuthenticatedException
¶
Bases: HTTPException
Raised when a request requires authentication but none was provided.
Source code in src/fastapi_tools/exceptions.py
NotAuthorizedException
¶
RateLimitExceededException
¶
Bases: HTTPException
Raised when a client exceeds the configured rate limit.
Source code in src/fastapi_tools/exceptions.py
SessionConfig
¶
WebappConfig
¶
create_app
¶
create_app(
config: WebappConfig,
*,
extra_routers: list[APIRouter] | None = None,
static_dir: Path | str | None = None,
templates_dir: Path | str | None = None,
lifespan: Callable | None = None,
) -> FastAPI
Create and configure a FastAPI application.
Parameters:
-
config(WebappConfig) –Webapp configuration.
-
extra_routers(list[APIRouter] | None, default:None) –Additional routers to include (project-specific).
-
static_dir(Path | str | None, default:None) –Path to static files directory. If None, /static not mounted.
-
templates_dir(Path | str | None, default:None) –Path to templates directory. If None, templating not configured.
-
lifespan(Callable | None, default:None) –Custom lifespan context manager. If None, a default is used that initialises SessionStore and GoogleAuthService only.
Returns:
-
FastAPI–Configured FastAPI application instance.
Source code in src/fastapi_tools/factory.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 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 | |
get_current_user
async
¶
get_current_user(
session: Annotated[
SessionData | None, Depends(get_current_session)
],
) -> SessionData
Require an authenticated user; raises NotAuthenticatedException otherwise.
Source code in src/fastapi_tools/dependencies.py
get_optional_user
async
¶
get_optional_user(
session: Annotated[
SessionData | None, Depends(get_current_session)
],
) -> SessionData | None
Get the current user if authenticated, or None.