Skip to content

Backend Development Setup

Vaishnavi Gupta edited this page Aug 22, 2022 · 8 revisions

Requirements

  • Python3.7 - Make sure you have a python3 environment setup with version 3.7.4.
  • Virtualenv - Make sure you install your packages locally in a virtual environment. After adding a packing to the project, make sure to use the following command.
pip freeze >requirements.txt
  • MySQL - Preferrably MySQL 5.7 database is used.
  • SQLAlchemy - An SQL ORM for utilizing the MySQL database.
  • Cmake - Can be installed by following the instructions provided here.
  • Sendinblue Account

Setup Instructions

  1. Create a database in MySQL.
CREATE DATABASE IF NOT EXISTS labellab;
  1. Go into the labellab-flask folder.
cd labellab-flask
  1. Now, create a .env file containing config variables along with the database connection string. Refer to the .envsample file for its contents.
export FLASK_APP="app.py"
export FLASK_ENV=""
export FLASK_CONFIG=""

export DEV_DATABASE_URL= "mysql+pymysql://" + username + ":" + password + "@" + host + "/labellab"   
export TEST_DATABASE_URL="mysql+pymysql://" + username + ":" + password + "@" + host + "/test_labellab"   
export DATABASE_URL=""  

export API_KEY=""
  1. Create a virtual environment in that folder. If virtualenv is not present on your system, install it first.
pip install virtualenv
virtualenv -p python3 venv

If you have more than one versions of python installed in your system, create virtual environment using Python3.7.4.

  • For Windows -
py -3.7 -m venv venv
  • For Linux/MacOS -
virtualenv -p /usr/bin/python3.7 venv
  1. Activate the virtual environment.
  • For Windows -
venv\Scripts\activate.bat
  • For Linux/MacOS -
source venv/bin/activate
  1. Install all project dependencies by using the following command.
pip install -r requirements.txt
  1. Upgrade your database using the migrations file
flask db upgrade

Note: It is preferred to undo the migrations before pulling the latest changes, if the latest changes have any changes in the migrations
or has a new migrations file and in order to create a new migartions file the command flask db migrate can be used.

Note: If faced by a directory missing issue do ensure that you have the labellab-flask directory in your PYTHONPATH environment variable.

Running the Application

The API can be started with the following command.

flask run

To connect using the mobile application, using this command instead.

flask run --host=0.0.0.0