Skip to content

Learning-Something/fastapi-sqlalchemy-mariadb

Repository files navigation

Todo List with SQLAlchemy and MariaDB

This is a simple todo list application using SQLAlchemy and MariaDB.

Quality Gate Status Coverage Reliability Rating Maintainability Rating Security Rating Code Smells Bugs Vulnerabilities Duplicated Lines (%)

Technologies

  • FastAPI - FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.
  • SQLAlchemy - SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL.
  • MariaDB - MariaDB is an open source relational database management system (RDBMS) based on MySQL.
  • SQLAlchemy AsyncIO + asyncmy - SQLAlchemy dialect for MySQL/MariaDB with asyncio support.
  • Alembic - Alembic is a lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python.
  • Docker - Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers.
  • New Relic - New Relic is a SaaS-based application performance management (APM) software platform that provides real-time insights into application performance and user experience.
  • Pytest - Pytest is a testing framework that makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries.
  • Pytest-asyncio - Pytest-asyncio is a plugin for pytest that allows you to write tests using asyncio coroutines.
  • Pre-commit - Pre-commit is a framework for managing and maintaining multi-language pre-commit hooks.
  • Python Decouple - Python Decouple is a straightforward solution for storing your settings in environment variables and retrieving them as Python objects.
  • Poetry - Poetry is a dependency manager for Python that allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

Requirements

Local Libraries (Optional)

Folder Structure

/.ignore # Local database files (ignored by git)
/src  # Source code
    /database  # Database connection, migrations and base model
    /exceptions  # Global exceptions
    /routes  # API routes
    /utils  # Utility functions
    /packages  # Domain and business logic
        /todo_list  # Todo list domain
            /models  # Todo list models
            /repositories  # Todo list repositories
            /services  # Todo list services
            /schemas  # Todo list schemas
            /exceptions  # Todo list exceptions
            /routes  # Todo list routes
            /tests  # Todo list unit tests
    app.py  # Main application
    settings.py  # Application settings
    conftest.py  # Pytest configuration
.editorconfig  # Editor configuration
.env  # Environment variables (ignored by git)
.env-example  # Environment variables example
.flake8  # Flake8 configuration
.gitignore  # Git ignore configuration
.pre-commit-config.yaml  # Pre-commit configuration
.pylintrc  # Pylint configuration
docker-compose.yml  # Docker compose configuration
Dockerfile  # Dockerfile
logging.ini  # Logging configuration
Makefile  # Makefile with common commands
mypy.ini  # Mypy configuration
newrelic.ini  # New Relic configuration
poetry.lock  # Poetry lock file
pyproject.toml  # Poetry configuration
README.md  # This file
start.sh  # Start script

Running the Application

Docker

  • Put your DOPPLER_TOKEN in the .env file
  • Run docker-compose up or make up to start the application

Local

  • Put your DOPPLER_TOKEN in the .env file
  • Run poetry install to install the dependencies
  • Run poetry run alembic upgrade head to run the database migrations
  • Run ./start.sh to start the application

Running the Tests

Docker

  • Run docker-compose up to start the application and MariaDB database
  • Run docker-compose exec todo_list tests to run the tests

Local

  • Run poetry install to install the dependencies
  • Run make migrate-upgrade to run the database migrations
  • Run doppler run -- pytest to run the tests

API Documentation

Production

Local

Adding new libraries

  • Run poetry add <library> to add a new library to production
  • Run poetry add <library> -G dev to add a new library to development