Skip to content

Commit 1ca869c

Browse files
committed
readme and post_gen hook
1 parent 062d573 commit 1ca869c

File tree

4 files changed

+83
-6
lines changed

4 files changed

+83
-6
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,43 @@
1-
# under development...
1+
# Full featured FastAPI template, all boring and tedious things are covered
2+
3+
- SQLAlchemy using new 2.0 API + async queries
4+
- Postgresql database under `asyncpg`
5+
- Alembic migrations
6+
- Very minimal project structure yet ready for quick start building new api
7+
- Refresh token endpoint (not only access like in official template)
8+
- Two databases in docker-compose.yml (second for tests)
9+
- poetry
10+
- `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`
12+
13+
# Quickstart
14+
15+
```bash
16+
# You can install it globally
17+
pip install cookiecutter
18+
19+
# And cookiecutter this project :)
20+
cookiecutter https://github.com/rafsaf/minimal-fastapi-postgres-template
21+
22+
cd project_name
23+
# Databases
24+
docker-compose up -d
25+
# Alembic migrations upgrade and initial_data.py script
26+
bash init.sh
27+
# And this is it:
28+
uvicorn app.main:app
29+
```
30+
31+
tests:
32+
33+
```bash
34+
pytest
35+
# Note, it will use second database declared in docker-compose.yml, not default one like
36+
# in official template
37+
```
38+
39+
# About
40+
41+
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).
42+
43+
`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)

hooks/post_gen_project.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
Copy content from env template (autogenerated passwords etc)
3+
to .env which is gitignored, then remove template env file as it is redundant
4+
"""
5+
6+
from pathlib import Path
7+
8+
env_template_file = Path("./.env_template")
9+
env_file = Path("./.env")
10+
11+
env_file.write_text(env_template_file.read_text())
12+
env_template_file.unlink()

{{cookiecutter.project_name}}/.env.example

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
DEBUG=true
2-
SECRET_KEY="{{ random_ascii_string(50) }}"
2+
SECRET_KEY=string
33
ACCESS_TOKEN_EXPIRE_MINUTES=11520
44

55

66
VERSION="0.1.0"
7-
DESCRIPTION="{{ cookiecutter.project_name }}"
8-
PROJECT_NAME="{{ cookiecutter.project_name }}"
7+
DESCRIPTION=string
8+
PROJECT_NAME=string
99
API_STR=
1010
BACKEND_CORS_ORIGINS=http://localhost:3000,http://localhost:8001
1111

1212
POSTGRES_USER=postgres
13-
POSTGRES_PASSWORD="{{ random_ascii_string(50) }}"
13+
POSTGRES_PASSWORD=strong_password
1414
POSTGRES_SERVER=db
1515
POSTGRES_DB=db
1616
POSTGRES_PORT=4999
1717

1818
FIRST_SUPERUSER_EMAIL=example@example.com
19-
FIRST_SUPERUSER_PASSWORD="{{ random_ascii_string(20) }}"
19+
FIRST_SUPERUSER_PASSWORD=string_password
2020

2121
# letsencrypt ssl certificate contact email
2222
DEFAULT_FROM_EMAIL=my_personal_email@example.com
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
DEBUG=true
2+
SECRET_KEY="{{ random_ascii_string(50) }}"
3+
ACCESS_TOKEN_EXPIRE_MINUTES=11520
4+
5+
6+
VERSION="0.1.0"
7+
DESCRIPTION="{{ cookiecutter.project_name }}"
8+
PROJECT_NAME="{{ cookiecutter.project_name }}"
9+
API_STR=
10+
BACKEND_CORS_ORIGINS=http://localhost:3000,http://localhost:8001
11+
12+
POSTGRES_USER=postgres
13+
POSTGRES_PASSWORD="{{ random_ascii_string(50) }}"
14+
POSTGRES_SERVER=db
15+
POSTGRES_DB=db
16+
POSTGRES_PORT=4999
17+
18+
FIRST_SUPERUSER_EMAIL=example@example.com
19+
FIRST_SUPERUSER_PASSWORD="{{ random_ascii_string(20) }}"
20+
21+
# letsencrypt ssl certificate contact email
22+
DEFAULT_FROM_EMAIL=my_personal_email@example.com
23+
MAIN_DOMAIN=example.com

0 commit comments

Comments
 (0)