All Projects โ†’ dimmg โ†’ Flusk

dimmg / Flusk

Boilerplate API on how to structure big Flask applications (includes SQLAlchemy, Docker, nginx)

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Flusk

Corser
CORS middleware for Node.js
Stars: โœญ 90 (-45.45%)
Mutual labels:  middleware, cors
Booklibrary
๐Ÿ“šSimple Book library application written on flask with SQLite database.
Stars: โœญ 98 (-40.61%)
Mutual labels:  sqlalchemy, flask
Flask Tutorial
่ฟ™ไธช้กน็›ฎๅทฒ็ปๅพˆไน…ๅพˆไน…ไบ†, ไธๆŽจ่็œ‹, ไธ่ฟ‡ๅ€’ๆ˜ฏๅฏไปฅ่ฟ›็พคๅจ้€ผๅจไธ€ไธ‹. ๐Ÿš— ไบคๆต็พค:630398887
Stars: โœญ 91 (-44.85%)
Mutual labels:  sqlalchemy, flask
Flask Whooshee
Customizable Flask - SQLAlchemy - Whoosh integration
Stars: โœญ 66 (-60%)
Mutual labels:  sqlalchemy, flask
Flask Graphene Sqlalchemy
A demo project for Flask + GraphQL (With Graphene & SQLAlchemy)
Stars: โœญ 117 (-29.09%)
Mutual labels:  sqlalchemy, flask
Ziggurat foundations
Framework agnostic set of sqlalchemy classes that make building applications that require permissions an easy task.
Stars: โœญ 67 (-59.39%)
Mutual labels:  sqlalchemy, flask
Flask movie site
็”จFlaskๆž„ๅปบไธ€ไธชๅพฎ็”ตๅฝฑ่ง†้ข‘็ฝ‘็ซ™
Stars: โœญ 97 (-41.21%)
Mutual labels:  sqlalchemy, flask
Flask Jwt Router
Flask JWT Router is a Python library that adds authorised routes to a Flask app.
Stars: โœญ 43 (-73.94%)
Mutual labels:  sqlalchemy, flask
Flask Graphene Sqlalchemy
โš—๏ธProject template to build a GraphQL API in Python
Stars: โœญ 109 (-33.94%)
Mutual labels:  sqlalchemy, flask
Gin Cors
Cross Origin Resource Sharing middleware for gin-gonic
Stars: โœญ 107 (-35.15%)
Mutual labels:  middleware, cors
Hobbit Core
A flask project generator.
Stars: โœญ 49 (-70.3%)
Mutual labels:  sqlalchemy, flask
Flask Msearch
Full text search for flask.
Stars: โœญ 164 (-0.61%)
Mutual labels:  sqlalchemy, flask
Python crawler
It's designed to be a simple, tiny, pratical python crawler using json and sqlite instead of mysql or mongdb. The destination website is Zhihu.com.
Stars: โœญ 45 (-72.73%)
Mutual labels:  sqlalchemy, flask
Indico
Indico - A feature-rich event management system, made @ CERN, the place where the Web was born.
Stars: โœญ 1,160 (+603.03%)
Mutual labels:  sqlalchemy, flask
Python Api Development Fundamentals
Develop a full-stack web application with Python and Flask
Stars: โœญ 44 (-73.33%)
Mutual labels:  sqlalchemy, flask
Markbj
ไธ€ไธชๅผ€ๆ”พ็š„็Ÿฅ่ฏ†็คพๅŒบ
Stars: โœญ 94 (-43.03%)
Mutual labels:  sqlalchemy, flask
Flask Bones
An example of a large scale Flask application using blueprints and extensions.
Stars: โœญ 849 (+414.55%)
Mutual labels:  sqlalchemy, flask
Ecache
๐Ÿ‘๐Ÿ‘ Integrate cache(redis) [flask etc.] with SQLAlchemy.
Stars: โœญ 28 (-83.03%)
Mutual labels:  sqlalchemy, flask
Weeklyreport
ๅŸบไบŽFlask็š„ๅผ€ๆบๅ‘จๆŠฅ็ณป็ปŸ๏ผŒๅฟซ้€Ÿdocker้ƒจ็ฝฒ
Stars: โœญ 102 (-38.18%)
Mutual labels:  sqlalchemy, flask
Tedivms Flask
Flask starter app with celery, bootstrap, and docker environment
Stars: โœญ 142 (-13.94%)
Mutual labels:  sqlalchemy, flask

Flusk

Flask - SQLAlchemy's declarative base - Docker - custom middleware.

Specifications

Application factory

Factories helps in creating many instances of the application. In this project, testing environment creates a new app instance whenever tests are ran.

Read More

Blueprints

Blueprints helps to split large application in small modular packages (one would say - similar to django apps).

