Skip to content

Repository files navigation

FastApi Template project

Useful links:

Installation

  • Clone the repository
git clone https://github.com/bandirom/fastapi-template.git
  • Install dependencies for local development
poetry install --extras dev
  • Create .env file
DATABASE_URI="postgresql+asyncpg://develop:develop@localhost/develop"
DEBUG=1
SECRET_KEY="someSecret"

Run project

  • Up only Postgresql and Redis in docker compose
docker-compose up -d db redis
  • Run project
python main.py

Use Alembic for migrations

  • Init alembic (Already done in the project)
alembic init -t async alembic
  • Check if Alembic works well
alembic current
  • Generate migrations
alembic revision --autogenerate -m "migration_name"
  • Migrate
alembic upgrade head

Work with async DB

  • Get users
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from db.models import User


async def get_users(session: AsyncSession):
  result = await session.execute(select(User))
  return result.scalars().all()

Docker & docker compose

Local development with docker compose

  • Edit .env file
DATABASE_URI=postgresql+asyncpg://develop:develop@db/develop
  • Build docker compose image
docker compose up -d --build

Production

  • Build image
docker build -t fastapi-project -f docker/Dockerfile .
  • (Optional) Run container
docker run --rm -it --env-file .env -p 8080:8080 --name fastapi-project fastapi-project

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages