API reference¶
Generated from the installed package. For the full list of re-exports, see
FasterAPI/__init__.py.
FasterAPI
¶
FasterAPI — A high-performance ASGI web framework.
Drop-in FastAPI replacement powered by msgspec (C extension JSON), radix-tree routing, uvloop, and Python 3.13 sub-interpreters.
BackgroundTask
¶
A single background task to be executed after a response is sent.
Source code in FasterAPI/background.py
run()
async
¶
Execute the background task.
BackgroundTasks
¶
A collection of background tasks to be executed after a response is sent.
Source code in FasterAPI/background.py
add_task(func, *args, **kwargs)
¶
BaseHTTPMiddleware
¶
Base class for HTTP middleware that wraps an ASGI application.
Source code in FasterAPI/middleware.py
dispatch(scope, receive, send)
async
¶
Process the request. Override this method in subclasses.
Source code in FasterAPI/middleware.py
Body
¶
Declare a request body parameter with optional default and embed mode.
Source code in FasterAPI/params.py
CORSMiddleware
¶
Bases: BaseHTTPMiddleware
Middleware that handles Cross-Origin Resource Sharing (CORS) headers.
Source code in FasterAPI/middleware.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 | |
dispatch(scope, receive, send)
async
¶
Handle CORS preflight requests and inject CORS headers into responses.
Source code in FasterAPI/middleware.py
Cookie
¶
Declare a cookie parameter with an optional default value.
Source code in FasterAPI/params.py
Depends
¶
Declare a dependency to be resolved and injected into a route handler.
Source code in FasterAPI/dependencies.py
Faster
¶
The main FasterAPI application class, implementing the ASGI interface.
Source code in FasterAPI/app.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 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 278 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 364 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 | |
FasterRouter
¶
API router for grouping routes with a common prefix and tags.
Source code in FasterAPI/router.py
File
¶
Declare a file upload parameter.
Source code in FasterAPI/params.py
FileResponse
¶
Response that sends a file as an attachment.
Source code in FasterAPI/response.py
to_asgi(send)
async
¶
Read the file and send it through the ASGI interface.
Source code in FasterAPI/response.py
Form
¶
Declare a form field parameter with an optional default value.
Source code in FasterAPI/params.py
FormData
¶
Bases: dict[str, Any]
Dict subclass for form data that may contain UploadFile values.
Source code in FasterAPI/datastructures.py
GZipMiddleware
¶
Bases: BaseHTTPMiddleware
Middleware that compresses responses using gzip when the client supports it.
Source code in FasterAPI/middleware.py
dispatch(scope, receive, send)
async
¶
Compress the response body with gzip if it exceeds the minimum size.
Source code in FasterAPI/middleware.py
HTMLResponse
¶
HTTPException
¶
Bases: Exception
An HTTP exception that results in an error response with the given status code.
Source code in FasterAPI/exceptions.py
HTTPSRedirectMiddleware
¶
Bases: BaseHTTPMiddleware
Middleware that redirects all HTTP requests to HTTPS.
Source code in FasterAPI/middleware.py
Header
¶
Declare a header parameter with optional default and alias.
Source code in FasterAPI/params.py
JSONResponse
¶
Bases: Response
Response that serializes content as JSON using msgspec.
Source code in FasterAPI/response.py
Path
¶
Declare a path parameter with optional default and description.
Source code in FasterAPI/params.py
PlainTextResponse
¶
Query
¶
Declare a query parameter with optional default, description, and alias.
Source code in FasterAPI/params.py
RadixRouter
¶
O(k) URL router using a compressed radix tree (k = path segments).
Source code in FasterAPI/router.py
add_route(method, path, handler, metadata=None)
¶
Register a handler for the given HTTP method and path pattern.
Source code in FasterAPI/router.py
resolve(method, path)
¶
Resolve a path to (handler, path_params, metadata) or None.
Source code in FasterAPI/router.py
RedirectResponse
¶
Bases: Response
Response that redirects to a different URL.
Source code in FasterAPI/response.py
Request
¶
Represents an incoming HTTP request with lazy attribute parsing.
Source code in FasterAPI/request.py
25 26 27 28 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 | |
form()
async
¶
Read the request body and parse as form / multipart data.
Source code in FasterAPI/request.py
RequestValidationError
¶
Bases: Exception
Raised when request data fails validation.
Source code in FasterAPI/exceptions.py
Response
¶
Base HTTP response class.
Source code in FasterAPI/response.py
to_asgi(send)
async
¶
Send the response through the ASGI interface.
Source code in FasterAPI/response.py
StreamingResponse
¶
Response that streams content from an async or sync iterator.
Source code in FasterAPI/response.py
to_asgi(send)
async
¶
Stream the response body through the ASGI interface.
Source code in FasterAPI/response.py
SubInterpreterPool
¶
Fallback pool using ProcessPoolExecutor.
Provides the same run() / shutdown() API as the
sub-interpreter pool. Upgrade to a Python version with the
interpreters module for true per-interpreter GIL support.
Source code in FasterAPI/concurrency.py
run(func, *args)
async
¶
Execute func in a worker process (pickle-based).
Source code in FasterAPI/concurrency.py
TestClient
¶
Synchronous test client for FasterAPI applications.
Wraps ASGI app with httpx.ASGITransport for HTTP testing. Provides websocket_connect() for WebSocket testing.
Source code in FasterAPI/testclient.py
73 74 75 76 77 78 79 80 81 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 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
delete(url, **kwargs)
¶
get(url, **kwargs)
¶
head(url, **kwargs)
¶
options(url, **kwargs)
¶
patch(url, **kwargs)
¶
post(url, **kwargs)
¶
put(url, **kwargs)
¶
websocket_connect(path, headers=None, query_string='')
¶
Context manager for testing WebSocket endpoints.
Source code in FasterAPI/testclient.py
TrustedHostMiddleware
¶
Bases: BaseHTTPMiddleware
Middleware that validates the Host header against a list of allowed hosts.
Source code in FasterAPI/middleware.py
UploadFile
¶
Represents an uploaded file from a multipart/form-data request.
Uses SpooledTemporaryFile: data stays in memory up to 1 MB, then spills to disk.
Source code in FasterAPI/datastructures.py
WebSocket
¶
Represents a WebSocket connection.
Source code in FasterAPI/websocket.py
accept(subprotocol=None)
async
¶
Accept the WebSocket connection, optionally selecting a subprotocol.
Source code in FasterAPI/websocket.py
close(code=1000, reason='')
async
¶
Close the WebSocket connection.
receive_bytes()
async
¶
Receive a binary message from the WebSocket.
receive_json()
async
¶
receive_text()
async
¶
send_bytes(data)
async
¶
send_json(data)
async
¶
Send data as a JSON-encoded text message through the WebSocket.
WebSocketDisconnect
¶
WebSocketState
¶
run_in_subinterpreter(func, *args)
async
¶
Execute func with maximum available parallelism.
Python 3.13+: Runs in a sub-interpreter with its own GIL. True parallel execution, no pickling, ~100x lighter than a process.
Python 3.11–3.12: Falls back to ProcessPoolExecutor.
Arguments must be picklable. Still achieves parallelism via
multiprocessing.
Python < 3.11: Same as 3.11 fallback with older asyncio internals.
Usage::
result = await run_in_subinterpreter(heavy_computation, n)