Skip to main content

Add SQLAlchemy support to your Flask application.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_sqlalchemy-3.1.0.tar.gz (81.8 kB view details)

Uploaded Source

Built Distribution

flask_sqlalchemy-3.1.0-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file flask_sqlalchemy-3.1.0.tar.gz.

File metadata

  • Download URL: flask_sqlalchemy-3.1.0.tar.gz
  • Upload date:
  • Size: 81.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for flask_sqlalchemy-3.1.0.tar.gz
Algorithm Hash digest
SHA256 82bfd6663bbded03127f70697aaf2020d6bc4c0f43c5af4b1a142191903ae908
MD5 45dd8274ba662645b8eafe7108dcac47
BLAKE2b-256 0e50e777c8450585c57f71494e72fca1dd6f189c96d54701cdf21a7ae87d32a1

See more details on using hashes here.

File details

Details for the file flask_sqlalchemy-3.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_sqlalchemy-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f7060d00edb229ef2f2d98b414bc49fc1a4b26562af94cc1f090fc6c41bf41d
MD5 6840c2e3092647255a38808c505dc82d
BLAKE2b-256 f24341158f14ebf519f1f0edda4c0bd2ff983cdee8777d541621cc41c9192cec

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page