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.

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.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

flask_sqlalchemy_lite-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flask_sqlalchemy_lite-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.4

File hashes

Hashes for flask_sqlalchemy_lite-0.1.0.tar.gz
Algorithm Hash digest
SHA256 953173780a974940e6d0cfde1b1fe7097dae66dd7d18bc728f441847f6c48e09
MD5 a2620093a5dc94e5a2c9781e6be4e98b
BLAKE2b-256 4fe517bfe7ef0a575c82b87157d5ad67cdb73f5d124509d1be8180950bdfc358

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for flask_sqlalchemy_lite-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90ec1d5f4692b7369d88adcff1b9a8ca27baaff040bc4246c6ffee0af9421ce9
MD5 2d6c795b6b9258b3328aac61c170282d
BLAKE2b-256 24c8a6ae83d1d24c2795ce08f8504dbbe326ab2efb4ad32d78256f5fc9865275

See more details on using hashes here.

Provenance

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