Giter Club home page Giter Club logo

fastapi-todo-rest's Introduction

fastapi-todo-rest

REST API backend boilerplate built with Python, FastAPI, and Celery. Inspired by tiangolo/full-stack-fastapi-postgresql and testdrivenio/fastapi-react.

The project is intended to be used as a template or a reference for creating new web services. The most interesting part is the tools and technologies that this project use. See the Features section below.

From the perspective of functional requirements the application is quite simple and offers the next functionality:

  • register a user and send him a welcome e-mail in background, update profile, delete profile
  • login a user
  • create a todo item providing subject and optional deadline, delete a todo item
  • edit a todo item by changing subject, deadline or visibility (e.g. move to archive)
  • resolve/reopen a todo item
  • periodically check for todo items that passed the deadline and mark them as overdue with e-mail notification
  • periodically check for todo items that were resolved or overdue more than 24h ago and archive them

Tools and technologies used

  • Docker and Docker Compose
    • using healthchecks as readiness checks
    • reusing services definitions in Compose via extends
  • vscode Dev Containers for the best developer experience
  • GitHub Actions to run linters and tests on a pull-request
  • git pre-commit hook that runs linters
  • Python, Poetry
  • FastAPI, Pydantic
  • JWT token authentication
  • PostgreSQL and SQLAlchemy
    • alembic migrations
    • models with create_time and update_time timestamps that are being set automatically
    • using partial indices for the best performance and the smallest overhead
  • Celery
    • scheduling background tasks directly from an API path operation's code
    • running periodic background tasks with a certain schedule
    • backed by RabbitMQ
    • using Flower to be able to monitor Celery tasks
  • Pytest
    • tests are run against a separate isolated test DB
    • initial DB state is declared in a database seeding script
    • test data with either specific or faked (with Faker) fields is being created using factories
  • linters and static analysis tools
    • black for the code style checks
    • isort for the imports order check
    • Flake8 for errors, unused code, code style, and cyclomatic complexity checks
    • mypy to do the type checking
  • code autoformatting and cleaning
    • autoflake to remove unused imports and unused variables
    • black to autoformat the code to conform to the PEP 8
    • isort to sort imports
  • MailHog for e-mails testing

Prerequisites (dependencies)

  • Docker ^23.0
  • Docker Compose plugin ^2.17

Before you start

โš ๏ธ Make sure you've created a .env file from the .env.example template:

cp .env.example .env

and reviewed variables values in the .env file replacing _CHANGE_THIS_ placeholders with appropriate values.

How to start in vscode

The project was mainly configured to be developed in vscode. It is still available to be run simply with a CLI command without the vscode (see below).

The vscode's Dev Containers feature is used in order to reach a full integration of the IDE with the application's dockerized Python environment. That gives a decent developer experience (DX) working with the application's source code: code completion, code navigation etc.

In order to start the application and run vscode inside the application's container do the following:

  1. in vscode open the project's directory
  2. hit Ctrl+Shift+P
  3. paste remote-containers.reopenInContainer
  4. hit Enter

After application starts apply database migrations to initialize the database:

alembic upgrade head

How to start without vscode

If you simply want to spin up the application or if the vscode is not an option for you, just run:

docker compose up --detach --build --wait

After application starts apply database migrations to initialize the database:

docker compose exec api alembic upgrade head

OpenAPI docs

Out of the box FastAPI provides autogeneration of an OpenAPI documentation for your REST API.

Navigate to http://localhost:8000/docs.

OpenAPI docs

MailHog web UI

MailHog is an email testing tool for developers. It mimics sending a real email and allows you to see sent emails in your browser.

Navigate to http://localhost:8025/.

MailHog

Flower web UI

Flower is a web based tool for monitoring and administrating Celery clusters. Intended to be used in the project to debug Celery tasks.

Navigate to http://localhost:5555/. Protected with basic HTTP authentication. User and password are being set via FLOWER_USER and FLOWER_PASSWORD environment variables in the .env file.

Flower

Day-to-day tasks cheat sheet

Navigate to application/README.md to see frequently used commands cheat sheet.

fastapi-todo-rest's People

Contributors

dependabot[bot] avatar golubev avatar stacksharebot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

digitib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.