feat: implement missing FastAPI-parity features#24
Merged
Conversation
Security utilities (OAuth2PasswordBearer, OAuth2PasswordRequestForm,
SecurityScopes, HTTPBasic, APIKeyHeader/Query/Cookie), lifespan async
context manager, response_model/include/exclude field filtering,
Annotated[T, Depends()] PEP-593 style injection, sub-application
mounting via app.mount(), EventSourceResponse (SSE), ORJSONResponse/
UJSONResponse aliases, datetime/UUID/Decimal JSON serialization,
multiple response declarations (responses={404:...}), router-level
dependencies, dataclass request body support, enum path param
OpenAPI schemas, openapi_tags/terms_of_service/contact/license_info
in app constructor, and StaticFiles + Jinja2Templates integrations.
TestClient gains lifespan startup/shutdown support via background thread.
31 new tests; 234 total passing.
https://claude.ai/code/session_0175FLYUJtjUuigZeBQnscSB
- app.py: remove unused AsyncGenerator/asynccontextmanager/msgspec imports, drop forward-ref quotes on Faster type, use contextlib.suppress for StopAsyncIteration - dependencies.py: use callable() instead of hasattr(__call__), use inspect.getattr_static to fetch __call__ for type-hint resolution - openapi/generator.py: fix import order, rename dict_schema/extra_schema to avoid no-redef, remove stale type:ignore comment - security.py: remove forward-ref quotes on from_request return type, add raise-from on HTTPException, explicit str() casts in from_request - staticfiles.py: remove unused os import - tests/test_new_features.py: fix import sort, drop unused pytest/StaticFiles https://claude.ai/code/session_0175FLYUJtjUuigZeBQnscSB
Keep our encode_json/ORJSONResponse/UJSONResponse additions in response.py, take upstream benchmark numbers in README. https://claude.ai/code/session_0175FLYUJtjUuigZeBQnscSB
Contributor
Benchmark results
🟢 Benchmark status: improvement detected. HTTP throughput (FasterAPI vs FastAPI vs Fiber)
Direct ASGI (no HTTP; 50,000 iterations)
Routing (radix vs regex, 1,500,000 lookups)
How to read this
|
…ge cases Adds 28 new tests to bring total coverage from 82.71% to 85.97%, passing the 85% CI threshold. Covers StaticFiles path traversal, html mode, error responses; Jinja2Templates rendering; and security auto_error=False paths. https://claude.ai/code/session_0175FLYUJtjUuigZeBQnscSB
jinja2 is used in tests/test_coverage_gaps.py to cover Jinja2Templates. Without it installed in CI, those tests are skipped, dropping total coverage below the 85% threshold. https://claude.ai/code/session_0175FLYUJtjUuigZeBQnscSB
… 3.13 On Python 3.13, mypy flags `f.default_factory is not dataclasses.MISSING` as a [misc] error because the typeshed types for Field.default_factory don't include _MISSING_TYPE. Using callable() avoids the type comparison and works correctly since dataclasses.MISSING is not callable. https://claude.ai/code/session_0175FLYUJtjUuigZeBQnscSB
msgspec's updated typeshed stubs annotate json.encode() as returning bytes directly, making cast(bytes, ...) redundant. mypy --python-version 3.13 flags this as [redundant-cast]; removing the cast resolves the CI failure on Python 3.13. https://claude.ai/code/session_01WD4Xmw8KHWMU6bXFttoTpD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the missing features identified in the codebase audit, bringing FasterAPI to full FastAPI API parity.
New modules
security.py—OAuth2PasswordBearer,OAuth2PasswordRequestForm,SecurityScopes,HTTPBasic/HTTPBasicCredentials,APIKeyHeader,APIKeyQuery,APIKeyCookietemplating.py—Jinja2TemplateswithTemplateResponse()staticfiles.py—StaticFilesASGI app with path-traversal protectionUpdated modules
response.py—EventSourceResponse(SSE),ORJSONResponse/UJSONResponsealiases,datetime/UUID/Decimalserialization via customenc_hookdependencies.py—Annotated[T, Depends()]PEP 593 style,@dataclassbody support, callable-instance dependencies (for security schemes), class-based dependenciesapp.py—lifespan=async context manager,response_model/response_model_include/response_model_excludefield filtering,app.mount()for sub-apps,openapi_tags/terms_of_service/contact/license_infoconstructor params,responses={404:…}per-route,dependencies=oninclude_router()router.py—dependencies=[]onFasterRouterand all route decoratorsopenapi/generator.py— Enum path param schemas, multiple response declarations, all new metadata fields,datetime/UUID/Decimal/@dataclasstype schemastestclient.py— Lifespan startup/shutdown support via background thread__init__.py— Exports all new public classesTest plan