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.
Files changed (21) hide show
  1. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/CHANGELOG.md +22 -3
  2. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/PKG-INFO +8 -8
  3. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/README.md +7 -7
  4. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/pyproject.toml +1 -1
  5. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/__init__.py +1 -1
  6. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/builder.py +21 -7
  7. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/container.py +5 -2
  8. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/patch.py +3 -2
  9. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/.gitignore +0 -0
  10. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/LICENSE +0 -0
  11. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/exceptions.py +0 -0
  12. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/installers/__init__.py +0 -0
  13. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/installers/cors.py +0 -0
  14. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/installers/database.py +0 -0
  15. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/lifetime.py +0 -0
  16. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/middleware.py +0 -0
  17. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/py.typed +0 -0
  18. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/resolver.py +0 -0
  19. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/router.py +0 -0
  20. {fastapi_app_builder-0.1.0b2 → fastapi_app_builder-0.1.0b3}/src/fastapi_app_builder/validation.py +0 -0
  21. {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, a request
53
- using a layered service graph went from 541 µs to 75 µs, and throughput from
54
- about 2,700 to 12,100 requests per second. That is now faster than wiring the
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.0b2
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 | 66 µs | 829 µs | 96 µs | **75 µs** |
376
- | Layered + DB cleanup | 65 µs | 924 µs | 109 µs | **78 µs** |
377
- | One service, no dependencies | 63 µs | 212 µs | 69 µs | **68 µs** |
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.128 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.
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 roughly 5–6 µs per parameter per 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 the style FastAPI's docs use pays a thread hop per provider 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.
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, plain `async def` `Depends()` and fastapi-app-builder cost about the same. The gap grows with every service in the graph.
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 | 66 µs | 829 µs | 96 µs | **75 µs** |
336
- | Layered + DB cleanup | 65 µs | 924 µs | 109 µs | **78 µs** |
337
- | One service, no dependencies | 63 µs | 212 µs | 69 µs | **68 µs** |
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.128 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.
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 roughly 5–6 µs per parameter per 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 the style FastAPI's docs use pays a thread hop per provider 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.
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, plain `async def` `Depends()` and fastapi-app-builder cost about the same. The gap grows with every service in the graph.
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
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fastapi-app-builder"
3
- version = "0.1.0b2"
3
+ version = "0.1.0b3"
4
4
  description = "ASP.NET Core-style dependency injection for FastAPI"
5
5
  readme = "README.md"
6
6
  license = { text = "MIT" }
@@ -62,4 +62,4 @@ __all__ = [
62
62
  "ValidationError",
63
63
  ]
64
64
 
65
- __version__ = "0.1.0b2"
65
+ __version__ = "0.1.0b3"
@@ -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 base_route in controller.routes:
355
- if hasattr(base_route, "endpoint"):
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)
@@ -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
- is_protocol = getattr(base, "_is_protocol", False)
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__:
@@ -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