Flask-SQLAlchemySession2024
This is a fork of the excellent Flask-SQLAlchemySession package by Dimitris Theodorou, which has unfortunately gone unpatched for a few years.
Provides an SQLAlchemy scoped session that creates unique sessions per Flask request, following the guidelines documented at Using Custom Created Scopes.
TODO
- coverage
- docs
Usage
Initialize a flask_scoped_session as you would a
scoped_session, with the addition of a Flask
app. Then use the resulting session to query models:
from flask import Flask, abort, jsonify
from flask_sqlalchemy_session import flask_scoped_session
app = Flask(__name__)
session = flask_scoped_session(session_factory, app)
@app.route("/users/<int:user_id>")
def user(user_id):
user = session.query(User).get(user_id)
if user is None:
abort(404)
return flask.jsonify(**user.to_dict())
The current_session is also provided as a convenient accessor to the session
of the current request, in the same spirit of flask.request and
flask.current_app.
from flask_sqlalchemy_session import current_session
@app.route("/users/<int:user_id>")
def user(user_id):
user = current_session.query(User).get(user_id)
if user is None:
abort(404)
return flask.jsonify(**user.to_dict())
Tests
You can run the tests by invoking PYTHONPATH=. py.test tests/ in the repository root.
Metadata
Release files for Flask-SQLAlchemy-Session2024 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| Flask-SQLAlchemy-Session2024-3.0.0.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Flask_SQLAlchemy_Session2024-3.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.4 kB
Release files / Flask-SQLAlchemy-Session2024-3.0.0.tar.gz
| Download URL | Flask-SQLAlchemy-Session2024-3.0.0.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8166cb167abc9369f19d7b55ba7c375e4cc5229f4a777aa9a3d01fdf1bd98626
|
|
BLAKE2b-256 checksum How to use checksums |
8b790936e16a4025c451b5648bf446e52697d6dd748e8f07527c31e53a095839
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Release files / Flask_SQLAlchemy_Session2024-3.0.0-py3-none-any.whl
| Download URL | Flask_SQLAlchemy_Session2024-3.0.0-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
60e33535f7ec6418011cb9f99278d12880927b9834ed43d3812ba66bd8065072
|
|
BLAKE2b-256 checksum How to use checksums |
f41b2ab0a83a7580bcb31b1e4859722dca81257e96d8df73bc35f0517fc1f9b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|