You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[`Pydantic V2`](https://docs.pydantic.dev/2.4/): the most widely used data validation library for Python, now rewritten in Rust [`(5x to 50x speed improvement)`](https://docs.pydantic.dev/latest/blog/pydantic-v2-alpha/)
17
17
-[`SQLAlchemy 2.0`](https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html): Python SQL toolkit and Object Relational Mapper
18
18
-[`PostgreSQL`](https://www.postgresql.org): The World's Most Advanced Open Source Relational Database
19
-
-[`Redis`](https://redis.io): The open source, in-memory data store used by millions of developers as a database, cache, streaming engine, and message broker.
19
+
-[`Redis`](https://redis.io): The open source, in-memory data store used by millions of developers as a database, cache, streaming engine, and message broker
20
+
-[`ARQ`](https://arq-docs.helpmanual.io) Job queues and RPC in python with asyncio and redis.
20
21
21
22
## 1. Features
22
23
- Fully async
23
24
- Pydantic V2 and SQLAlchemy 2.0
24
25
- User authentication with JWT
25
26
- Easy redis caching
26
27
- Easy client-side caching
28
+
- ARQ integration for task queue
27
29
- Easily extendable
28
30
- Flexible
29
31
30
-
### 1.1 To do
31
-
-[x] Redis cache
32
-
-[ ] Arq job queues
33
-
-[x] App settings (such as database connection, etc) only for what's inherited in core.config.Settings
34
-
35
32
## 2. Contents
36
33
0.[About](#0-about)
37
34
1.[Features](#1-features)
38
-
1.[To do](#11-to-do)
39
35
2.[Contents](#2-contents)
40
36
3.[Usage](#3-usage)
41
37
4.[Requirements](#4-requirements)
@@ -48,15 +44,17 @@
48
44
7.[Creating the first superuser](#7-creating-the-first-superuser)
Inside `app/models`, create a new `entity.py` for each new entity (replacing entity with the name) and define the attributes according to [SQLAlchemy 2.0 standards](https://docs.sqlalchemy.org/en/20/orm/mapping_styles.html#orm-mapping-styles):
236
311
```python
237
312
from sqlalchemy import String, DateTime
@@ -249,7 +324,7 @@ class Entity(Base):
249
324
...
250
325
```
251
326
252
-
### 9.3 Pydantic Schemas
327
+
### 9.4 Pydantic Schemas
253
328
Inside `app/schemas`, create a new `entity.py` for for each new entity (replacing entity with the name) and create the schemas according to [Pydantic V2](https://docs.pydantic.dev/latest/#pydantic-examples) standards:
254
329
```python
255
330
from typing import Annotated
@@ -289,7 +364,7 @@ class EntityDelete(BaseModel):
289
364
290
365
```
291
366
292
-
### 9.4 Alembic Migration
367
+
### 9.5 Alembic Migration
293
368
Then, while in the `src` folder, run Alembic migrations:
294
369
```sh
295
370
poetry run alembic revision --autogenerate
@@ -300,7 +375,7 @@ And to apply the migration
300
375
poetry run alembic upgrade head
301
376
```
302
377
303
-
### 9.5 CRUD
378
+
### 9.6 CRUD
304
379
Inside `app/crud`, create a new `crud_entities.py` inheriting from `CRUDBase` for each new entity:
Inside `app/api/v1`, create a new `entities.py` file and create the desired routes
316
391
```python
317
392
from typing import Annotated
@@ -342,7 +417,7 @@ router = APIRouter(prefix="/v1") # this should be there already
342
417
router.include_router(entity_router)
343
418
```
344
419
345
-
### 9.7 Caching
420
+
### 9.8 Caching
346
421
The `cache` decorator allows you to cache the results of FastAPI endpoint functions, enhancing response times and reducing the load on your application by storing and retrieving data in a cache.
347
422
348
423
Caching the response of an endpoint is really simple, just apply the `cache` decorator to the endpoint function.
@@ -390,7 +465,7 @@ In this case, what will happen is:
390
465
391
466
Passing resource_id_name is usually preferred.
392
467
393
-
### 9.8 More Advanced Caching
468
+
### 9.9 More Advanced Caching
394
469
The behaviour of the `cache` decorator changes based on the request method of your endpoint.
395
470
It caches the result if you are passing it to a **GET** endpoint, and it invalidates the cache with this key_prefix and id if passed to other endpoints (**PATCH**, **DELETE**).
396
471
@@ -451,7 +526,48 @@ async def patch_post(
451
526
#### Client-side Caching
452
527
For `client-side caching`, all you have to do is let the `Settings` class defined in `app/core/config.py` inherit from the `ClientSideCacheSettings` class. You can set the `CLIENT_CACHE_MAX_AGE` value in `.env,` it defaults to 60 (seconds).
0 commit comments