Skip to content

Instantly share code, notes, and snippets.

@jvmsangkal
Last active December 11, 2015 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvmsangkal/dfcf1cc0371f830256c1 to your computer and use it in GitHub Desktop.
Save jvmsangkal/dfcf1cc0371f830256c1 to your computer and use it in GitHub Desktop.

Python Flask Project Structure

Introduction

A boilerplate for REST APIs implement using python flask and pymysql. This project uses python3 and follows the (company's Python conventions)(https://github.com/anyTV/Python-conventions).

Running the application

  1. Download zip
  2. Extract to your project's folder
  3. Import database/schema.sql and database/seed.sql
mysql -uroot < database/schema.sql
mysql -uroot < database/seed.sql
  1. Install dependecies
python setup.py
  1. Update instance/config.py
  2. Run the app
python run.py

Project Structure

  • app
    • module-1
      • init.py
      • dispatch.py
    • module-n
      • init.py
      • dispatch.py
  • instance
    • env
      • development.py
      • production.py
      • staging.py
    • config.py
  • lib
    • database.py
    • error_handler.py
    • response.py
  • venv
  • setup.py
  • run.py

Request context

app - contains the files for the main app

module-n - contains the files for secific module (eg. user module)

module-n/dispatch.py - this file contains all the request context and will be responsible for the routing and setting request related functions.

module-n/init.py will contain all the functions native to the object. All functions and variables in this file most not be dependent on the request context. eg. the function "register" should be put in dispatch while the function "create user" is in init.py. The function register is responsible for getting all the clean data from the request.

instance - contains all the config files.

lib - contains all the core files

util - contains helper functions

Author

Freedom! Labs, any.TV Limited DBA Freedom!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment