Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pallets-eco/flask-sqlalchemy-lite
Integrate SQLAlchemy with Flask.
https://github.com/pallets-eco/flask-sqlalchemy-lite
flask flask-sqlalchemy flask-sqlalchemy-lite pallets pallets-eco python sqlalchemy
Last synced: about 1 hour ago
JSON representation
Integrate SQLAlchemy with Flask.
- Host: GitHub
- URL: https://github.com/pallets-eco/flask-sqlalchemy-lite
- Owner: pallets-eco
- License: mit
- Created: 2024-06-07T18:52:35.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-11-10T00:18:28.000Z (about 2 months ago)
- Last Synced: 2024-12-18T08:10:05.177Z (7 days ago)
- Topics: flask, flask-sqlalchemy, flask-sqlalchemy-lite, pallets, pallets-eco, python, sqlalchemy
- Language: Python
- Homepage: https://flask-sqlalchemy-lite.readthedocs.io
- Size: 78.1 KB
- Stars: 36
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# 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.[SQLAlchemy]: https://sqlalchemy.org
[Flask]: https://flask.palletsprojects.com
[Flask-SQLAlchemy]: https://flask-sqlalchemy.readthedocs.io## 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][discord].
>
> [discord]: https://discord.gg/pallets## A Simple Example
```python
from flask import Flask
from flask_sqlalchemy_lite import SQLAlchemy
from sqlalchemy import select
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_columnclass Base(DeclarativeBase):
passclass 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))
```