rn-forge-fastapi 0.4.0__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.
- rn_forge_fastapi-0.4.0/LICENSE +21 -0
- rn_forge_fastapi-0.4.0/PKG-INFO +165 -0
- rn_forge_fastapi-0.4.0/README.md +127 -0
- rn_forge_fastapi-0.4.0/pyproject.toml +108 -0
- rn_forge_fastapi-0.4.0/pyproject.toml.orig +113 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/__init__.py +111 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/app.py +210 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/auth/__init__.py +69 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/auth/authorization.py +62 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/auth/csrf.py +243 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/auth/dependencies.py +374 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/auth/proxies.py +55 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/auth/rate_limit.py +91 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/auth/redis.py +88 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/auth/routes.py +725 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/auth/sessions.py +504 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/cors.py +80 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/dependencies.py +157 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/deprecation.py +45 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/health.py +71 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/idempotency.py +82 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/merge_patch.py +89 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/openapi.py +91 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/problem.py +155 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/py.typed +0 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/read_mask.py +86 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/soft_delete.py +188 -0
- rn_forge_fastapi-0.4.0/src/rn_forge/fastapi/transfer.py +936 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rohit Narayanan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rn-forge-fastapi
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: FastAPI adapters over rn-forge-web
|
|
5
|
+
Author: Rohit Narayanan
|
|
6
|
+
Author-email: Rohit Narayanan <rohit.nn@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Framework :: FastAPI
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Dist: rn-forge-auth>=0.1.0,<0.2
|
|
18
|
+
Requires-Dist: rn-forge-web[security]>=0.3.0,<0.4
|
|
19
|
+
Requires-Dist: fastapi>=0.141.1
|
|
20
|
+
Requires-Dist: opentelemetry-instrumentation-fastapi>=0.65b0
|
|
21
|
+
Requires-Dist: rn-forge-auth[oidc]>=0.1.0,<0.2 ; extra == 'oidc'
|
|
22
|
+
Requires-Dist: rn-forge-auth[redis]>=0.1.0,<0.2 ; extra == 'redis'
|
|
23
|
+
Requires-Dist: assertpy>=1.1 ; extra == 'testing'
|
|
24
|
+
Requires-Dist: httpx>=0.28.1 ; extra == 'testing'
|
|
25
|
+
Requires-Dist: pytest>=9.1.1 ; extra == 'testing'
|
|
26
|
+
Requires-Dist: rn-forge-data>=0.1.1,<0.2 ; extra == 'transfer'
|
|
27
|
+
Requires-Dist: python-multipart>=0.0.20 ; extra == 'transfer'
|
|
28
|
+
Requires-Python: >=3.14
|
|
29
|
+
Project-URL: Documentation, https://rn-forge.github.io/pykit/packages/rn-forge-fastapi/latest/
|
|
30
|
+
Project-URL: Source, https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-fastapi
|
|
31
|
+
Project-URL: Changelog, https://github.com/rn-forge/pykit/blob/main/packages/rn-forge-fastapi/CHANGELOG.md
|
|
32
|
+
Project-URL: Issues, https://github.com/rn-forge/pykit/issues
|
|
33
|
+
Provides-Extra: oidc
|
|
34
|
+
Provides-Extra: redis
|
|
35
|
+
Provides-Extra: testing
|
|
36
|
+
Provides-Extra: transfer
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
|
|
39
|
+
# rn-forge-fastapi
|
|
40
|
+
|
|
41
|
+
[Documentation](https://rn-forge.github.io/pykit/packages/rn-forge-fastapi/latest/)
|
|
42
|
+
·
|
|
43
|
+
[Changelog](https://github.com/rn-forge/pykit/blob/main/packages/rn-forge-fastapi/CHANGELOG.md)
|
|
44
|
+
·
|
|
45
|
+
[Source](https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-fastapi)
|
|
46
|
+
· [All pykit packages](https://rn-forge.github.io/pykit/)
|
|
47
|
+
|
|
48
|
+
FastAPI adapters over `rn-forge-web`.
|
|
49
|
+
|
|
50
|
+
`rn-forge-web` settles the wire — the problem body, the cursor codec, the ETag
|
|
51
|
+
semantics, the idempotency reuse rule, the readiness aggregate, the 401/403
|
|
52
|
+
boundary. This package is the FastAPI-shaped plumbing that puts those decisions
|
|
53
|
+
into an application: exception-handler registration, `Depends` factories, a
|
|
54
|
+
router factory and an OpenAPI repair. **It makes no wire decision of its own.**
|
|
55
|
+
|
|
56
|
+
| Module | What it adapts |
|
|
57
|
+
| -- | -- |
|
|
58
|
+
| `problem` | `register_problem_handlers(app)` — every error the app produces, including FastAPI's own 404/405/422, as `application/problem+json` |
|
|
59
|
+
| `openapi` | `FastApiApp.openapi()` repairs the cached document — adds `ProblemDetail` and the problem responses it can actually produce, accuracy only; `operation_id` — the shared `operationId` convention |
|
|
60
|
+
| `dependencies` | `page_params`, `require_idempotency_key`, `require_if_match` |
|
|
61
|
+
| `health` | `health_router(checks=...)` — `/healthz` and `/readyz` |
|
|
62
|
+
| `auth` | `auth_router` and `SessionMiddleware` — the `/auth` routes, login sessions and CSRF protection over `rn-forge-auth`; `bearer_auth`, `basic_auth`, `current_principal`, `requires`, `requires_permission`, `PolicyGuard` — `Security` dependencies; rate limiting; `auth.redis` — the Redis CSRF store and rate limiter (`redis` extra) |
|
|
63
|
+
| `app` | `FastApiApp(config)` — a `FastAPI` subclass with the standard adapters installed |
|
|
64
|
+
|
|
65
|
+
## Where it sits
|
|
66
|
+
|
|
67
|
+
```text
|
|
68
|
+
commons ──► web ──► auth ──► django
|
|
69
|
+
└───► fastapi (this package)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`rn-forge-fastapi` depends on `rn-forge-web`, `rn-forge-auth` and FastAPI. It
|
|
73
|
+
never imports `rn_forge.django` — the two framework packages are independent
|
|
74
|
+
siblings — nor `rn_forge.cli` or `rn_forge.tooling`. `.importlinter` carries the
|
|
75
|
+
`fastapi-runtime-has-no-tooling` and `web-layers` contracts, and
|
|
76
|
+
`uv run lint-imports` proves them.
|
|
77
|
+
|
|
78
|
+
## The import path
|
|
79
|
+
|
|
80
|
+
This package is `rn_forge.fastapi`; the framework is `fastapi`. The two do not
|
|
81
|
+
collide: `from fastapi import APIRouter` always resolves to the framework,
|
|
82
|
+
unless a process puts `src/rn_forge/` itself on `sys.path`.
|
|
83
|
+
|
|
84
|
+
## Installation
|
|
85
|
+
|
|
86
|
+
Require the packages by version range:
|
|
87
|
+
|
|
88
|
+
```toml
|
|
89
|
+
dependencies = [
|
|
90
|
+
"rn-forge-fastapi>=0.4,<0.5",
|
|
91
|
+
"rn-forge-web>=0.3,<0.4",
|
|
92
|
+
]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Application code imports `rn_forge.web` directly (wire models, pagination,
|
|
96
|
+
problem types, the auth contract), and this package does not re-export it.
|
|
97
|
+
Declare `rn-forge-web` as well, so the import is not an undeclared transitive
|
|
98
|
+
dependency.
|
|
99
|
+
|
|
100
|
+
Inside this workspace, `[tool.uv.sources]` overrides the requirement with the
|
|
101
|
+
local checkout, for local development only.
|
|
102
|
+
|
|
103
|
+
## What this package deliberately does not ship
|
|
104
|
+
|
|
105
|
+
- **Settings, infrastructure, or application policy.** `FastApiApp` wires the
|
|
106
|
+
standard adapters from an explicit `AppConfig`; applications still construct
|
|
107
|
+
their settings, clients, authenticators, stores and product routes.
|
|
108
|
+
- **A dependency-injection container, a settings facade, any store.** FastAPI's
|
|
109
|
+
`Depends` is the DI framework; configuration arrives as function arguments;
|
|
110
|
+
an `AsyncIdempotencyStore` is SQL- or Redis-backed and belongs to the
|
|
111
|
+
application.
|
|
112
|
+
- **A tracing middleware.** Tracing is W3C Trace Context through OpenTelemetry's
|
|
113
|
+
own `FastAPIInstrumentor`, not a house middleware — `FastApiApp` calls it by
|
|
114
|
+
default (`AppConfig.tracing`). The current trace id reaches a 500 the same
|
|
115
|
+
way it reaches any other response: `render_problem` reads it from the active
|
|
116
|
+
span, and `ServerErrorMiddleware` sits inside the instrumentation's span,
|
|
117
|
+
not outside it.
|
|
118
|
+
- **A token verifier.** The auth binding takes any
|
|
119
|
+
`rn_forge.auth.Authenticator`; verifying a JWT against a JWKS is that
|
|
120
|
+
authenticator's job. For OIDC that authenticator already exists —
|
|
121
|
+
`rn_forge.auth.oidc.OidcAuthenticator`, via this package's `oidc` extra —
|
|
122
|
+
and is shared with `rn-forge-django` so both stacks accept the same tokens.
|
|
123
|
+
Nothing here wraps it; pass it to `bearer_auth`.
|
|
124
|
+
|
|
125
|
+
## Dependencies
|
|
126
|
+
|
|
127
|
+
**`rn-forge-web`** — every module adapts one of its primitives.
|
|
128
|
+
`rn-forge-commons` is not declared: nothing here imports it directly, and it
|
|
129
|
+
arrives through `rn-forge-web`.
|
|
130
|
+
|
|
131
|
+
**`rn-forge-auth`** — a base dependency: the `auth` package is built on its
|
|
132
|
+
login flows, `Principal`, `Requirement` and authenticator contracts. Its OIDC
|
|
133
|
+
adapter comes with this package's `oidc` extra, and its Redis stores with the
|
|
134
|
+
`redis` extra, which also installs the client for `auth.redis`.
|
|
135
|
+
|
|
136
|
+
**`fastapi`** (`>=0.141.1`) — a hard dependency, not an extra. It is used as
|
|
137
|
+
documented, not abstracted away — an application keeps `APIRouter`, `Depends`,
|
|
138
|
+
`Header` and `response_model` exactly as FastAPI defines them. `pydantic` (2.13
|
|
139
|
+
resolved) and `starlette` arrive with it; the `rn_forge.web.WireModel`
|
|
140
|
+
configuration uses `validate_by_name`/`serialize_by_alias`, which need pydantic
|
|
141
|
+
≥ 2.11.
|
|
142
|
+
|
|
143
|
+
**Not wrapped:** FastAPI's `HTTPBearer`/`HTTPBasic` are used with
|
|
144
|
+
`auto_error=False` — kept for the `securitySchemes` entry they put in the
|
|
145
|
+
schema, stripped of their own 401 body and non-RFC-6750 challenge.
|
|
146
|
+
|
|
147
|
+
## OpenAPI across stacks
|
|
148
|
+
|
|
149
|
+
Wire behaviour and `operationId` are identical to the Django stack; the rest of
|
|
150
|
+
the document text is not. `Page[T]` keeps pydantic's own name, `Page_UserOut_`.
|
|
151
|
+
|
|
152
|
+
An operation outside the six CRUD verbs is a custom method, spelled
|
|
153
|
+
`POST /orders/{orderId}:cancel` and named `ordersCancel` (see `rn-forge-web`'s
|
|
154
|
+
`api-conventions.md` §9). Spelled as a plain path segment it still gets a
|
|
155
|
+
mechanical name and wants an explicit `operation_id=`.
|
|
156
|
+
|
|
157
|
+
`operationId` must be unique across the document. drf-spectacular warns and
|
|
158
|
+
appends a numeral on a collision; FastAPI does neither, so two routes ending in
|
|
159
|
+
the same literal segment collide silently here.
|
|
160
|
+
|
|
161
|
+
## Documentation
|
|
162
|
+
|
|
163
|
+
`uv run --directory packages/rn-forge-fastapi --group docs mkdocs build --strict`,
|
|
164
|
+
or the combined site from the repo root. The wiring guide is the page an
|
|
165
|
+
application is written from.
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# rn-forge-fastapi
|
|
2
|
+
|
|
3
|
+
[Documentation](https://rn-forge.github.io/pykit/packages/rn-forge-fastapi/latest/)
|
|
4
|
+
·
|
|
5
|
+
[Changelog](https://github.com/rn-forge/pykit/blob/main/packages/rn-forge-fastapi/CHANGELOG.md)
|
|
6
|
+
·
|
|
7
|
+
[Source](https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-fastapi)
|
|
8
|
+
· [All pykit packages](https://rn-forge.github.io/pykit/)
|
|
9
|
+
|
|
10
|
+
FastAPI adapters over `rn-forge-web`.
|
|
11
|
+
|
|
12
|
+
`rn-forge-web` settles the wire — the problem body, the cursor codec, the ETag
|
|
13
|
+
semantics, the idempotency reuse rule, the readiness aggregate, the 401/403
|
|
14
|
+
boundary. This package is the FastAPI-shaped plumbing that puts those decisions
|
|
15
|
+
into an application: exception-handler registration, `Depends` factories, a
|
|
16
|
+
router factory and an OpenAPI repair. **It makes no wire decision of its own.**
|
|
17
|
+
|
|
18
|
+
| Module | What it adapts |
|
|
19
|
+
| -- | -- |
|
|
20
|
+
| `problem` | `register_problem_handlers(app)` — every error the app produces, including FastAPI's own 404/405/422, as `application/problem+json` |
|
|
21
|
+
| `openapi` | `FastApiApp.openapi()` repairs the cached document — adds `ProblemDetail` and the problem responses it can actually produce, accuracy only; `operation_id` — the shared `operationId` convention |
|
|
22
|
+
| `dependencies` | `page_params`, `require_idempotency_key`, `require_if_match` |
|
|
23
|
+
| `health` | `health_router(checks=...)` — `/healthz` and `/readyz` |
|
|
24
|
+
| `auth` | `auth_router` and `SessionMiddleware` — the `/auth` routes, login sessions and CSRF protection over `rn-forge-auth`; `bearer_auth`, `basic_auth`, `current_principal`, `requires`, `requires_permission`, `PolicyGuard` — `Security` dependencies; rate limiting; `auth.redis` — the Redis CSRF store and rate limiter (`redis` extra) |
|
|
25
|
+
| `app` | `FastApiApp(config)` — a `FastAPI` subclass with the standard adapters installed |
|
|
26
|
+
|
|
27
|
+
## Where it sits
|
|
28
|
+
|
|
29
|
+
```text
|
|
30
|
+
commons ──► web ──► auth ──► django
|
|
31
|
+
└───► fastapi (this package)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`rn-forge-fastapi` depends on `rn-forge-web`, `rn-forge-auth` and FastAPI. It
|
|
35
|
+
never imports `rn_forge.django` — the two framework packages are independent
|
|
36
|
+
siblings — nor `rn_forge.cli` or `rn_forge.tooling`. `.importlinter` carries the
|
|
37
|
+
`fastapi-runtime-has-no-tooling` and `web-layers` contracts, and
|
|
38
|
+
`uv run lint-imports` proves them.
|
|
39
|
+
|
|
40
|
+
## The import path
|
|
41
|
+
|
|
42
|
+
This package is `rn_forge.fastapi`; the framework is `fastapi`. The two do not
|
|
43
|
+
collide: `from fastapi import APIRouter` always resolves to the framework,
|
|
44
|
+
unless a process puts `src/rn_forge/` itself on `sys.path`.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
Require the packages by version range:
|
|
49
|
+
|
|
50
|
+
```toml
|
|
51
|
+
dependencies = [
|
|
52
|
+
"rn-forge-fastapi>=0.4,<0.5",
|
|
53
|
+
"rn-forge-web>=0.3,<0.4",
|
|
54
|
+
]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Application code imports `rn_forge.web` directly (wire models, pagination,
|
|
58
|
+
problem types, the auth contract), and this package does not re-export it.
|
|
59
|
+
Declare `rn-forge-web` as well, so the import is not an undeclared transitive
|
|
60
|
+
dependency.
|
|
61
|
+
|
|
62
|
+
Inside this workspace, `[tool.uv.sources]` overrides the requirement with the
|
|
63
|
+
local checkout, for local development only.
|
|
64
|
+
|
|
65
|
+
## What this package deliberately does not ship
|
|
66
|
+
|
|
67
|
+
- **Settings, infrastructure, or application policy.** `FastApiApp` wires the
|
|
68
|
+
standard adapters from an explicit `AppConfig`; applications still construct
|
|
69
|
+
their settings, clients, authenticators, stores and product routes.
|
|
70
|
+
- **A dependency-injection container, a settings facade, any store.** FastAPI's
|
|
71
|
+
`Depends` is the DI framework; configuration arrives as function arguments;
|
|
72
|
+
an `AsyncIdempotencyStore` is SQL- or Redis-backed and belongs to the
|
|
73
|
+
application.
|
|
74
|
+
- **A tracing middleware.** Tracing is W3C Trace Context through OpenTelemetry's
|
|
75
|
+
own `FastAPIInstrumentor`, not a house middleware — `FastApiApp` calls it by
|
|
76
|
+
default (`AppConfig.tracing`). The current trace id reaches a 500 the same
|
|
77
|
+
way it reaches any other response: `render_problem` reads it from the active
|
|
78
|
+
span, and `ServerErrorMiddleware` sits inside the instrumentation's span,
|
|
79
|
+
not outside it.
|
|
80
|
+
- **A token verifier.** The auth binding takes any
|
|
81
|
+
`rn_forge.auth.Authenticator`; verifying a JWT against a JWKS is that
|
|
82
|
+
authenticator's job. For OIDC that authenticator already exists —
|
|
83
|
+
`rn_forge.auth.oidc.OidcAuthenticator`, via this package's `oidc` extra —
|
|
84
|
+
and is shared with `rn-forge-django` so both stacks accept the same tokens.
|
|
85
|
+
Nothing here wraps it; pass it to `bearer_auth`.
|
|
86
|
+
|
|
87
|
+
## Dependencies
|
|
88
|
+
|
|
89
|
+
**`rn-forge-web`** — every module adapts one of its primitives.
|
|
90
|
+
`rn-forge-commons` is not declared: nothing here imports it directly, and it
|
|
91
|
+
arrives through `rn-forge-web`.
|
|
92
|
+
|
|
93
|
+
**`rn-forge-auth`** — a base dependency: the `auth` package is built on its
|
|
94
|
+
login flows, `Principal`, `Requirement` and authenticator contracts. Its OIDC
|
|
95
|
+
adapter comes with this package's `oidc` extra, and its Redis stores with the
|
|
96
|
+
`redis` extra, which also installs the client for `auth.redis`.
|
|
97
|
+
|
|
98
|
+
**`fastapi`** (`>=0.141.1`) — a hard dependency, not an extra. It is used as
|
|
99
|
+
documented, not abstracted away — an application keeps `APIRouter`, `Depends`,
|
|
100
|
+
`Header` and `response_model` exactly as FastAPI defines them. `pydantic` (2.13
|
|
101
|
+
resolved) and `starlette` arrive with it; the `rn_forge.web.WireModel`
|
|
102
|
+
configuration uses `validate_by_name`/`serialize_by_alias`, which need pydantic
|
|
103
|
+
≥ 2.11.
|
|
104
|
+
|
|
105
|
+
**Not wrapped:** FastAPI's `HTTPBearer`/`HTTPBasic` are used with
|
|
106
|
+
`auto_error=False` — kept for the `securitySchemes` entry they put in the
|
|
107
|
+
schema, stripped of their own 401 body and non-RFC-6750 challenge.
|
|
108
|
+
|
|
109
|
+
## OpenAPI across stacks
|
|
110
|
+
|
|
111
|
+
Wire behaviour and `operationId` are identical to the Django stack; the rest of
|
|
112
|
+
the document text is not. `Page[T]` keeps pydantic's own name, `Page_UserOut_`.
|
|
113
|
+
|
|
114
|
+
An operation outside the six CRUD verbs is a custom method, spelled
|
|
115
|
+
`POST /orders/{orderId}:cancel` and named `ordersCancel` (see `rn-forge-web`'s
|
|
116
|
+
`api-conventions.md` §9). Spelled as a plain path segment it still gets a
|
|
117
|
+
mechanical name and wants an explicit `operation_id=`.
|
|
118
|
+
|
|
119
|
+
`operationId` must be unique across the document. drf-spectacular warns and
|
|
120
|
+
appends a numeral on a collision; FastAPI does neither, so two routes ending in
|
|
121
|
+
the same literal segment collide silently here.
|
|
122
|
+
|
|
123
|
+
## Documentation
|
|
124
|
+
|
|
125
|
+
`uv run --directory packages/rn-forge-fastapi --group docs mkdocs build --strict`,
|
|
126
|
+
or the combined site from the repo root. The wiring guide is the page an
|
|
127
|
+
application is written from.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "rn-forge-fastapi"
|
|
3
|
+
version = "0.4.0"
|
|
4
|
+
description = "FastAPI adapters over rn-forge-web"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
classifiers = [
|
|
9
|
+
"Development Status :: 3 - Alpha",
|
|
10
|
+
"Intended Audience :: Developers",
|
|
11
|
+
"Framework :: FastAPI",
|
|
12
|
+
"Operating System :: OS Independent",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
15
|
+
"Programming Language :: Python :: 3.14",
|
|
16
|
+
"Typing :: Typed",
|
|
17
|
+
]
|
|
18
|
+
requires-python = ">=3.14"
|
|
19
|
+
dependencies = [
|
|
20
|
+
"rn-forge-auth>=0.1.0,<0.2",
|
|
21
|
+
"rn-forge-web[security]>=0.3.0,<0.4",
|
|
22
|
+
"fastapi>=0.141.1",
|
|
23
|
+
"opentelemetry-instrumentation-fastapi>=0.65b0",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[[project.authors]]
|
|
27
|
+
name = "Rohit Narayanan"
|
|
28
|
+
email = "rohit.nn@gmail.com"
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
testing = [
|
|
32
|
+
"assertpy>=1.1",
|
|
33
|
+
"httpx>=0.28.1",
|
|
34
|
+
"pytest>=9.1.1",
|
|
35
|
+
]
|
|
36
|
+
oidc = ["rn-forge-auth[oidc]>=0.1.0,<0.2"]
|
|
37
|
+
redis = ["rn-forge-auth[redis]>=0.1.0,<0.2"]
|
|
38
|
+
transfer = [
|
|
39
|
+
"rn-forge-data>=0.1.1,<0.2",
|
|
40
|
+
"python-multipart>=0.0.20",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[project.urls]
|
|
44
|
+
Documentation = "https://rn-forge.github.io/pykit/packages/rn-forge-fastapi/latest/"
|
|
45
|
+
Source = "https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-fastapi"
|
|
46
|
+
Changelog = "https://github.com/rn-forge/pykit/blob/main/packages/rn-forge-fastapi/CHANGELOG.md"
|
|
47
|
+
Issues = "https://github.com/rn-forge/pykit/issues"
|
|
48
|
+
|
|
49
|
+
[build-system]
|
|
50
|
+
requires = ["uv_build>=0.11.28,<0.12.0"]
|
|
51
|
+
build-backend = "uv_build"
|
|
52
|
+
|
|
53
|
+
[tool.uv.build-backend]
|
|
54
|
+
module-name = "rn_forge.fastapi"
|
|
55
|
+
|
|
56
|
+
[tool.uv.sources.rn-forge-auth]
|
|
57
|
+
workspace = true
|
|
58
|
+
|
|
59
|
+
[tool.uv.sources.rn-forge-commons]
|
|
60
|
+
workspace = true
|
|
61
|
+
|
|
62
|
+
[tool.uv.sources.rn-forge-data]
|
|
63
|
+
workspace = true
|
|
64
|
+
|
|
65
|
+
[tool.uv.sources.rn-forge-web]
|
|
66
|
+
workspace = true
|
|
67
|
+
|
|
68
|
+
[tool.uv.sources.rn-forge-fastapi]
|
|
69
|
+
workspace = true
|
|
70
|
+
|
|
71
|
+
[tool.workspace-ci.smoke]
|
|
72
|
+
modules = ["rn_forge.fastapi"]
|
|
73
|
+
|
|
74
|
+
[tool.workspace-ci.smoke.extras]
|
|
75
|
+
oidc = ["rn_forge.auth.oidc"]
|
|
76
|
+
redis = [
|
|
77
|
+
"rn_forge.auth.redis",
|
|
78
|
+
"rn_forge.fastapi.auth.redis",
|
|
79
|
+
]
|
|
80
|
+
transfer = ["rn_forge.fastapi.transfer"]
|
|
81
|
+
|
|
82
|
+
[tool.pytest.ini_options]
|
|
83
|
+
addopts = "-ra --import-mode=importlib -m 'not scaffold'"
|
|
84
|
+
markers = [
|
|
85
|
+
"unit: fast isolated tests",
|
|
86
|
+
"scaffold: installs built wheels into a scaffolded application (slow)",
|
|
87
|
+
"security_control: demonstrates the security control with the given rn_forge.auth.conformance case ID",
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
[dependency-groups]
|
|
91
|
+
dev = [
|
|
92
|
+
"assertpy>=1.1",
|
|
93
|
+
"httpx>=0.28.1",
|
|
94
|
+
"opentelemetry-sdk>=1.44",
|
|
95
|
+
"pyright>=1.1.411",
|
|
96
|
+
"pytest>=9.1.1",
|
|
97
|
+
"pytest-cov>=7.1.0",
|
|
98
|
+
"pytest-randomly>=4.1.0",
|
|
99
|
+
"rn-forge-fastapi[oidc,redis,transfer]",
|
|
100
|
+
"ruff>=0.15.21",
|
|
101
|
+
"sqlalchemy>=2.0",
|
|
102
|
+
]
|
|
103
|
+
docs = [
|
|
104
|
+
"mkdocs>=1.6.1",
|
|
105
|
+
"mkdocs-material>=9.7.6",
|
|
106
|
+
"mkdocstrings[python]>=1.0.6",
|
|
107
|
+
"rn-forge-fastapi",
|
|
108
|
+
]
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "rn-forge-fastapi"
|
|
3
|
+
version = "0.4.0"
|
|
4
|
+
description = "FastAPI adapters over rn-forge-web"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [{ name = "Rohit Narayanan", email = "rohit.nn@gmail.com" }]
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 3 - Alpha",
|
|
11
|
+
"Intended Audience :: Developers",
|
|
12
|
+
"Framework :: FastAPI",
|
|
13
|
+
"Operating System :: OS Independent",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
16
|
+
"Programming Language :: Python :: 3.14",
|
|
17
|
+
"Typing :: Typed",
|
|
18
|
+
]
|
|
19
|
+
requires-python = ">=3.14"
|
|
20
|
+
# Internal requirements are version ranges (ADR-0004).
|
|
21
|
+
#
|
|
22
|
+
# `rn-forge-commons` is not declared: nothing here imports it directly, and it
|
|
23
|
+
# arrives through `rn-forge-web`.
|
|
24
|
+
dependencies = [
|
|
25
|
+
"rn-forge-auth>=0.1.0,<0.2",
|
|
26
|
+
# `[security]` is a hard requirement, not an extra: `FastApiApp` installs
|
|
27
|
+
# `SecurityHeadersMiddleware` by default (`AppConfig.security_headers`).
|
|
28
|
+
"rn-forge-web[security]>=0.3.0,<0.4",
|
|
29
|
+
# A hard dependency, not an extra: every module in this package is a FastAPI
|
|
30
|
+
# adapter. The floor is what resolved on 2026-09-12. pydantic arrives with it.
|
|
31
|
+
"fastapi>=0.141.1",
|
|
32
|
+
# `FastApiApp` instruments itself by default (`AppConfig.tracing`). Brings
|
|
33
|
+
# `opentelemetry-instrumentation`, which holds `TraceResponsePropagator`.
|
|
34
|
+
"opentelemetry-instrumentation-fastapi>=0.65b0",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.optional-dependencies]
|
|
38
|
+
# httpx is what FastAPI's TestClient drives requests through.
|
|
39
|
+
testing = ["assertpy>=1.1", "httpx>=0.28.1", "pytest>=9.1.1"]
|
|
40
|
+
# JWKS bearer auth: `rn_forge.auth.oidc.OidcAuthenticator` passed to
|
|
41
|
+
# `bearer_auth()`. Nothing in this package imports it; the extra exists so a
|
|
42
|
+
# consumer asks for it by name rather than reaching into auth's extras.
|
|
43
|
+
oidc = [
|
|
44
|
+
"rn-forge-auth[oidc]>=0.1.0,<0.2",
|
|
45
|
+
]
|
|
46
|
+
# Redis-backed login sessions and transactions for `rn_forge.fastapi.auth`:
|
|
47
|
+
# `rn_forge.auth.redis`, and the CSRF token store `rn_forge.fastapi.auth.redis`.
|
|
48
|
+
redis = [
|
|
49
|
+
"rn-forge-auth[redis]>=0.1.0,<0.2",
|
|
50
|
+
]
|
|
51
|
+
# Tabular export and import: `rn_forge.fastapi.transfer`. Not imported by the
|
|
52
|
+
# package facade. `python-multipart` is what FastAPI's `UploadFile` needs.
|
|
53
|
+
transfer = [
|
|
54
|
+
"rn-forge-data>=0.1.1,<0.2",
|
|
55
|
+
"python-multipart>=0.0.20",
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
[project.urls]
|
|
59
|
+
Documentation = "https://rn-forge.github.io/pykit/packages/rn-forge-fastapi/latest/"
|
|
60
|
+
Source = "https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-fastapi"
|
|
61
|
+
Changelog = "https://github.com/rn-forge/pykit/blob/main/packages/rn-forge-fastapi/CHANGELOG.md"
|
|
62
|
+
Issues = "https://github.com/rn-forge/pykit/issues"
|
|
63
|
+
|
|
64
|
+
[build-system]
|
|
65
|
+
requires = ["uv_build>=0.11.28,<0.12.0"]
|
|
66
|
+
build-backend = "uv_build"
|
|
67
|
+
|
|
68
|
+
[tool.uv.build-backend]
|
|
69
|
+
module-name = "rn_forge.fastapi"
|
|
70
|
+
|
|
71
|
+
[tool.uv.sources]
|
|
72
|
+
rn-forge-auth = { workspace = true }
|
|
73
|
+
rn-forge-commons = { workspace = true }
|
|
74
|
+
rn-forge-data = { workspace = true }
|
|
75
|
+
rn-forge-web = { workspace = true }
|
|
76
|
+
rn-forge-fastapi = { workspace = true }
|
|
77
|
+
|
|
78
|
+
[tool.workspace-ci.smoke]
|
|
79
|
+
modules = ["rn_forge.fastapi"]
|
|
80
|
+
|
|
81
|
+
[tool.workspace-ci.smoke.extras]
|
|
82
|
+
oidc = ["rn_forge.auth.oidc"]
|
|
83
|
+
redis = ["rn_forge.auth.redis", "rn_forge.fastapi.auth.redis"]
|
|
84
|
+
transfer = ["rn_forge.fastapi.transfer"]
|
|
85
|
+
|
|
86
|
+
[tool.pytest.ini_options]
|
|
87
|
+
addopts = "-ra --import-mode=importlib -m 'not scaffold'"
|
|
88
|
+
markers = [
|
|
89
|
+
"unit: fast isolated tests",
|
|
90
|
+
"scaffold: installs built wheels into a scaffolded application (slow)",
|
|
91
|
+
"security_control: demonstrates the security control with the given rn_forge.auth.conformance case ID",
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
[dependency-groups]
|
|
95
|
+
dev = [
|
|
96
|
+
"assertpy>=1.1",
|
|
97
|
+
"httpx>=0.28.1",
|
|
98
|
+
"opentelemetry-sdk>=1.44",
|
|
99
|
+
"pyright>=1.1.411",
|
|
100
|
+
"pytest>=9.1.1",
|
|
101
|
+
"pytest-cov>=7.1.0",
|
|
102
|
+
"pytest-randomly>=4.1.0",
|
|
103
|
+
"rn-forge-fastapi[oidc,redis,transfer]",
|
|
104
|
+
"ruff>=0.15.21",
|
|
105
|
+
# Test-only: the ResourcePolicy tests scope real `select()` queries.
|
|
106
|
+
"sqlalchemy>=2.0",
|
|
107
|
+
]
|
|
108
|
+
docs = [
|
|
109
|
+
"mkdocs>=1.6.1",
|
|
110
|
+
"mkdocs-material>=9.7.6",
|
|
111
|
+
"mkdocstrings[python]>=1.0.6",
|
|
112
|
+
"rn-forge-fastapi",
|
|
113
|
+
]
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""FastAPI adapters for :mod:`rn_forge.web` contracts."""
|
|
2
|
+
|
|
3
|
+
from rn_forge.fastapi.app import AppConfig, FastApiApp
|
|
4
|
+
from rn_forge.fastapi.auth import (
|
|
5
|
+
ANONYMOUS_PREFIX,
|
|
6
|
+
ANONYMOUS_TTL,
|
|
7
|
+
CSRF_COOKIE,
|
|
8
|
+
CSRF_HEADER,
|
|
9
|
+
SESSION_COOKIE,
|
|
10
|
+
TRANSACTION_COOKIE,
|
|
11
|
+
ActiveSession,
|
|
12
|
+
AuthRoutesConfig,
|
|
13
|
+
BearerAuth,
|
|
14
|
+
CsrfProtection,
|
|
15
|
+
CsrfStore,
|
|
16
|
+
InMemoryCsrfStore,
|
|
17
|
+
InMemoryRateLimiter,
|
|
18
|
+
PolicyGuard,
|
|
19
|
+
RateLimit,
|
|
20
|
+
RateLimiter,
|
|
21
|
+
SessionMiddleware,
|
|
22
|
+
Sessions,
|
|
23
|
+
active_session,
|
|
24
|
+
auth_router,
|
|
25
|
+
basic_auth,
|
|
26
|
+
bearer_auth,
|
|
27
|
+
current_principal,
|
|
28
|
+
requires,
|
|
29
|
+
requires_permission,
|
|
30
|
+
rotate_session,
|
|
31
|
+
sessions_for,
|
|
32
|
+
)
|
|
33
|
+
from rn_forge.fastapi.cors import CorsPolicy, apply_cors
|
|
34
|
+
from rn_forge.fastapi.dependencies import (
|
|
35
|
+
conditional_get,
|
|
36
|
+
order_by_param,
|
|
37
|
+
page_params,
|
|
38
|
+
require_idempotency_key,
|
|
39
|
+
require_if_match,
|
|
40
|
+
)
|
|
41
|
+
from rn_forge.fastapi.deprecation import deprecated
|
|
42
|
+
from rn_forge.fastapi.health import health_router
|
|
43
|
+
from rn_forge.fastapi.idempotency import idempotent
|
|
44
|
+
from rn_forge.fastapi.merge_patch import (
|
|
45
|
+
merge_into,
|
|
46
|
+
merge_patch_body,
|
|
47
|
+
merge_patch_openapi,
|
|
48
|
+
)
|
|
49
|
+
from rn_forge.fastapi.openapi import operation_id
|
|
50
|
+
from rn_forge.fastapi.problem import Log, register_problem_handlers
|
|
51
|
+
from rn_forge.fastapi.read_mask import masked, read_mask_param
|
|
52
|
+
from rn_forge.fastapi.soft_delete import (
|
|
53
|
+
SoftDeleteState,
|
|
54
|
+
SoftDeleteStore,
|
|
55
|
+
show_deleted_param,
|
|
56
|
+
soft_delete_router,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
__all__ = [
|
|
60
|
+
"ANONYMOUS_PREFIX",
|
|
61
|
+
"ANONYMOUS_TTL",
|
|
62
|
+
"CSRF_COOKIE",
|
|
63
|
+
"CSRF_HEADER",
|
|
64
|
+
"SESSION_COOKIE",
|
|
65
|
+
"TRANSACTION_COOKIE",
|
|
66
|
+
"ActiveSession",
|
|
67
|
+
"AppConfig",
|
|
68
|
+
"AuthRoutesConfig",
|
|
69
|
+
"BearerAuth",
|
|
70
|
+
"CorsPolicy",
|
|
71
|
+
"CsrfProtection",
|
|
72
|
+
"CsrfStore",
|
|
73
|
+
"FastApiApp",
|
|
74
|
+
"InMemoryCsrfStore",
|
|
75
|
+
"InMemoryRateLimiter",
|
|
76
|
+
"Log",
|
|
77
|
+
"PolicyGuard",
|
|
78
|
+
"RateLimit",
|
|
79
|
+
"RateLimiter",
|
|
80
|
+
"SessionMiddleware",
|
|
81
|
+
"Sessions",
|
|
82
|
+
"SoftDeleteState",
|
|
83
|
+
"SoftDeleteStore",
|
|
84
|
+
"active_session",
|
|
85
|
+
"apply_cors",
|
|
86
|
+
"auth_router",
|
|
87
|
+
"basic_auth",
|
|
88
|
+
"bearer_auth",
|
|
89
|
+
"conditional_get",
|
|
90
|
+
"current_principal",
|
|
91
|
+
"deprecated",
|
|
92
|
+
"health_router",
|
|
93
|
+
"idempotent",
|
|
94
|
+
"masked",
|
|
95
|
+
"merge_into",
|
|
96
|
+
"merge_patch_body",
|
|
97
|
+
"merge_patch_openapi",
|
|
98
|
+
"operation_id",
|
|
99
|
+
"order_by_param",
|
|
100
|
+
"page_params",
|
|
101
|
+
"read_mask_param",
|
|
102
|
+
"register_problem_handlers",
|
|
103
|
+
"require_idempotency_key",
|
|
104
|
+
"require_if_match",
|
|
105
|
+
"requires",
|
|
106
|
+
"requires_permission",
|
|
107
|
+
"rotate_session",
|
|
108
|
+
"sessions_for",
|
|
109
|
+
"show_deleted_param",
|
|
110
|
+
"soft_delete_router",
|
|
111
|
+
]
|