Skip to content

Sparrow0hawk/flask-sqlalchemy

This branch is 50 commits behind pallets-eco/flask-sqlalchemy:main.

Folders and files

NameName
Last commit message
Last commit date
Dec 1, 2023
Mar 18, 2011
Aug 25, 2023
Sep 9, 2023
Jan 15, 2024
Jan 15, 2024
Sep 10, 2023
May 25, 2020
Jun 9, 2023
Jun 9, 2023
Jan 15, 2024
Sep 11, 2023
Nov 5, 2023
May 31, 2019
Jun 20, 2023
Apr 18, 2019
Aug 22, 2023
Sep 11, 2023
Sep 11, 2023

Repository files navigation

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.

Installing

Install and update using pip:

$ pip install -U Flask-SQLAlchemy

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(db.Integer, primary_key=True)
    username: Mapped[str] = mapped_column(db.String, unique=True, nullable=False)

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

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

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

Contributing

For guidance on setting up a development environment and how to make a contribution to Flask-SQLAlchemy, see the contributing guidelines.

Donate

The Pallets organization develops and supports Flask-SQLAlchemy and other popular packages. In order to grow the community of contributors and users, and allow the maintainers to devote more time to the projects, please donate today.

Links

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%