Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pallets-eco/flask-sqlalchemy
Adds SQLAlchemy support to Flask
https://github.com/pallets-eco/flask-sqlalchemy
flask flask-sqlalchemy python sqlalchemy
Last synced: 6 days ago
JSON representation
Adds SQLAlchemy support to Flask
- Host: GitHub
- URL: https://github.com/pallets-eco/flask-sqlalchemy
- Owner: pallets-eco
- License: bsd-3-clause
- Created: 2010-06-01T15:01:50.000Z (over 14 years ago)
- Default Branch: main
- Last Pushed: 2024-06-01T13:03:14.000Z (5 months ago)
- Last Synced: 2024-06-03T15:32:56.363Z (5 months ago)
- Topics: flask, flask-sqlalchemy, python, sqlalchemy
- Language: Python
- Homepage: https://flask-sqlalchemy.palletsprojects.com
- Size: 1.5 MB
- Stars: 4,170
- Watchers: 113
- Forks: 897
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.rst
- Contributing: CONTRIBUTING.rst
- License: LICENSE.txt
Awesome Lists containing this project
- jimsghstars - pallets-eco/flask-sqlalchemy - Adds SQLAlchemy support to Flask (Python)
- best-of-web-python - GitHub - 1% open · ⏱️ 03.06.2024): (Flask Utilities)
README
# Flask-SQLAlchemy
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.[Flask]: https://flask.palletsprojects.com
[SQLAlchemy]: https://www.sqlalchemy.org## 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 import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_columnapp = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///example.sqlite"class Base(DeclarativeBase):
passdb = SQLAlchemy(app, model_class=Base)
class User(db.Model):
id: Mapped[int] = mapped_column(primary_key=True)
username: Mapped[str] = mapped_column(unique=True)with app.app_context():
db.create_all()db.session.add(User(username="example"))
db.session.commit()users = db.session.scalars(db.select(User))
```