Flask-AppBuilder

5.2.0 · active · verified Sun Apr 05

Flask-AppBuilder (FAB) is a simple and rapid application development framework built on top of Flask. It provides detailed security features, automatic CRUD generation for database models, Google Charts integration, and more. It is currently at version 5.2.0 and maintains an active release cadence with frequent updates and new features. [3, 4]

Warnings

Install

Imports

Quickstart

This quickstart sets up a minimal Flask-AppBuilder application with a simple SQLAlchemy model and a corresponding ModelView for CRUD operations. It initializes Flask, Flask-SQLAlchemy, and Flask-AppBuilder, then registers a basic view. You'll need to set a `FLASK_SECRET_KEY` environment variable or replace the placeholder. After running, use `flask fab create-admin` to set up an administrative user. [2, 8, 10, 12, 21]

import os
from flask import Flask
from flask_appbuilder import SQLA, AppBuilder, ModelView
from flask_appbuilder.models.sqla.interface import SQLAInterface

# Your App class
class MyUser(SQLA.Model):
    id = SQLA.Column(SQLA.Integer, primary_key=True)
    name = SQLA.Column(SQLA.String(50), unique=True, nullable=False)

    def __repr__(self):
        return self.name

# Instantiate Flask app
app = Flask(__name__)
app.config['SECRET_KEY'] = os.environ.get('FLASK_SECRET_KEY', 'a-very-secret-key-that-you-should-change')
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(os.path.dirname(__file__), 'app.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

# Instantiate SQLAlchemy and AppBuilder
db = SQLA(app)
appbuilder = AppBuilder(app, db.session)

# Create a ModelView for MyUser
class MyUserView(ModelView):
    datamodel = SQLAInterface(MyUser)
    list_columns = ['name']

# Add the view to AppBuilder
appbuilder.add_view(MyUserView, 'List My Users', icon='fa-users', category='My App')

# To run the app:
# $ export FLASK_APP=your_app_file_name.py
# $ flask fab create-admin (follow prompts to create an admin user)
# $ flask run
# Access at http://127.0.0.1:5000

view raw JSON →