Read More

Logic separation

The logic is splitted in the following layers:

  • backend (persistence layer) - where resides the code to read/write/delete records to disk or database
  • domain (domain layer) - where resides the bussines logic and external api integrations, i/o operations for a blueprint
  • views (presentation layer) - knows only about HTTP request and response. Its duty is to process a request and pass data to lower layers and to return responses.
  • models (data model layer) - where all blueprint models are defined
Middleware

The application tends to use middlewares instead of decorators or custom functions across the project.

  • application/json requests - ensures that all incoming requests are of application/json Content-Type
  • schema validation - validates the request payload against a JSON Schema
  • cors - allow cors requests for consumer apps
  • json exceptions - custom exception handler used to raise JSON exceptions
  • json responses - custom response handler used to return JSON objects
Extensions

The project tends to use the framework agnostic extensions over the flask ones, because they are usually wrappers and besides that, they may add additional functionality that you don't actually need (e.g. managers)

Docker

Ensures that the application you develop on local machine, behaves exactly in production.

Official Site

Directory layout

.
โ”œโ”€โ”€ core                                   # main codebase for the application
โ”‚   โ”œโ”€โ”€ api                                # API specific codebase
โ”‚   โ”‚   โ”œโ”€โ”€ common                         # shared logic used by the application
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ database.py                # common database logic
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ exceptions.py              # custom exception classes
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ middleware                 # application middleware
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py            # define application middlewares
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ request.py             # `request` related middleware
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ response.py            # `response` related middleware
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ serializers.py             # custom defined serializers
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ validation.py              # JSON schema validation logic
โ”‚   โ”‚   โ”œโ”€โ”€ conftest.py                    # pytest configurations and custom fixtures
โ”‚   โ”‚   โ”œโ”€โ”€ foss                           # flask blueprint
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ backend.py                 # logic related to database queries
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ domain.py                  # business logic and external integrations
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py                # blueprint config
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ models.py                  # blueprint models
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ tests                      # blueprint tests
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ test_unit.py           # unit tests
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ test_integration.py    # integration tests
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ test_models.py         # database models tests
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ views.py                   # logic related to request -> response
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py                    # app factory, blueprints, errorhandler and middleware registration
โ”‚   โ”‚   โ””โ”€โ”€ specifications                 # API specifications, RAML files and JSON schemas
โ”‚   โ”‚       โ””โ”€โ”€ schemas                    # JSON schemas folder
โ”‚   โ”‚           โ””โ”€โ”€ foss                   # schemas for a specific blueprint
โ”‚   โ”‚               โ”œโ”€โ”€ create_foss.json   # endpoint/view/route schema
โ”‚   โ”‚               โ””โ”€โ”€ update_foss.json   # endpoint/view/route schema
โ”‚   โ”œโ”€โ”€ Dockerfile                         # Dockerfile for the flask application
โ”‚   โ”œโ”€โ”€ requirements.txt                   # application dependencies
โ”‚   โ””โ”€โ”€ run.py                             # application creation and running
โ”œโ”€โ”€ docker-compose.yml                     # Dockerfiles manager
โ”œโ”€โ”€ Makefile                               # set of useful tasks (make `targets`)
โ”œโ”€โ”€ nginx                                  # nginx docker image related information
โ”‚   โ”œโ”€โ”€ Dockerfile                         # Dockerfile for the nginx web server
โ”‚   โ””โ”€โ”€ sites-enabled
โ”‚       โ””โ”€โ”€ nginx.conf                     # nginx configuration
โ””โ”€โ”€ README.md

Prerequisites

  • Python 3.5
  • Docker

Installation

Clone the repository

git clone https://github.com/dimmg/flusk.git

Build and run docker images

make dcompose-start

Run application

  • Development

    SSH into the running api container and start the development server

    docker exec -it flusk_api_1 bash
    python run.py
    

    By having a running server, execute

    docker inspect flusk_nginx_1
    

    where IPAddress it is the address of the running application.

  • Production

    Change docker-compose.yml file as follows:

    command:
        gunicorn -w 1 -b 0.0.0.0:5000 run:wsgi
        # tail -f /dev/null
    

    Rebuild the images via

    make dcompose-restart
    

    After rebuilding, the gunicorn wsgi server is running in background.

    To get the address of the running web server container run

    docker inspect flusk_nginx_1
    

Migrations

Migrations are done using the alembic migration tool.

Flow
  1. make changes to your models when needed
  2. create a migration
  3. check the migration script and modify it as needed
  4. apply the migration
Commands
  • create migration
make db-revision msg=<..message..>
  • apply the last migration
make db-upgrade
  • get the raw SQL for the last migration
make db-upgrade-sql

Note that these are the basic migration commands. To get the most from alembic, use the original $ alembic runner.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].