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
-[3. Import new models.py file in alembic env.py](#3-import-new-modelspy-file-in-alembic-envpy)
24
-
-[2. Create and apply alembic migration](#2-create-and-apply-alembic-migration)
25
-
-[3. Create request and response schemas](#3-create-request-and-response-schemas)
26
-
-[4. Create endpoints](#4-create-endpoints)
27
-
-[5. Add Pet model to tests factories](#5-add-pet-model-to-tests-factories)
28
-
-[5. Create new test file](#5-create-new-test-file)
29
-
-[6. Write tests](#6-write-tests)
24
+
-[4. Create and apply alembic migration](#4-create-and-apply-alembic-migration)
25
+
-[5. Create request and response schemas](#5-create-request-and-response-schemas)
26
+
-[6. Create endpoints](#6-create-endpoints)
27
+
-[7. Add Pet model to tests factories](#7-add-pet-model-to-tests-factories)
28
+
-[8. Create new test file](#8-create-new-test-file)
29
+
-[9. Write tests](#9-write-tests)
30
30
-[Design choices](#design-choices)
31
31
-[Dockerfile](#dockerfile)
32
32
-[Registration](#registration)
@@ -40,8 +40,6 @@ _Check out online example: [https://minimal-fastapi-postgres-template.rafsaf.pl]
40
40
41
41
## About
42
42
43
-
This project is heavily based on [the official template](https://github.com/tiangolo/full-stack-fastapi-postgresql) (and on my previous work: [link1](https://github.com/rafsaf/fastapi-plan), [link2](https://github.com/rafsaf/docker-fastapi-projects)), started on Sep 2021 and then updated (more or less) on yearly basis.
44
-
45
43
If you are curious about latest changes and rationale, read 2026 update blog post: [Update of minimal-fastapi-postgres-template to version 7.0.0](https://rafsaf.pl/blog/2026/02/07/update-of-minimal-fastapi-postgres-template-to-version-7.0.0/).
46
44
47
45
Enjoy!
@@ -54,8 +52,8 @@ Enjoy!
54
52
-[x] Full [Alembic](https://github.com/alembic/alembic) migrations setup (also in unit tests).
55
53
-[x] Secure and tested setup for [PyJWT](https://github.com/jpadilla/pyjwt) and [bcrypt](https://github.com/pyca/bcrypt).
56
54
-[x] Ready to go Dockerfile with [uvicorn](https://www.uvicorn.org/) webserver.
57
-
-[x][uv](https://docs.astral.sh/uv/getting-started/installation/), [mypy](https://github.com/python/mypy), [pre-commit](https://github.com/pre-commit/pre-commit) hooks with [ruff](https://github.com/astral-sh/ruff)
58
-
-[x] Perfect pytest asynchronous test setup with +40 tests and full coverage
55
+
-[x][uv](https://docs.astral.sh/uv/getting-started/installation/), [mypy](https://github.com/python/mypy), [pre-commit](https://github.com/pre-commit/pre-commit) hooks with [ruff](https://github.com/astral-sh/ruff).
56
+
-[x] Perfect pytest asynchronous test setup and full coverage.
You should then use `git init` (if needed) to initialize git repository and access OpenAPI spec at [http://localhost:8000/](http://localhost:8000/) by default. See last section for customizations.
100
98
101
-
### 5. Activate pre-commit
99
+
### 4. Activate pre-commit
102
100
103
101
[pre-commit](https://pre-commit.com/) is de facto standard now for pre push activities like isort or black or its nowadays replacement ruff.
104
102
@@ -121,7 +119,7 @@ pre-commit run --all-files
121
119
122
120
```
123
121
124
-
### 6. Running tests
122
+
### 5. Running tests
125
123
126
124
Note, it will create databases for session and run tests in many processes by default (using pytest-xdist) to speed up execution, based on how many CPU are available in environment.
127
125
@@ -190,7 +188,7 @@ import app.pets.models # noqa
190
188
191
189
```
192
190
193
-
### 2. Create and apply alembic migration
191
+
### 4. Create and apply alembic migration
194
192
195
193
```bash
196
194
### Use below commands in root folder in virtualenv ###
@@ -214,7 +212,7 @@ alembic upgrade head
214
212
215
213
PS. Note, alembic is configured in a way that it work with async setup and also detects specific column changes if using `--autogenerate` flag.
File `app/tests/factories.py` contains `User` model factory already. Every new DB model should also have it, as it really simplify things later (when you have more models and relationships).
311
309
@@ -322,11 +320,11 @@ class PetFactory(SQLAlchemyFactory[Pet]):
322
320
323
321
```
324
322
325
-
### 5. Create new test file
323
+
### 8. Create new test file
326
324
327
325
Create folder `app/pet/tests` and inside files `__init__.py` and eg. `test_pets_views.py`.
328
326
329
-
### 6. Write tests
327
+
### 9. Write tests
330
328
331
329
We will write two really simple tests into new file `test_pets_views.py`
0 commit comments