Registry / web-framework / flask-security-too

flask-security-too

JSON →
library5.8.1pypypiunverified

Flask-Security-Too quickly adds common security features like user registration, login, roles, and password management to your Flask application. Currently at version 5.8.0, it's the actively maintained successor to the original Flask-Security, frequently releasing updates with fixes and improvements. Despite the 'too' suffix in its PyPI name, it is now the official Flask-Security project under Pallets-Eco.

pip install flask-security-too Flask-SQLAlchemy
INSTALL
IMPORT
SIG · FLASK-SECURITY-TOO
F
flask-security-too
web-frameworkpythonv5.8.1
Install
4.9s avg
Import
1469ms
Disk
58MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.8.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
installs and imports cleanly · install 0.0s · import 1.502s · 58.5MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 4.9s · import 1.437s · 57MB
58MB installed
● package 58MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Security
from flask_security import Security
from flask_security_too import Security
Despite the PyPI package name `flask-security-too`, the Python module name is `flask_security`.
SQLAlchemySessionUserDatastore
from flask_security import SQLAlchemySessionUserDatastore
UserMixin
from flask_security import UserMixin
RoleMixin
from flask_security import RoleMixin

This quickstart sets up a basic Flask application with Flask-SQLAlchemy and Flask-Security-Too, enabling user registration and login functionality. It defines simple User and Role models and initializes the `Security` extension with a `SQLAlchemySessionUserDatastore`. Remember to set `FLASK_SECRET_KEY` and `SECURITY_PASSWORD_SALT` environment variables in production.

import os from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_security import Security, SQLAlchemySessionUserDatastore, UserMixin, RoleMixin # Configure Flask app app = Flask(__name__) app.config['DEBUG'] = True app.config['SECRET_KEY'] = os.environ.get('FLASK_SECRET_KEY', 'super-secret-dev-key') app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SECURITY_PASSWORD_SALT'] = os.environ.get('SECURITY_PASSWORD_SALT', 'some-random-salt') # Initialize SQLAlchemy db = SQLAlchemy(app) # Define User and Role models roles_users = db.Table( 'roles_users', db.Column('user_id', db.Integer, db.ForeignKey('user.id')), db.Column('role_id', db.Integer, db.ForeignKey('role.id')) ) class Role(db.Model, RoleMixin): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(255), unique=True) password = db.Column(db.String(255)) active = db.Column(db.Boolean()) fs_uniquifier = db.Column(db.String(64), unique=True, nullable=False) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic')) # Setup Flask-Security user_datastore = SQLAlchemySessionUserDatastore(db.session, User, Role) security = Security(app, user_datastore) @app.before_first_request def create_user(): db.create_all() if not user_datastore.find_user(email='test@example.com'): user_datastore.create_user(email='test@example.com', password='password') db.session.commit() @app.route('/') def home(): return 'Hello, Flask-Security-Too! Go to /login or /register.' if __name__ == '__main__': app.run()
Debug
Known issues
gotchaThe PyPI package name is `flask-security-too`, but the Python module to import from is `flask_security`. Attempting to import from `flask_security_too` will result in a `ModuleNotFoundError`.
fix
Always use `from flask_security import ...` for imports.
affects: All versions
breakingUpgrading from very old `Flask-Security` versions (pre-5.x) may require reviewing your password hashing configuration due to `Passlib` integration changes. Specifically, `SECURITY_PASSWORD_SCHEMES` might need to be adjusted.
fix
Consult the official Flask-Security-Too documentation regarding `SECURITY_PASSWORD_SCHEMES` and `Passlib` configuration for your specific upgrade path.
affects: < 5.0.0
gotchaWhen using Flask-SQLAlchemy version 3.x or higher, it is recommended to use `SQLAlchemySessionUserDatastore` instead of `SQLAlchemyUserDatastore`. The former uses `db.session` directly, aligning better with modern Flask-SQLAlchemy practices.
fix
Initialize your user datastore with `SQLAlchemySessionUserDatastore(db.session, User, Role)`.
affects: >= 5.0.0
gotchaEnsure `app.config['SECRET_KEY']` and `app.config['SECURITY_PASSWORD_SALT']` are set to long, random, and distinct strings, especially in production environments. Using simple or default values compromises security.
fix
Generate strong, unique keys for both `SECRET_KEY` and `SECURITY_PASSWORD_SALT` and manage them securely (e.g., via environment variables).
affects: All versions
Upgrade
Version history
5.8.1latest on PyPI · released May 21, 2026
Audit
Dependencies
FlaskrequiredCore Flask integration.
Flask-LoginrequiredUser session management (internal dependency).
PasslibrequiredPassword hashing and management.
Flask-SQLAlchemyoptionalRequired for using the SQLAlchemy user datastore.
Flask-MailoptionalRequired for email features like password reset and confirmation.
Agent activity
27 hits · last 30 days
node
24
Amazon
1
OpenAI (training)
1
Resources
flask-security-too — pip install flask-security-too · libregistry