pallets-eco/flask-sqlalchemy

Adds SQLAlchemy support to Flask

4,307

stars

1,130

commits

Python

primary language

May 18, 2026

updated

flask-sqlalchemy.readthedocs.io
flask
flask-sqlalchemy
python
sqlalchemy
Browse cluster: Template engines and web frameworks

README

Flask-SQLAlchemy

Flask-SQLAlchemy is an extension for Flask that adds support for SQLAlchemy to your application. It aims to simplify using SQLAlchemy with Flask by providing useful defaults and extra helpers that make it easier to accomplish common tasks.

Pallets Community Ecosystem

[!IMPORTANT]
This project is part of the Pallets Community Ecosystem. Pallets is the open source organization that maintains Flask; Pallets-Eco enables community maintenance of Flask extensions. If you are interested in helping maintain this project, please reach out on the Pallets Discord server.

A Simple Example

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///example.sqlite"

class Base(DeclarativeBase):
  pass

db = SQLAlchemy(app, model_class=Base)

class User(db.Model):
    id: Mapped[int] = mapped_column(primary_key=True)
    username: Mapped[str] = mapped_column(unique=True)

with app.app_context():
    db.create_all()

    db.session.add(User(username="example"))
    db.session.commit()

    users = db.session.scalars(db.select(User))

Contributors

(top 30 of 103)

davidism

484 commits

mitsuhiko

127 commits

dependabot[bot]

75 commits

pallets-eco/flask-sqlalchemy

Adds SQLAlchemy support to Flask

4,307

stars

1,130

commits

Python

primary language

May 18, 2026

updated

flask-sqlalchemy.readthedocs.io
flask
flask-sqlalchemy
python
sqlalchemy
Browse cluster: Template engines and web frameworks

README

Flask-SQLAlchemy

Flask-SQLAlchemy is an extension for Flask that adds support for SQLAlchemy to your application. It aims to simplify using SQLAlchemy with Flask by providing useful defaults and extra helpers that make it easier to accomplish common tasks.

Pallets Community Ecosystem

[!IMPORTANT]
This project is part of the Pallets Community Ecosystem. Pallets is the open source organization that maintains Flask; Pallets-Eco enables community maintenance of Flask extensions. If you are interested in helping maintain this project, please reach out on the Pallets Discord server.

A Simple Example

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///example.sqlite"

class Base(DeclarativeBase):
  pass

db = SQLAlchemy(app, model_class=Base)

class User(db.Model):
    id: Mapped[int] = mapped_column(primary_key=True)
    username: Mapped[str] = mapped_column(unique=True)

with app.app_context():
    db.create_all()

    db.session.add(User(username="example"))
    db.session.commit()

    users = db.session.scalars(db.select(User))

Contributors

(top 30 of 103)

davidism

484 commits

mitsuhiko

127 commits

dependabot[bot]

75 commits

Languages

Python

100.0%