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.1.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.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flask_sqlalchemy_lite-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 6de2f70c835a2c0a11264cbbc0cc33e7ed9732a52ee056781c5739e960213d2f
MD5 f587b8b1330a8022ce277ff6288d17fe
BLAKE2b-256 b7dc3f4c55cfc03e189e50b80843d5d3ff70c97711d924537b7a5ad8587cf7fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_sqlalchemy_lite-0.2.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_sqlalchemy_lite-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 93f1df6228389fdc60a0733353f8c1a18aaeaf03c8d6ab541bafdf2987c5e777
MD5 9de693ff456d658d2f3944db5678d5aa
BLAKE2b-256 20f3df9d508d4ed9657ae23d9e936ca2f2c0556742c032598e0d79f78e64646f

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_sqlalchemy_lite-0.2.1-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