Skip to main content

Integrate SQLAlchemy with Flask.

Project description

Flask-SQLAlchemy-Lite

Integrate SQLAlchemy with Flask. Use Flask's config to define SQLAlchemy database engines. Create SQLAlchemy ORM sessions that are cleaned up automatically after requests.

Intended to be a replacement for Flask-SQLAlchemy. Unlike the prior extension, this one does not attempt to manage the model base class, tables, metadata, or multiple binds for sessions. This makes the extension much simpler, letting the developer use standard SQLAlchemy instead.

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_lite import SQLAlchemy
from sqlalchemy import select
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column


class Base(DeclarativeBase):
    pass


class User(Base):
    __tablename__ = "user"
    id: Mapped[int] = mapped_column(primary_key=True)
    username: Mapped[str] = mapped_column(unique=True)


app = Flask(__name__)
app.config["SQLALCHEMY_ENGINES"] = {"default": "sqlite:///default.sqlite"}
db = SQLAlchemy(app)

with app.app_context():
    Base.metadata.create_all(db.engine)

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

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

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_lite-0.2.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_sqlalchemy_lite-0.2.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file flask_sqlalchemy_lite-0.2.0.tar.gz.

File metadata

  • Download URL: flask_sqlalchemy_lite-0.2.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for flask_sqlalchemy_lite-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e77d3a6a6fd7389c3c3d9f0cbc66f8583e5cf3899dd9f5225f064cc81982fc5b
MD5 a5b94e455819b98fcd3a8cb7eff4083c
BLAKE2b-256 c51ae042f3128c3affa06528ee4e68ce5eee6280d49a9c5dccc4cce89ee5303b

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_sqlalchemy_lite-0.2.0.tar.gz:

Publisher: publish.yaml on pallets-eco/flask-sqlalchemy-lite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_sqlalchemy_lite-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_sqlalchemy_lite-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 983eaeba30f8aca3e559798415fcff8ca1db77d8ed6b975edcb6b5bd8f114f77
MD5 a5113b47255f517544db18c7f87a21bc
BLAKE2b-256 f54912016a949863d334cf399a1328cf8e812f6645c8c38d6f68b5fa4466ddf4

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_sqlalchemy_lite-0.2.0-py3-none-any.whl:

Publisher: publish.yaml on pallets-eco/flask-sqlalchemy-lite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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