fastapi-app-builder 0.1.0b2__tar.gz → 0.1.0b3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/CHANGELOG.md +22 -3
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/PKG-INFO +8 -8
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/README.md +7 -7
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/pyproject.toml +1 -1
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/__init__.py +1 -1
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/builder.py +21 -7
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/container.py +5 -2
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/patch.py +3 -2
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/.gitignore +0 -0
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/LICENSE +0 -0
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/exceptions.py +0 -0
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/installers/__init__.py +0 -0
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/installers/cors.py +0 -0
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/installers/database.py +0 -0
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/lifetime.py +0 -0
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/middleware.py +0 -0
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/py.typed +0 -0
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/resolver.py +0 -0
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/router.py +0 -0
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/validation.py +0 -0
- {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/wrapper.py +0 -0
|
@@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.1.0b3] - 2026-11-29
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Defining a route crashed with recent FastAPI releases (seen with 0.165)
|
|
12
|
+
with `TypeError: analyze_param() missing 1 required keyword-only argument:
|
|
13
|
+
'is_path_param'`, because FastAPI changed an internal function this library
|
|
14
|
+
patches. The patch now passes FastAPI's arguments through, so it works with
|
|
15
|
+
older and newer FastAPI. 0.1.0b1 and 0.1.0b2 are affected: upgrade to this
|
|
16
|
+
release
|
|
17
|
+
- With recent FastAPI, startup validation skipped the endpoints of routers
|
|
18
|
+
added with `include_router()`, because FastAPI now keeps included routers
|
|
19
|
+
nested instead of copying their routes
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- The benchmark now defines every variant's endpoint on an `APIRouter`
|
|
23
|
+
included into the app, as real apps are organized. The README's numbers are
|
|
24
|
+
measured with FastAPI 0.165
|
|
25
|
+
|
|
8
26
|
## [0.1.0b2] - 2026-11-29
|
|
9
27
|
|
|
10
28
|
### Upgrading
|
|
@@ -49,9 +67,10 @@ Four behavior changes could affect existing apps:
|
|
|
49
67
|
wiring the same services through FastAPI's `Depends()`
|
|
50
68
|
|
|
51
69
|
### Changed
|
|
52
|
-
- Request handling is about 7x faster. In the included benchmark
|
|
53
|
-
using a layered service graph went from 541 µs to 75 µs,
|
|
54
|
-
about 2,700 to 12,100 requests per second. That is now
|
|
70
|
+
- Request handling is about 7x faster. In the included benchmark (FastAPI
|
|
71
|
+
0.128), a request using a layered service graph went from 541 µs to 75 µs,
|
|
72
|
+
and throughput from about 2,700 to 12,100 requests per second. That is now
|
|
73
|
+
faster than wiring the
|
|
55
74
|
same services with FastAPI's `Depends()` (see the README's Performance
|
|
56
75
|
section):
|
|
57
76
|
- Endpoint services are resolved directly by a thin wrapper, instead of
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: fastapi-app-builder
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.0b3
|
|
4
4
|
Summary: ASP.NET Core-style dependency injection for FastAPI
|
|
5
5
|
Project-URL: Homepage, https://github.com/Saurus119/fastapi-builder
|
|
6
6
|
Project-URL: Documentation, https://github.com/Saurus119/fastapi-builder#readme
|
|
@@ -372,19 +372,19 @@ Injecting services with fastapi-app-builder is faster than wiring the same servi
|
|
|
372
372
|
|
|
373
373
|
| Scenario | Hand-wired (no DI) | `Depends()`, `def` providers | `Depends()`, `async def` providers | fastapi-app-builder |
|
|
374
374
|
|---|---:|---:|---:|---:|
|
|
375
|
-
| Layered services |
|
|
376
|
-
| Layered + DB cleanup |
|
|
377
|
-
| One service, no dependencies |
|
|
375
|
+
| Layered services | 83 µs | 773 µs | 146 µs | **92 µs** |
|
|
376
|
+
| Layered + DB cleanup | 82 µs | 782 µs | 175 µs | **94 µs** |
|
|
377
|
+
| One service, no dependencies | 81 µs | 206 µs | 93 µs | **87 µs** |
|
|
378
378
|
|
|
379
|
-
Time per request; lower is better. In the layered scenario, the endpoint uses a service and an audit log, which share a repository, which uses a DB context; the service also uses a singleton cache. The cleanup variant closes the DB context after each request, with a `yield` dependency in FastAPI and a `dispose` function here. Requests are sent straight to the ASGI app, so the numbers are framework and DI overhead only, without network or server time. Measured with Python 3.13 and FastAPI 0.
|
|
379
|
+
Time per request; lower is better. In the layered scenario, the endpoint uses a service and an audit log, which share a repository, which uses a DB context; the service also uses a singleton cache. The cleanup variant closes the DB context after each request, with a `yield` dependency in FastAPI and a `dispose` function here. Every variant defines its endpoint on an `APIRouter` included into the app. Requests are sent straight to the ASGI app, so the numbers are framework and DI overhead only, without network or server time. Measured with Python 3.13 and FastAPI 0.165 on Windows 11. Run [`benchmarks/compare_depends.py`](benchmarks/compare_depends.py) to measure on your own machine; the `def` column varies most between runs.
|
|
380
380
|
|
|
381
381
|
Why it's faster:
|
|
382
382
|
|
|
383
|
-
- **No `Depends()` per service.** FastAPI solves every `Depends()` parameter with its dependency machinery, which costs
|
|
384
|
-
- **No threadpool hops.** FastAPI runs every plain `def` provider in its threadpool, so
|
|
383
|
+
- **No `Depends()` per service.** FastAPI solves every `Depends()` parameter with its dependency machinery, which costs several microseconds per parameter on every request. fastapi-app-builder hides service parameters from FastAPI and resolves all of them in one plain call before the endpoint runs, and services depend on each other through ordinary constructor calls.
|
|
384
|
+
- **No threadpool hops.** FastAPI runs every plain `def` provider in its threadpool, so each one costs a thread hop on every request. That's why the `def` column is so much slower, and it gets worse under concurrent load. Services are resolved in the same call as the endpoint.
|
|
385
385
|
- **Cleanup without generators.** A `yield` dependency needs its own context manager on every request; a `dispose` function is one call after the response.
|
|
386
386
|
|
|
387
|
-
With a single service and nothing behind it,
|
|
387
|
+
With a single service and nothing behind it, the difference is small. It grows with every service in the graph.
|
|
388
388
|
|
|
389
389
|
## API Reference
|
|
390
390
|
|
|
@@ -332,19 +332,19 @@ Injecting services with fastapi-app-builder is faster than wiring the same servi
|
|
|
332
332
|
|
|
333
333
|
| Scenario | Hand-wired (no DI) | `Depends()`, `def` providers | `Depends()`, `async def` providers | fastapi-app-builder |
|
|
334
334
|
|---|---:|---:|---:|---:|
|
|
335
|
-
| Layered services |
|
|
336
|
-
| Layered + DB cleanup |
|
|
337
|
-
| One service, no dependencies |
|
|
335
|
+
| Layered services | 83 µs | 773 µs | 146 µs | **92 µs** |
|
|
336
|
+
| Layered + DB cleanup | 82 µs | 782 µs | 175 µs | **94 µs** |
|
|
337
|
+
| One service, no dependencies | 81 µs | 206 µs | 93 µs | **87 µs** |
|
|
338
338
|
|
|
339
|
-
Time per request; lower is better. In the layered scenario, the endpoint uses a service and an audit log, which share a repository, which uses a DB context; the service also uses a singleton cache. The cleanup variant closes the DB context after each request, with a `yield` dependency in FastAPI and a `dispose` function here. Requests are sent straight to the ASGI app, so the numbers are framework and DI overhead only, without network or server time. Measured with Python 3.13 and FastAPI 0.
|
|
339
|
+
Time per request; lower is better. In the layered scenario, the endpoint uses a service and an audit log, which share a repository, which uses a DB context; the service also uses a singleton cache. The cleanup variant closes the DB context after each request, with a `yield` dependency in FastAPI and a `dispose` function here. Every variant defines its endpoint on an `APIRouter` included into the app. Requests are sent straight to the ASGI app, so the numbers are framework and DI overhead only, without network or server time. Measured with Python 3.13 and FastAPI 0.165 on Windows 11. Run [`benchmarks/compare_depends.py`](benchmarks/compare_depends.py) to measure on your own machine; the `def` column varies most between runs.
|
|
340
340
|
|
|
341
341
|
Why it's faster:
|
|
342
342
|
|
|
343
|
-
- **No `Depends()` per service.** FastAPI solves every `Depends()` parameter with its dependency machinery, which costs
|
|
344
|
-
- **No threadpool hops.** FastAPI runs every plain `def` provider in its threadpool, so
|
|
343
|
+
- **No `Depends()` per service.** FastAPI solves every `Depends()` parameter with its dependency machinery, which costs several microseconds per parameter on every request. fastapi-app-builder hides service parameters from FastAPI and resolves all of them in one plain call before the endpoint runs, and services depend on each other through ordinary constructor calls.
|
|
344
|
+
- **No threadpool hops.** FastAPI runs every plain `def` provider in its threadpool, so each one costs a thread hop on every request. That's why the `def` column is so much slower, and it gets worse under concurrent load. Services are resolved in the same call as the endpoint.
|
|
345
345
|
- **Cleanup without generators.** A `yield` dependency needs its own context manager on every request; a `dispose` function is one call after the response.
|
|
346
346
|
|
|
347
|
-
With a single service and nothing behind it,
|
|
347
|
+
With a single service and nothing behind it, the difference is small. It grows with every service in the graph.
|
|
348
348
|
|
|
349
349
|
## API Reference
|
|
350
350
|
|
{fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/builder.py
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from collections.abc import Callable
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
3
|
+
from collections.abc import Callable, Iterable, Iterator
|
|
4
|
+
from typing import TYPE_CHECKING, Any
|
|
5
5
|
|
|
6
6
|
from fastapi import APIRouter, FastAPI
|
|
7
7
|
|
|
@@ -351,10 +351,24 @@ class AppBuilder:
|
|
|
351
351
|
)
|
|
352
352
|
else:
|
|
353
353
|
# Validate standard APIRouter endpoints
|
|
354
|
-
for
|
|
355
|
-
|
|
356
|
-
errors.extend(
|
|
357
|
-
self._services.validate_endpoint(base_route.endpoint)
|
|
358
|
-
)
|
|
354
|
+
for endpoint in _iter_endpoints(controller.routes):
|
|
355
|
+
errors.extend(self._services.validate_endpoint(endpoint))
|
|
359
356
|
|
|
360
357
|
return errors
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def _iter_endpoints(routes: Iterable[Any]) -> Iterator[Callable[..., Any]]:
|
|
361
|
+
"""Yield the endpoint of every route, including routes of nested routers.
|
|
362
|
+
|
|
363
|
+
Older FastAPI copies an included router's routes into the parent. Newer
|
|
364
|
+
FastAPI keeps the included router as one route pointing at it
|
|
365
|
+
(``original_router``), so its routes are only reachable through that.
|
|
366
|
+
"""
|
|
367
|
+
for route in routes:
|
|
368
|
+
endpoint = getattr(route, "endpoint", None)
|
|
369
|
+
if endpoint is not None:
|
|
370
|
+
yield endpoint
|
|
371
|
+
continue
|
|
372
|
+
nested = getattr(route, "original_router", None)
|
|
373
|
+
if nested is not None:
|
|
374
|
+
yield from _iter_endpoints(nested.routes)
|
{fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/container.py
RENAMED
|
@@ -33,6 +33,10 @@ _CtorParam = tuple[str, Any, bool]
|
|
|
33
33
|
|
|
34
34
|
_VAR_KINDS = (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD)
|
|
35
35
|
|
|
36
|
+
# typing.Protocol itself, typed loosely so comparing a class to it type-checks
|
|
37
|
+
# the same way under every mypy version
|
|
38
|
+
_PROTOCOL: Any = Protocol
|
|
39
|
+
|
|
36
40
|
# Set on endpoints wrapped for injection (see wrapper.py), pointing at the
|
|
37
41
|
# original function. Validation inspects the original, whose signature still
|
|
38
42
|
# lists the service parameters the wrapper hides from FastAPI.
|
|
@@ -62,8 +66,7 @@ def is_potential_service_type(annotation: Any) -> TypeGuard[type]:
|
|
|
62
66
|
|
|
63
67
|
# Protocol classes, or classes that explicitly implement one
|
|
64
68
|
for base in annotation.__mro__:
|
|
65
|
-
|
|
66
|
-
if is_protocol and base is not Protocol: # type: ignore[comparison-overlap]
|
|
69
|
+
if getattr(base, "_is_protocol", False) and base is not _PROTOCOL:
|
|
67
70
|
return True
|
|
68
71
|
|
|
69
72
|
if isinstance(annotation, ABCMeta) or ABC in annotation.__mro__:
|
{fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/patch.py
RENAMED
|
@@ -131,13 +131,15 @@ def _apply_patch() -> None:
|
|
|
131
131
|
original_add_api_route = APIRouter.add_api_route
|
|
132
132
|
original_add_api_websocket_route = APIRouter.add_api_websocket_route
|
|
133
133
|
|
|
134
|
+
# Takes only the arguments it changes and passes the rest through:
|
|
135
|
+
# FastAPI renames the others between releases (e.g. is_path_param
|
|
136
|
+
# became path_param_names).
|
|
134
137
|
@functools.wraps(original_analyze_param)
|
|
135
138
|
def patched_analyze_param(
|
|
136
139
|
*,
|
|
137
140
|
param_name: str,
|
|
138
141
|
annotation: Any,
|
|
139
142
|
value: Any,
|
|
140
|
-
is_path_param: bool,
|
|
141
143
|
**kwargs: Any,
|
|
142
144
|
) -> Any:
|
|
143
145
|
# Check if no default is set (inspect._empty, PydanticUndefined, or None)
|
|
@@ -162,7 +164,6 @@ def _apply_patch() -> None:
|
|
|
162
164
|
param_name=param_name,
|
|
163
165
|
annotation=annotation,
|
|
164
166
|
value=value,
|
|
165
|
-
is_path_param=is_path_param,
|
|
166
167
|
**kwargs,
|
|
167
168
|
)
|
|
168
169
|
|
|
File without changes
|
|
File without changes
|
{fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/exceptions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/lifetime.py
RENAMED
|
File without changes
|
{fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/middleware.py
RENAMED
|
File without changes
|
{fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/py.typed
RENAMED
|
File without changes
|
{fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/resolver.py
RENAMED
|
File without changes
|
{fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/router.py
RENAMED
|
File without changes
|
{fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/validation.py
RENAMED
|
File without changes
|
{fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/wrapper.py
RENAMED
|
File without changes
|