Flask_api_project_structure

screenshot of Flask_api_project_structure

Flask_api_project_structure

My take on writing flask restful apps

Overview

The Flask Project Structure is a boilerplate for writing Flask restful APIs. It provides a proper way to separate configurations in production, development, and testing environments. The boilerplate includes features such as SQL Alchemy for CRUD operations, an email service configuration, password and token authentication using Argon2 and PyJWT, and Pymongo functions for basic CRUD operations. By using this boilerplate, developers can easily get started with writing Flask APIs and microservices.

Features

  • Proper separation of configs in Production, Development, and Testing
  • SQL Alchemy with built-in CRUD operations
  • Configured email service
  • Password and Token authentication handled using Argon2 and PyJWT
  • Pymongo functions for basic CRUD operations

Installation

To run the Flask app for the first time:

Step 0: Clone the repository

git clone <link>
cd <dir> (or inside project workspaces if you want individual venvs)

Step 1: Create virtual environment

python -m venv <name>

Step 2: Start virtual environment

Windows: <name>\Scripts\activate
Linux: source <name>/bin/activate

Step 3: Install requirements

pip install -r requirements.txt

To run the Flask app:

flask run

Optional parameters:

  • -h 0.0.0.0: sets host to 0.0.0.0
  • -p 9876: sets port to 9876
  • --with-threads: use multi-threading
  • --help: more useful options

For database requirements:

  • For MySQL: install mysql and psycopg2
  • For MongoDB: install pymongo

Update requirements.txt if new packages are installed:

pip freeze > requirements.txt

Note: Do not update requirements.txt manually.

Summary

The Flask Project Structure is a boilerplate that provides a convenient way to organize and write Flask restful APIs. It includes features such as proper config separation, SQL Alchemy for CRUD operations, email service configuration, password and token authentication, and Pymongo functions for basic CRUD operations. The installation process is straightforward, with clear instructions on setting up a virtual environment and installing the necessary requirements. Overall, this boilerplate simplifies the development process for Flask APIs and microservices.