An open API service indexing awesome lists of open source software.

https://github.com/amozebus/fastapi-beyond-crud-2

Template for API that uses PostgreSQL-database / Шаблон API, использующего базу данных PostgreSQL
https://github.com/amozebus/fastapi-beyond-crud-2

alembic fastapi fastapi-template postgresql python sqlmodel

Last synced: 7 months ago
JSON representation

Template for API that uses PostgreSQL-database / Шаблон API, использующего базу данных PostgreSQL

Awesome Lists containing this project

README

          

# FastAPI Beyond CRUD 2 (with PostgreSQL)

Code style: black

Template for API that uses [PostgreSQL](https://postgresql.org)-database. Written in [Python](https://python.org) with [FastAPI](https://fastapi.tiangolo.com), [asyncpg](https://github.com/MagicStack/asyncpg) as database client, [SQLModel](https://sqlmodel.tiangolo.com) as ORM

Included [Alembic](https://alembic.sqlalchemy.org) for database migrations

Users' passwords hashing with [BCrypt](https://en.wikipedia.org/wiki/Bcrypt) and users authorization with access [JWTs](https://jwt.io)

## How to run

1. Rename `.env.example` to `.env` and fill fields

* Fields:

```
DATABASE_URL (str): PostgreSQL-database URL

JWT_SECRET (str): secret for JWTs signature

ACCESS_TOKEN_EXPIRE (int): access JWTs expire time in seconds
```

2. Install dependencies:

```sh
pip install -r requirements.txt
```

3. Run database migrations:

```sh
alembic upgrade head
```

3. Run app:

```sh
python src/main.py
```

### Docker

2. Build Docker image:

```sh
docker build . --tag api
```

3. Run Docker image:

```sh
docker run -d api
```

4. Run database migrations:

```sh
docker exec {container id} alembic upgrade head
```