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
-[x] Very minimal project structure yet ready for quick start building new apps
35
+
-[x] PostgreSQL 16 database under `asyncpg`, docker-compose.yml
36
+
-[x] Full [Alembic](https://alembic.sqlalchemy.org/en/latest/) migrations setup
34
37
-[x] Refresh token endpoint (not only access like in official template)
35
-
-[x] Database in docker-compose.yml and ready to go Dockerfile with [uvicorn](https://www.uvicorn.org/) webserver
36
-
-[x][Poetry](https://python-poetry.org/docs/) and Python 3.12 based
37
-
-[x]`pre-commit` hooks with [ruff](https://github.com/astral-sh/ruff)
38
+
-[x] Ready to go Dockerfile with [uvicorn](https://www.uvicorn.org/) webserver as an example
39
+
-[x][Poetry](https://python-poetry.org/docs/), `mypy`, `pre-commit` hooks with [ruff](https://github.com/astral-sh/ruff)
38
40
-[x]**Perfect** pytest asynchronous test setup with +40 tests and full coverage
39
41
40
42
<br>
41
43
42
-
_Check out also online example: https://minimal-fastapi-postgres-template.rafsaf.pl, it's 100% code used in template (docker image) with added domain and https only._
44
+
_Check out also online example: https://minimal-fastapi-postgres-template.rafsaf.pl, it's 100% code used in template (docker image) with added my domain and https only._
See [docs](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template).
57
55
58
-
```
59
-
60
-
### 2. Install dependecies with poetry or without it
56
+
### 2. Install dependecies with [Poetry](https://python-poetry.org/docs/)
61
57
62
58
```bash
63
-
cd project_name
59
+
cd your_project_name
60
+
64
61
### Poetry install (python3.12)
65
62
poetry install
66
-
67
-
### Optionally there is also `requirements-dev.txt` file
68
-
python3.12 -m venv venv
69
-
source venv/bin/activate
70
-
pip install -r requirements-dev.txt
71
63
```
72
64
73
65
Note, be sure to use `python3.12` with this template with either poetry or standard venv & pip, if you need to stick to some earlier python version, you should adapt it yourself (remove new versions specific syntax for example `str | int` for python < 3.10 or `tomllib` for python < 3.11)
74
66
75
-
### 3. Setup databases
67
+
### 3. Setup database and migrations
76
68
77
69
```bash
78
-
### Setup two databases
70
+
### Setup database
79
71
docker-compose up -d
80
72
81
-
### Alembic migrations upgrade and initial_data.py script
82
-
bash init.sh
73
+
### Run Alembic migrations
74
+
alembic upgrade head
83
75
```
84
76
85
77
### 4. Now you can run app
@@ -94,35 +86,27 @@ You should then use `git init` to initialize git repository and access OpenAPI s
94
86
95
87
### 5. Activate pre-commit
96
88
97
-
[pre-commit](https://pre-commit.com/) is de facto standard now for pre push activities like isort or black.
89
+
[pre-commit](https://pre-commit.com/) is de facto standard now for pre push activities like isort or black or its replacement ruff.
98
90
99
-
Refer to `.pre-commit-config.yaml` file to see my opinionated choices.
91
+
Refer to `.pre-commit-config.yaml` file to see my current opinionated choices.
100
92
101
93
```bash
102
94
# Install pre-commit
103
-
pre-commit install
95
+
pre-commit install --install-hooks
104
96
105
-
#First initialization and run on all files
97
+
#Run on all files
106
98
pre-commit run --all-files
107
99
```
108
100
109
101
### 6. Running tests
110
102
103
+
Note, it will create databases during and run tests in many processes by default, based on how many CPU are available.
104
+
105
+
For more details, see [Test setup](#test-setup).
106
+
111
107
```bash
112
-
#Note, it will use second database declared in docker-compose.yml, not default one
This template has by default included `Dockerfile` with [Uvicorn](https://www.uvicorn.org/) webserver, because it's simple and just for showcase purposes, with direct relation to FastAPI and great ease of configuration. You should be able to run container(s) (over :8000 port) and then need to setup the proxy, loadbalancer, with https enbaled, so the app stays behind it.
374
360
375
361
If you prefer other webservers for FastAPI, check out [Nginx Unit](https://unit.nginx.org/), [Daphne](https://github.com/django/daphne), [Hypercorn](https://pgjones.gitlab.io/hypercorn/index.html).
376
362
377
-
## Docs URL, CORS and Allowed Hosts
363
+
###Docs URL, CORS and Allowed Hosts
378
364
379
365
There are some **opinionated** default settings in `/app/main.py` for documentation, CORS and allowed hosts.
380
366
@@ -413,3 +399,5 @@ There are some **opinionated** default settings in `/app/main.py` for documentat
413
399
```
414
400
415
401
Prevents HTTP Host Headers attack, you shoud put here you server IP or (preferably) full domain under it's accessible like `example.com`. By default in .env there are two most popular records: `ALLOWED_HOSTS=["localhost", "127.0.0.1"]`
0 commit comments