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
{{ message }}
This repository was archived by the owner on Sep 28, 2023. It is now read-only.
dead simple but powerful template manager for FastAPI applications.
6
+
Dead simple but powerful template manager for FastAPI applications.
7
7
8
8
-[About](#about)
9
9
-[Quickstart](#quickstart)
@@ -17,7 +17,8 @@ dead simple but powerful template manager for FastAPI applications.
17
17
18
18
## About
19
19
20
-
features:
20
+
Features:
21
+
21
22
- postgresql database with [Tortoise ORM](https://tortoise-orm.readthedocs.io/en/latest/index.html) as ORM
22
23
- well organised, rock solid project structure (see section [Project structure](#project-structure))
23
24
- ready-to-use user model, authentiaction system (JWT), hashing with Bcrypt
@@ -29,12 +30,12 @@ features:
29
30
- poetry or pip
30
31
- deployment ready docker-compose.prod.yml file with poetry, you will only need own domain
31
32
32
-
furthermore:
33
+
Furthermore:
34
+
33
35
- full [project structure schema](#project-structure)
34
-
-[high level overview](#high-level-overview) how this project is organised and why, questions like where do the settings live or what every variable in `.env` file
36
+
-[high level overview](#high-level-overview) how this project is organised and why, questions like where do the settings live or what every variable in `.env` file is used for
35
37
- step by step explanation [how to add new endpoint](#how-to-add-new-endpoint), from creating new model, adding schemas and routes to migrating database and writting tests (it's always better to have it and optionally adopt it, than wasting time trying to figure out the best dev path)
36
38
37
-
38
39
## Quickstart
39
40
40
41
NOTE: you will need [docker](https://www.docker.com/get-started) and optional but recommended [poetry](https://python-poetry.org/docs/) installed!
@@ -66,7 +67,6 @@ pip install -r requirements.txt
66
67
67
68
### 1. DEVELOPMENT
68
69
69
-
70
70
since we wanna use uvicorn in development, create only postgres container using docker-compose.yml file like that:
71
71
72
72
```bash
@@ -100,7 +100,6 @@ The diffrence between development approach is that web server automatically runs
100
100
2.`FIRST_SUPER_USER_EMAIL` - first account email
101
101
3.`DEBUG` - when it's false, the `POSTGRES_SERVER` is set to `localhost` for development, so change it to `DEBUG=true` to use `db` postgres server.
102
102
103
-
104
103
### 3. PRODUCTION (https, own domain)
105
104
106
105
To make it available from https://your_domain.com on VM run
@@ -164,15 +163,15 @@ Plesae also note that to get no-test certificate, you should comment line `"--ce
164
163
165
164
## High level overview
166
165
167
-
This project strucutre is mostly based on the [official template](#https://github.com/tiangolo/full-stack-fastapi-postgresql) (but not only) which is really great but unfortunatly does not support Tortoise ORM and is... (too?) complicated. All the security or problematic stuff (`app/core/security.py` with `verify_password` function, login and token routes, JWT token schemas) are just copied from there, so you can be preety sure it will work as expected.
166
+
This project strucutre is mostly based on the [official template](#https://github.com/tiangolo/full-stack-fastapi-postgresql) (but not only) which is really great but unfortunatly does not support Tortoise ORM and is... (too?) complicated. All the security or problematic stuff (`app/core/security.py` with `verify_password` function, login and token routes, JWT token schemas) are just copied from there, so you can be pretty sure it will work as expected.
168
167
169
168
The main thougts are:
170
169
171
-
- There two sorts of settings, first one located in `.env` file for the ENTIRE project, and python-specific settings which lives in `app/core/config.py`, the file is based on pydantic solution (using dotenv lib). Why? Well, that's simple, this is due to [12factor methodology](https://12factor.net/), python-specific settings inherit from `.env` file, so this is the only place where you actually change something. If you have any problems understanding mentioned `config.py` file, just refer to [pydantic - settings management](https://pydantic-docs.helpmanual.io/usage/settings/), it's preety clear.
170
+
- There two sorts of settings, first one located in `.env` file for the ENTIRE project, and python-specific settings which lives in `app/core/config.py`, the file is based on pydantic solution (using dotenv lib). Why? Well, that's simple, this is due to [12factor methodology](https://12factor.net/), python-specific settings inherit from `.env` file, so this is the only place where you actually change something. If you have any problems understanding mentioned `config.py` file, just refer to [pydantic - settings management](https://pydantic-docs.helpmanual.io/usage/settings/), it's pretty clear.
172
171
173
172
- Models, crud, schemas, api routes, tests... it might be confusing how to actually ADD SOMETHING NEW here, but after following next section (learn by doing, step by step), it should be pretty easy
174
173
175
-
- Database-related stuff is very convinient, taken mostly from [Tortoise ORM](https://tortoise-orm.readthedocs.io/en/latest/index.html) docs and just *working*. There is `register_tortoise` function in `main.py`, `TORTOISE_ORM` variable in `app/core/config.py`. Please, be aware that if you don't run `initial_data.py` SOMEHOW (in development- you have to do it yourself, in debug/production it is handled by shell script `initial.sh`, which also runs tests and migrations), you won't be able to connect to database. `initial_data.py` is hearbly based on the same named file in **official template** mentioned earlier. It has two responsibilities, first is running `init` function from Tortoise to initialize connection, and the second - creating first superuser (defined in `.env`) if one doesn't yet exists.
174
+
- Database-related stuff is very convinient, taken mostly from [Tortoise ORM](https://tortoise-orm.readthedocs.io/en/latest/index.html) docs and just _working_. There is `register_tortoise` function in `main.py`, `TORTOISE_ORM` variable in `app/core/config.py`. Please, be aware that if you don't run `initial_data.py` SOMEHOW (in development- you have to do it yourself, in debug/production it is handled by shell script `initial.sh`, which also runs tests and migrations), you won't be able to connect to database. `initial_data.py` is hearbly based on the same named file in **official template** mentioned earlier. It has two responsibilities, first is running `init` function from Tortoise to initialize connection, and the second - creating first superuser (defined in `.env`) if one doesn't yet exists.
176
175
177
176
- Migrations are also provided by Tortiose (the tool is aerich), docs can be found [here in aerich repo](https://github.com/tortoise/aerich). The default migration (default user model) file is already included. After changes in models (e.g. new model `Cars`), just run `aerich migrate`, `aerich upgrade` and you are good to go.
178
177
@@ -287,7 +286,6 @@ dog = CRUDDog(Dog)
287
286
from .crud_dog import dog # type:ignore
288
287
```
289
288
290
-
291
289
8. Create `dogs.py` with endpoints in `app/api/routers` folder
0 commit comments