Skip to content

Rmolimock/flask_api_boilerplate

Repository files navigation

Flask API Boilerplate

This is a boilerplate repo for a Flask API. I'm creating it to help me get started with new projects faster.

Features

  • Automatically connect to mysql database, given user-provided credentials
  • A base model for serializing, deserializing, and shared methods
  • A client model for application clients
  • A user model for identifying individual users
  • Automatically create tables in the database for client models
  • Flask-Migrate for database version control
  • CRUD routes for clients and users
  • Pytests for clients
  • Pytests for users
  • Pytests for shared methods
  • Make pytests scalable with TestBase

Requirements

  • Python 3.10
  • MySQL 8.0
  • Flask 2.0
  • Flask-Migrate 3.0
  • Flask-SQLAlchemy 3.0
  • PyMySQL 1.0
  • Inotify-tools

Installation

Clone the repo, install requirements, and create a .env file

  1. git clone https://github.com/Rmolimock/flask_api_boilerplate.git
  2. cd flask_api_boilerplate
  3. pip install -r requirements.txt
  4. Create a .env file with the following contents (to be added to mysql db once installed in step 9):
  • DB_NAME=
  • DB_USER=
  • DB_PASSWORD=
  • DB_HOST=
  • DB_PORT=
  • FLASK_APP=main.py
  • PYTHONPATH='.'

Optionally setup a test error alert window

  1. sudo apt-get install inotify-tools # for running run_pytest_on_save.sh
  2. sudo apt install zenity # for running run_pytest_on_save.sh
  3. chmod +x run_pytest_on_save.sh
  4. ./run_pytest_on_save.sh # in a separate terminal

Install MySQL

  1. sudo apt-get install mysql-server # if you don't have MySQL installed
  2. mysql -u root -p
  3. sudo mysql # to enter into the mysql shell, then within the shell:
  4. ALTER USER '[user from .env file - probably root]'@'localhost' IDENTIFIED by '[password from .env_file]'; FLUSH PRIVILEGES; CREATE DATABASE 'database name from .env file'; EXIT;

Setup database version control

  1. flask db init # if you don't have migrations folder, alembic.ini, or env.py yet
  2. flask db migrate
  3. flask db upgrade

Run the app

  1. FLASK_DEBUG=True flask run

temp to do list

  • delete authorization, before_request, and test files
  • create tests for authorization (which includes before_request functionality) prior to recreating it
  • allow tests to inform the structure of the flow of authorization
  • then parameterize the tests for different scenarios

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors