Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rafsaf authored Jan 30, 2022
1 parent af6cee2 commit bd25047
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
<img src="https://img.shields.io/github/license/rafsaf/minimal-fastapi-postgres-template" alt="License">
</a>

:information_source: This repository contains two different templates to choose from.
## Minimal FastAPI Postgres Template

There are two templates to choose from, first **minimal template** 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.

Seconds one, **fastapi-users template** is similar to minimal in structure, but based on popular library [FastAPI Users](https://fastapi-users.github.io/fastapi-users/) and very powerful (yet it require using it for user accounts management).

:bangbang: | This repository contains two different templates to choose from.
:---: | :---

## Minimal async FastAPI + postgresql template

![template-fastapi-minimal-openapi-example](./docs/template-minimal-openapi-example.png)


- SQLAlchemy using new 2.0 API + async queries
- Postgresql database under `asyncpg`
Expand All @@ -22,27 +29,24 @@
- `pre-push.sh` script with poetry export, autoflake, black, isort and flake8
- Setup for async tests, one func test for token flow and very extensible `conftest.py`

![template-fastapi-minimal-openapi-example](./docs/template-minimal-openapi-example.png)

## Async FastAPI + postgresql template based on [fastapi-users](https://fastapi-users.github.io/fastapi-users/)

- Extensible base user model
- Ready-to-use register, login, reset password and verify e-mail routes
- Ready-to-use social OAuth2 login flow
- SQLAlchemy using new 2.0 API + async queries
- Postgresql database under `asyncpg`
- Alembic migrations
- Very minimal project structure yet ready for quick start building new api
- Refresh token endpoint (not only access like in official template)
- Two databases in docker-compose.yml (second one for tests)
- poetry
- `pre-push.sh` script with poetry export, autoflake, black, isort and flake8
- Setup for async tests, one func test for token flow and very extensible `conftest.py`

![template-fastapi-users-openapi-example](./docs/template-fastapi-users-openapi-example.png)

## What this repo is

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.

## What this repo is not

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).

## Quickstart

Expand All @@ -53,6 +57,9 @@ pip install cookiecutter
# And cookiecutter this project :)
cookiecutter https://github.com/rafsaf/minimal-fastapi-postgres-template

# decide if u want fastapi-users based template by
# changing "use_fastapi_users" in cookiecutter option to True, by default it is minimal template.

cd project_name
# Poetry install (and activate environment!)
poetry install
Expand All @@ -78,9 +85,11 @@ This project is heavily base on official template https://github.com/tiangolo/fu

`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).

## Step by step example
On January 30 I added another template to this repository, that is based on [FastAPI Users](https://fastapi-users.github.io/fastapi-users/) project. The main assumptions have not changed and project structure is very similar. What it gives is not buggy, extensible, tested Users accounts managing system. This is a lot, if your project needs to manage accounts, this is definitely better than minimal template.

## Step by step example for minimal template

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.
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. For second template, there may be some differences (imports etc.)

### 1. Add `HappyDog` model

Expand Down

0 comments on commit bd25047

Please sign in to comment.