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
# Full featured FastAPI template, all boring and tedious things are covered
1
+
## Minimal async FastAPI + postgresql template
2
+
3
+

2
4
3
5
- SQLAlchemy using new 2.0 API + async queries
4
6
- Postgresql database under `asyncpg`
5
7
- Alembic migrations
6
8
- Very minimal project structure yet ready for quick start building new api
7
9
- Refresh token endpoint (not only access like in official template)
8
-
- Two databases in docker-compose.yml (second for tests)
10
+
- Two databases in docker-compose.yml (second one for tests)
9
11
- poetry
10
12
-`pre-push.sh` script with poetry export, autoflake, black, isort and flake8
11
-
- Setup for tests, one big test for token flow and very extensible `conftest.py`
13
+
- Setup for async tests, one func test for token flow and very extensible `conftest.py`
14
+
15
+
## What this repo is
16
+
17
+
This is a minimal template for FastAPI backend + postgresql db as of 2021.11, `async` style for database sessions, endpoints and tests. It provides basic codebase that almost every application has, but nothing more.
18
+
19
+
## What this repo is not
12
20
13
-
# Quickstart
21
+
It is not complex, full featured solutions for all human kind problems. It doesn't include any third party that isn't necessary for most of apps (dashboards, queues) or implementation differs so much in every project that it's pointless (complex User model, emails, RBAC, permissions).
# Alembic migrations upgrade and initial_data.py script
28
38
bash init.sh
29
39
# And this is it:
30
-
uvicorn app.main:app
40
+
uvicorn app.main:app --reload
31
41
```
32
42
33
43
tests:
34
44
35
45
```bash
46
+
# Note, it will use second database declared in docker-compose.yml, not default one
36
47
pytest
37
-
# Note, it will use second database declared in docker-compose.yml, not default one like
38
-
# in official template
48
+
39
49
```
40
50
41
-
# About
51
+
##About
42
52
43
53
This project is heavily base on 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)), but as it is now not too much up-to-date, it is much easier to create new one than change official. I didn't like some of conventions over there also (`crud` and `db` folders for example).
44
54
45
-
`2.0` style SQLAlchemy API is good enough so there is no need to write everything in `crud` and waste our time... The `core` folder was also rewritten. There is great base for writting tests in `tests`, but I didn't want to write hundreds of them, I noticed that usually after changes in the structure of the project, auto tests are useless and you have to write them from scratch, hence less than more. Similarly with the `User` model, it is very modest, because it will be adapted to the project anyway (and there are no tests for these endpoints)
55
+
`2.0` style SQLAlchemy API is good enough so there is no need to write everything in `crud` and waste our time... The `core` folder was also rewritten. There is great base for writting tests in `tests`, but I didn't want to write hundreds of them, I noticed that usually after changes in the structure of the project, auto tests are useless and you have to write them from scratch anyway (delete old ones...), hence less than more. Similarly with the `User` model, it is very modest, because it will be adapted to the project anyway (and there are no tests for these endpoints, you would remove them probably).
56
+
57
+
## Step by step example
58
+
59
+
I always enjoy to to have some kind of example in templates (even if I don't like it much, _some_ parts may be useful and save my time...), so let's create `POST` endpoint for creating dogs.
0 commit comments