rn-forge-fastapi 0.4.0__py3-none-any.whl
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/__init__.py +111 -0
- rn_forge/fastapi/app.py +210 -0
- rn_forge/fastapi/auth/__init__.py +69 -0
- rn_forge/fastapi/auth/authorization.py +62 -0
- rn_forge/fastapi/auth/csrf.py +243 -0
- rn_forge/fastapi/auth/dependencies.py +374 -0
- rn_forge/fastapi/auth/proxies.py +55 -0
- rn_forge/fastapi/auth/rate_limit.py +91 -0
- rn_forge/fastapi/auth/redis.py +88 -0
- rn_forge/fastapi/auth/routes.py +725 -0
- rn_forge/fastapi/auth/sessions.py +504 -0
- rn_forge/fastapi/cors.py +80 -0
- rn_forge/fastapi/dependencies.py +157 -0
- rn_forge/fastapi/deprecation.py +45 -0
- rn_forge/fastapi/health.py +71 -0
- rn_forge/fastapi/idempotency.py +82 -0
- rn_forge/fastapi/merge_patch.py +89 -0
- rn_forge/fastapi/openapi.py +91 -0
- rn_forge/fastapi/problem.py +155 -0
- rn_forge/fastapi/py.typed +0 -0
- rn_forge/fastapi/read_mask.py +86 -0
- rn_forge/fastapi/soft_delete.py +188 -0
- rn_forge/fastapi/transfer.py +936 -0
- rn_forge_fastapi-0.4.0.dist-info/METADATA +165 -0
- rn_forge_fastapi-0.4.0.dist-info/RECORD +27 -0
- rn_forge_fastapi-0.4.0.dist-info/WHEEL +4 -0
- rn_forge_fastapi-0.4.0.dist-info/licenses/LICENSE +21 -0
|
@@ -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,27 @@
|
|
|
1
|
+
rn_forge/fastapi/__init__.py,sha256=UCGnWU4qG7cl1hwjEhAhY3ZM8vLXg4_-aS8jFfDTqrU,2556
|
|
2
|
+
rn_forge/fastapi/app.py,sha256=WL3XfC6CkCriJzf2FacXURfRyNgamy-PLC_8f7PSu5k,8727
|
|
3
|
+
rn_forge/fastapi/auth/__init__.py,sha256=OVcGbceaRYXNQxWdGJGI0_uqLFXt-05BZP3IRJSUnLg,1456
|
|
4
|
+
rn_forge/fastapi/auth/authorization.py,sha256=n3kT5HtsjjzXKYcEtDyWvSck5lnsG3dRxdxej-mLMoo,2128
|
|
5
|
+
rn_forge/fastapi/auth/csrf.py,sha256=zUBMeT5AmdrK542osl_hGScy8JXnAn08EByp_cR2fjg,8512
|
|
6
|
+
rn_forge/fastapi/auth/dependencies.py,sha256=sE1dxgB39dP98j77ArYOxfB9Yk-Cf2xEKbjac2A-K2E,13030
|
|
7
|
+
rn_forge/fastapi/auth/proxies.py,sha256=PJuZnyGfeooAr9q050mDxUwQm5UIHTVqlxCkE30P0V4,1679
|
|
8
|
+
rn_forge/fastapi/auth/rate_limit.py,sha256=D0a7PQ7StcVZp9HiUeeHv5zFO9zh2-WGyrUs4H8BK0Y,2691
|
|
9
|
+
rn_forge/fastapi/auth/redis.py,sha256=WIVmGzSXjC5xtru3EpjX0v5e12EqMBnYOsL4HIM6_bg,2799
|
|
10
|
+
rn_forge/fastapi/auth/routes.py,sha256=_kxY_hRxmQNZGjUjeM4cMeNaN-7ESD_owBGSfq_kv4A,28329
|
|
11
|
+
rn_forge/fastapi/auth/sessions.py,sha256=iWVSFFQRICnFv4xXvwW0QipHPviSPv9o9lrSXZaYCm8,18115
|
|
12
|
+
rn_forge/fastapi/cors.py,sha256=539m9hD4-8GwCMAM4iX6xX19aLTEaVtdFWa4M7FFRJE,2840
|
|
13
|
+
rn_forge/fastapi/dependencies.py,sha256=MKboTEi8TUHMxtpTFUhnEQ_TxXG63UFz-_kAYy_CeDs,5371
|
|
14
|
+
rn_forge/fastapi/deprecation.py,sha256=gKsn291BiSSBTF5HJIUYbHCBya5cZVouKe_y_9wL5to,1287
|
|
15
|
+
rn_forge/fastapi/health.py,sha256=qDOntUutsDQkWxmRW3XIO5V4ZNr36CGpUCkQzcoisSA,2286
|
|
16
|
+
rn_forge/fastapi/idempotency.py,sha256=8wHgUSy4kG_ciTCKxPf823O9gVi-CBW-6K6qcQdenHQ,2935
|
|
17
|
+
rn_forge/fastapi/merge_patch.py,sha256=_MJ9w1aFNDPamf50fKGvqGr0aTKciydDlOgngR0W7Lw,3241
|
|
18
|
+
rn_forge/fastapi/openapi.py,sha256=jJ8VYZvct8IJnZYigYLnh7I5JirXL-BuZaN11vSmzYE,3360
|
|
19
|
+
rn_forge/fastapi/problem.py,sha256=504x8FVFXeQaCVVLJpx3BMZd9g3yyh2o4RrzayZrq3Y,5401
|
|
20
|
+
rn_forge/fastapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
|
+
rn_forge/fastapi/read_mask.py,sha256=VtIhEMVsmEdzbhv7APW3kxnKqIoWu4YfQoFHT9pJ_bs,3449
|
|
22
|
+
rn_forge/fastapi/soft_delete.py,sha256=xBUWGOvwXZZ0WKUR6IkgUWjtt2FiUgQYk5Zh4BLCD9k,6233
|
|
23
|
+
rn_forge/fastapi/transfer.py,sha256=U_YocGUTum4Gs-leqA_ZGvBoCtIM2ogpo5t-lhJAFTc,32358
|
|
24
|
+
rn_forge_fastapi-0.4.0.dist-info/licenses/LICENSE,sha256=buwykOASkbZdpj0j_JmFbwNzbUiuLzOiaMQmVQt5lr8,1072
|
|
25
|
+
rn_forge_fastapi-0.4.0.dist-info/WHEEL,sha256=3NO1oYsF7mANFUWVdyEQLM-zmecczWWEmmF5rEbXrWk,80
|
|
26
|
+
rn_forge_fastapi-0.4.0.dist-info/METADATA,sha256=VKCGqBf_CIXFfjHrP596r3Q5Ud5nbuflSpi6p1llFrU,8012
|
|
27
|
+
rn_forge_fastapi-0.4.0.dist-info/RECORD,,
|
|
@@ -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.
|