This is a boilerplate repo for a Flask API. I'm creating it to help me get started with new projects faster.
- 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
- Python 3.10
- MySQL 8.0
- Flask 2.0
- Flask-Migrate 3.0
- Flask-SQLAlchemy 3.0
- PyMySQL 1.0
- Inotify-tools
- git clone https://github.com/Rmolimock/flask_api_boilerplate.git
- cd flask_api_boilerplate
- pip install -r requirements.txt
- 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='.'
- sudo apt-get install inotify-tools # for running run_pytest_on_save.sh
- sudo apt install zenity # for running run_pytest_on_save.sh
- chmod +x run_pytest_on_save.sh
- ./run_pytest_on_save.sh # in a separate terminal
- sudo apt-get install mysql-server # if you don't have MySQL installed
- mysql -u root -p
- sudo mysql # to enter into the mysql shell, then within the shell:
- 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;
- flask db init # if you don't have migrations folder, alembic.ini, or env.py yet
- flask db migrate
- flask db upgrade
- FLASK_DEBUG=True flask run
- 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