fastapi-restly 3.0.0rc1__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_restly-3.0.0rc1/LICENSE +21 -0
- fastapi_restly-3.0.0rc1/MANIFEST.in +1 -0
- fastapi_restly-3.0.0rc1/PKG-INFO +371 -0
- fastapi_restly-3.0.0rc1/README.md +308 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/__init__.py +131 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/_exceptions.py +194 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/db/__init__.py +48 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/db/_globals.py +92 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/db/_proxy.py +37 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/db/_session.py +232 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/models/__init__.py +30 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/models/_base.py +90 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/models/_helpers.py +40 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/py.typed +0 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/pytest_fixtures.py +27 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/query/__init__.py +13 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/query/_impl.py +567 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/query/_shared.py +22 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/schemas/__init__.py +35 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/schemas/_base.py +496 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/schemas/_generator.py +379 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/testing/__init__.py +29 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/testing/_client.py +98 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/testing/_fixtures.py +212 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/views/__init__.py +47 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/views/_async.py +260 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/views/_base.py +1262 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/views/_openapi.py +200 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/views/_react_admin.py +363 -0
- fastapi_restly-3.0.0rc1/fastapi_restly/views/_sync.py +251 -0
- fastapi_restly-3.0.0rc1/fastapi_restly.egg-info/PKG-INFO +371 -0
- fastapi_restly-3.0.0rc1/fastapi_restly.egg-info/SOURCES.txt +35 -0
- fastapi_restly-3.0.0rc1/fastapi_restly.egg-info/dependency_links.txt +1 -0
- fastapi_restly-3.0.0rc1/fastapi_restly.egg-info/requires.txt +36 -0
- fastapi_restly-3.0.0rc1/fastapi_restly.egg-info/top_level.txt +1 -0
- fastapi_restly-3.0.0rc1/pyproject.toml +131 -0
- fastapi_restly-3.0.0rc1/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rutger Prins
|
|
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 @@
|
|
|
1
|
+
prune tests
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastapi-restly
|
|
3
|
+
Version: 3.0.0rc1
|
|
4
|
+
Summary: A REST Framework for FastAPI
|
|
5
|
+
Author-email: Rutger Prins <rutgerprins@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/rjprins/fastapi-restly
|
|
8
|
+
Project-URL: Repository, https://github.com/rjprins/fastapi-restly
|
|
9
|
+
Project-URL: Source, https://github.com/rjprins/fastapi-restly
|
|
10
|
+
Project-URL: Documentation, https://rjprins.github.io/fastapi-restly/
|
|
11
|
+
Project-URL: Issues, https://github.com/rjprins/fastapi-restly/issues
|
|
12
|
+
Project-URL: Changelog, https://github.com/rjprins/fastapi-restly/blob/main/CHANGELOG.md
|
|
13
|
+
Keywords: fastapi,rest,crud,crud-api,sqlalchemy,pydantic,api,framework,react-admin
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Framework :: FastAPI
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Database
|
|
24
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.10
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: alembic>=1.15.2
|
|
31
|
+
Requires-Dist: fastapi>=0.115.0
|
|
32
|
+
Requires-Dist: orjson>=3.10.18
|
|
33
|
+
Requires-Dist: pydantic>=2.11.0
|
|
34
|
+
Requires-Dist: pydantic-settings>=2.9.1
|
|
35
|
+
Requires-Dist: sqlalchemy[asyncio]>=2.0.22
|
|
36
|
+
Provides-Extra: standard
|
|
37
|
+
Requires-Dist: aiosqlite>=0.21.0; extra == "standard"
|
|
38
|
+
Requires-Dist: fastapi[standard]>=0.115.0; extra == "standard"
|
|
39
|
+
Requires-Dist: httpx>=0.27.0; extra == "standard"
|
|
40
|
+
Requires-Dist: pytest>=8.3.5; extra == "standard"
|
|
41
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == "standard"
|
|
42
|
+
Requires-Dist: pytest-cov>=6.1.1; extra == "standard"
|
|
43
|
+
Provides-Extra: docs
|
|
44
|
+
Requires-Dist: ghp-import>=2.1.0; extra == "docs"
|
|
45
|
+
Requires-Dist: myst-parser>=4.0.1; extra == "docs"
|
|
46
|
+
Requires-Dist: pydata-sphinx-theme>=0.16.0; extra == "docs"
|
|
47
|
+
Requires-Dist: sphinx>=8.1.3; extra == "docs"
|
|
48
|
+
Requires-Dist: sphinx-autobuild>=2024.10.3; extra == "docs"
|
|
49
|
+
Requires-Dist: sphinx-copybutton>=0.5.2; extra == "docs"
|
|
50
|
+
Requires-Dist: sphinx-design>=0.6.0; extra == "docs"
|
|
51
|
+
Requires-Dist: sphinx-sitemap>=2.9.0; extra == "docs"
|
|
52
|
+
Provides-Extra: testing
|
|
53
|
+
Requires-Dist: httpx>=0.27.0; extra == "testing"
|
|
54
|
+
Requires-Dist: pytest>=8.3.5; extra == "testing"
|
|
55
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == "testing"
|
|
56
|
+
Requires-Dist: pytest-cov>=6.1.1; extra == "testing"
|
|
57
|
+
Provides-Extra: test
|
|
58
|
+
Requires-Dist: httpx>=0.27.0; extra == "test"
|
|
59
|
+
Requires-Dist: pytest>=8.3.5; extra == "test"
|
|
60
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == "test"
|
|
61
|
+
Requires-Dist: pytest-cov>=6.1.1; extra == "test"
|
|
62
|
+
Dynamic: license-file
|
|
63
|
+
|
|
64
|
+
# FastAPI-Restly
|
|
65
|
+
|
|
66
|
+
[](https://github.com/rjprins/fastapi-restly/actions/workflows/ci.yml)
|
|
67
|
+
[](https://github.com/rjprins/fastapi-restly/blob/main/pyproject.toml)
|
|
68
|
+
[](https://github.com/rjprins/fastapi-restly/blob/main/LICENSE)
|
|
69
|
+
[](https://rjprins.github.io/fastapi-restly/coverage/)
|
|
70
|
+
|
|
71
|
+
<p align="center">
|
|
72
|
+
<img src="https://raw.githubusercontent.com/rjprins/fastapi-restly/main/docs/_static/restly-cat.png" alt="FastAPI-Restly logo" width="200">
|
|
73
|
+
</p>
|
|
74
|
+
|
|
75
|
+
**Build maintainable CRUD APIs on FastAPI, SQLAlchemy 2.0, and Pydantic v2 — with real class-based views.**
|
|
76
|
+
|
|
77
|
+
> **Status:** `3.0.0` — first public release. See the [Changelog](CHANGELOG.md).
|
|
78
|
+
> ```bash
|
|
79
|
+
> pip install "fastapi-restly[standard]"
|
|
80
|
+
> ```
|
|
81
|
+
|
|
82
|
+
**Docs:** <https://rjprins.github.io/fastapi-restly/> · **[Changelog](CHANGELOG.md)** · **[Contributing](CONTRIBUTING.md)** · **[Security](SECURITY.md)** · **[Code of Conduct](CODE_OF_CONDUCT.md)** · **[Examples](example-projects/)**
|
|
83
|
+
|
|
84
|
+
## Why FastAPI-Restly?
|
|
85
|
+
|
|
86
|
+
The differentiator is **true class-based views**. You subclass `RestView` / `AsyncRestView` and override handlers like `handle_get`, `handle_create`, or object helpers like `save_object` — CRUD logic is *methods you can swap*, not opaque generated functions. Share behavior across views via inheritance the way you would with any Python class.
|
|
87
|
+
|
|
88
|
+
* **CRUD endpoints in minutes** — auto-generates Pydantic schemas from your SQLAlchemy models.
|
|
89
|
+
* **Override anything** — replace an endpoint, or just its business logic, without awkward hacks.
|
|
90
|
+
* **React Admin ready** — `AsyncReactAdminView` speaks the `ra-data-simple-rest` wire contract, no custom data provider needed.
|
|
91
|
+
* **Modern stack** — SQLAlchemy 2.0, Pydantic v2, async and sync support.
|
|
92
|
+
* **Filtering, pagination, sorting** — standard HTTP query interface generated from your response schema.
|
|
93
|
+
* **Field control** — `ReadOnly` / `WriteOnly` markers, plus scalar foreign-key references via `IDRef[...]`.
|
|
94
|
+
* **Testing utilities** — `RestlyTestClient` and savepoint-based isolation fixtures.
|
|
95
|
+
|
|
96
|
+
## Quickstart
|
|
97
|
+
|
|
98
|
+
FastAPI-Restly turns a SQLAlchemy model into a class-based CRUD resource:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
import fastapi_restly as fr
|
|
102
|
+
from fastapi import FastAPI
|
|
103
|
+
from sqlalchemy.orm import Mapped
|
|
104
|
+
|
|
105
|
+
app = FastAPI()
|
|
106
|
+
|
|
107
|
+
class User(fr.IDBase):
|
|
108
|
+
name: Mapped[str]
|
|
109
|
+
email: Mapped[str]
|
|
110
|
+
|
|
111
|
+
@fr.include_view(app)
|
|
112
|
+
class UserView(fr.AsyncRestView):
|
|
113
|
+
prefix = "/users"
|
|
114
|
+
model = User
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
That view exposes list, create, read, patch, and delete endpoints with filtering,
|
|
118
|
+
sorting, pagination, and an auto-generated Pydantic schema. For the full
|
|
119
|
+
copy-paste app, database setup, and run command, see
|
|
120
|
+
[Getting Started](docs/getting_started.md).
|
|
121
|
+
|
|
122
|
+
## How does it compare?
|
|
123
|
+
|
|
124
|
+
[`fastapi-crudrouter`](https://github.com/awtkns/fastapi-crudrouter) and [`fastcrud`](https://github.com/igorbenav/fastcrud) generate CRUD **functions** and register them on a router. FastAPI-Restly generates CRUD **methods on a class you can subclass**.
|
|
125
|
+
|
|
126
|
+
Unlike SQLModel, Restly does not ask you to wrap SQLAlchemy and Pydantic into one abstraction. Use explicit schemas when correctness matters, or let Restly derive them when the model/schema boundary is simple.
|
|
127
|
+
|
|
128
|
+
| | fastapi-crudrouter | fastcrud | **fastapi-restly** |
|
|
129
|
+
|---|---|---|---|
|
|
130
|
+
| Style | Router factory | Router factory | **Class-based views** |
|
|
131
|
+
| Customize an endpoint | Replace the route | Replace the route | Override `handle_get` / `handle_create` / `save_object`, or replace the route |
|
|
132
|
+
| Share behavior across resources | Wrapper functions | Wrapper functions | **Subclass a base view** |
|
|
133
|
+
| Schema generation | Optional | Optional | Optional (auto from model) |
|
|
134
|
+
| SQLAlchemy 2.0 / Pydantic v2 | Partial | Yes | **Yes, native** |
|
|
135
|
+
| React Admin wire contract | No | No | **Built-in (`AsyncReactAdminView`)** |
|
|
136
|
+
|
|
137
|
+
If you want a router that drops in and disappears, the CRUD-router libraries are a good fit. If you want a small object-oriented layer where every operation is a hookable method, that's Restly.
|
|
138
|
+
|
|
139
|
+
## Philosophy
|
|
140
|
+
|
|
141
|
+
Restly is a stack of micro-libraries. Each layer adds convenience while letting you drop down for deeper control. The less customization you need, the more you get out-of-the-box — full customization never requires awkward hacks. Restly stays close to patterns already provided by FastAPI, Pydantic, and SQLAlchemy.
|
|
142
|
+
|
|
143
|
+
## Installation (development)
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
git clone https://github.com/rjprins/fastapi-restly.git
|
|
147
|
+
cd fastapi-restly
|
|
148
|
+
uv sync
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Typing compatibility
|
|
152
|
+
|
|
153
|
+
Restly keeps consumer-facing typing fixtures in [`tests/typing/`](tests/typing) checked with Pyright to catch editor regressions:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
make test-typing
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Advanced features
|
|
160
|
+
|
|
161
|
+
### Manual schema definition
|
|
162
|
+
|
|
163
|
+
For custom validation or field aliases:
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
class UserSchema(fr.IDSchema):
|
|
167
|
+
name: str
|
|
168
|
+
email: str
|
|
169
|
+
age: int
|
|
170
|
+
internal_id: fr.ReadOnly[str]
|
|
171
|
+
|
|
172
|
+
@fr.include_view(app)
|
|
173
|
+
class UserView(fr.AsyncRestView):
|
|
174
|
+
prefix = "/users"
|
|
175
|
+
model = User
|
|
176
|
+
schema = UserSchema
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Use **auto-schema** for prototypes and internal tools. Use an **explicit schema** when contract stability and validation control matter (public APIs, aliases, strict response shapes).
|
|
180
|
+
|
|
181
|
+
### List endpoint query parameters
|
|
182
|
+
|
|
183
|
+
List endpoints expose a stable URL parameter dialect generated from the
|
|
184
|
+
response schema:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
GET /users/?name=John&age__gte=21
|
|
188
|
+
GET /users/?status=active,pending # comma-separated → OR (IN)
|
|
189
|
+
GET /users/?status__ne=archived,deleted # comma-separated → NOT IN
|
|
190
|
+
GET /users/?email__contains=example
|
|
191
|
+
GET /users/?deleted_at__isnull=true
|
|
192
|
+
GET /users/?order_by=-created_at,name
|
|
193
|
+
GET /users/?page=2&page_size=10
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Parameter keys follow the **response schema's public names** end-to-end —
|
|
197
|
+
including dotted relation paths. If `ArticleSchema.author` has
|
|
198
|
+
`Field(alias="writer")` and `AuthorSchema.name` has
|
|
199
|
+
`Field(alias="authorName")`, the URL key is `writer.authorName`. Aliased
|
|
200
|
+
fields are only reachable by their alias; `populate_by_name` does not
|
|
201
|
+
extend the URL surface with the Python field name.
|
|
202
|
+
|
|
203
|
+
Pagination is opt-in: omitting `page_size` returns every matching row.
|
|
204
|
+
For public/production endpoints set `default_page_size` and
|
|
205
|
+
`max_page_size` on the view class:
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
class UserView(fr.AsyncRestView):
|
|
209
|
+
default_page_size = 25
|
|
210
|
+
max_page_size = 200
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
See [How-To: Filter, Sort, and Paginate Lists](docs/howto_query_modifiers.md)
|
|
214
|
+
for the full operator surface, alias rules, and pagination guidance.
|
|
215
|
+
|
|
216
|
+
### Read-only and write-only fields
|
|
217
|
+
|
|
218
|
+
`IDSchema` already provides a read-only `id`, so don't redeclare it unless you need to narrow the type.
|
|
219
|
+
|
|
220
|
+
```python
|
|
221
|
+
class UserSchema(fr.IDSchema):
|
|
222
|
+
name: str
|
|
223
|
+
email: str
|
|
224
|
+
password: fr.WriteOnly[str] # never appears in responses
|
|
225
|
+
created_at: fr.ReadOnly[datetime] # cannot be set in requests
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Relationships
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
from sqlalchemy import ForeignKey
|
|
232
|
+
from sqlalchemy.orm import Mapped, mapped_column
|
|
233
|
+
|
|
234
|
+
class Order(fr.IDBase):
|
|
235
|
+
customer_id: Mapped[int] = mapped_column(ForeignKey("customer.id"))
|
|
236
|
+
total: Mapped[float]
|
|
237
|
+
|
|
238
|
+
class OrderSchema(fr.IDSchema):
|
|
239
|
+
customer_id: fr.IDRef[Customer] # wire format: 123 — resolved to FK
|
|
240
|
+
total: float
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Custom endpoints and handlers
|
|
244
|
+
|
|
245
|
+
Add endpoints with `@fr.get`, `@fr.post`, `@fr.put`, `@fr.patch`, `@fr.delete`, or the generic `@fr.route`. Override `handle_*` handlers (`handle_list`, `handle_get`, `handle_create`, ...) to customise built-in CRUD logic without replacing the endpoint.
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
@fr.include_view(app)
|
|
249
|
+
class UserView(fr.AsyncRestView):
|
|
250
|
+
prefix = "/users"
|
|
251
|
+
model = User
|
|
252
|
+
schema = UserSchema
|
|
253
|
+
|
|
254
|
+
@fr.get("/{id}/download")
|
|
255
|
+
async def download_user(self, id: int):
|
|
256
|
+
return {"id": id, "status": "ok"}
|
|
257
|
+
|
|
258
|
+
async def handle_list(self, query_params, query=None):
|
|
259
|
+
# Custom logic here
|
|
260
|
+
return await super().handle_list(query_params, query=query)
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### React Admin integration
|
|
264
|
+
|
|
265
|
+
Use `AsyncReactAdminView` to get a backend that [react-admin](https://marmelab.com/react-admin/) with [`ra-data-simple-rest`](https://github.com/marmelab/react-admin/tree/master/packages/ra-data-simple-rest) connects to out of the box:
|
|
266
|
+
|
|
267
|
+
```python
|
|
268
|
+
@fr.include_view(app)
|
|
269
|
+
class ProductView(fr.AsyncReactAdminView):
|
|
270
|
+
prefix = "/products"
|
|
271
|
+
model = Product
|
|
272
|
+
schema = ProductSchema
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
The view speaks the `ra-data-simple-rest` wire contract:
|
|
276
|
+
|
|
277
|
+
- **List** — translates `sort=["name","ASC"]`, `range=[0,24]`, and `filter={"name":"foo"}` into SQL and returns a JSON array with a `Content-Range: items 0-24/315` header.
|
|
278
|
+
- **All other CRUD** — `GET /{id}`, `POST /`, `PATCH /{id}`, `DELETE /{id}` work unchanged.
|
|
279
|
+
|
|
280
|
+
See [React Admin Integration](https://rjprins.github.io/fastapi-restly/howto_react_admin.html) in the docs for CORS setup and customization.
|
|
281
|
+
|
|
282
|
+
### Excluding built-in routes
|
|
283
|
+
|
|
284
|
+
```python
|
|
285
|
+
@fr.include_view(app)
|
|
286
|
+
class UserView(fr.AsyncRestView):
|
|
287
|
+
prefix = "/users"
|
|
288
|
+
model = User
|
|
289
|
+
exclude_routes = ("delete",) # names: "index", "get", "post", "patch", "delete"
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Pagination metadata
|
|
293
|
+
|
|
294
|
+
```python
|
|
295
|
+
@fr.include_view(app)
|
|
296
|
+
class UserView(fr.AsyncRestView):
|
|
297
|
+
prefix = "/users"
|
|
298
|
+
model = User
|
|
299
|
+
include_pagination_metadata = True
|
|
300
|
+
# Response: {"items": [...], "total": N, "page": 1, "page_size": 100, "total_pages": N, ...}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Testing
|
|
304
|
+
|
|
305
|
+
`fastapi_restly.testing` provides pytest fixtures (`app`, `client`, `async_session`, `session`) with **savepoint-based isolation** — each test runs inside a transaction that rolls back automatically, so no data leaks between tests. Add to your `conftest.py`:
|
|
306
|
+
|
|
307
|
+
Install the testing extra when consuming FastAPI-Restly as a package:
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
pip install "fastapi-restly[testing]"
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
```python
|
|
314
|
+
# conftest.py
|
|
315
|
+
import fastapi_restly as fr
|
|
316
|
+
|
|
317
|
+
pytest_plugins = ["fastapi_restly.pytest_fixtures"]
|
|
318
|
+
|
|
319
|
+
fr.configure(async_database_url="sqlite+aiosqlite:///test.db")
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
`RestlyTestClient` automatically asserts the expected HTTP status (`200` for GET, `201` for POST, `204` for DELETE, ...) and raises a descriptive `AssertionError` with the response body on failure:
|
|
323
|
+
|
|
324
|
+
```python
|
|
325
|
+
# test_users.py
|
|
326
|
+
def test_create_and_fetch_user(client):
|
|
327
|
+
# Raises AssertionError if status != 201
|
|
328
|
+
response = client.post("/users/", json={"name": "John", "email": "john@example.com"})
|
|
329
|
+
user_id = response.json()["id"]
|
|
330
|
+
|
|
331
|
+
# Raises AssertionError if status != 200
|
|
332
|
+
data = client.get(f"/users/{user_id}").json()
|
|
333
|
+
assert data["name"] == "John"
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Pass `assert_status_code=None` to skip the assertion and inspect the response yourself.
|
|
337
|
+
|
|
338
|
+
## Configuration
|
|
339
|
+
|
|
340
|
+
```python
|
|
341
|
+
# Async SQLite
|
|
342
|
+
fr.configure(async_database_url="sqlite+aiosqlite:///app.db")
|
|
343
|
+
|
|
344
|
+
# Async PostgreSQL
|
|
345
|
+
fr.configure(async_database_url="postgresql+asyncpg://user:pass@localhost/db")
|
|
346
|
+
|
|
347
|
+
# Sync SQLite
|
|
348
|
+
fr.configure(database_url="sqlite:///app.db")
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## Documentation
|
|
352
|
+
|
|
353
|
+
- **[Getting Started](https://rjprins.github.io/fastapi-restly/getting_started.html)** — fast path from zero to a working API
|
|
354
|
+
- **[User Guide](https://rjprins.github.io/fastapi-restly/user_guide.html)** — tutorial walkthroughs and topic guides
|
|
355
|
+
- **[API Reference](https://rjprins.github.io/fastapi-restly/api_reference.html)** — complete API docs
|
|
356
|
+
|
|
357
|
+
## Examples
|
|
358
|
+
|
|
359
|
+
Complete applications under [`example-projects/`](example-projects/):
|
|
360
|
+
|
|
361
|
+
- **[Shop](example-projects/shop/)** — e-commerce API with products, orders, customers
|
|
362
|
+
- **[Blog](example-projects/blog/)** — minimal blog with a single `Blog` model
|
|
363
|
+
- **[SaaS](example-projects/saas/)** — multi-tenant project management API
|
|
364
|
+
|
|
365
|
+
## Contributing
|
|
366
|
+
|
|
367
|
+
Pull requests and issue discussions welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for setup, coding standards, and the test workflow. By participating you agree to the [Code of Conduct](CODE_OF_CONDUCT.md). Security issues: see [SECURITY.md](SECURITY.md).
|
|
368
|
+
|
|
369
|
+
## License
|
|
370
|
+
|
|
371
|
+
MIT — see [LICENSE](LICENSE).
|