Use SQLAlchemy in a Pythonic way.
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
flask-sqlalchemy-crud
English | 中文
A lightweight CRUD + transaction helper for SQLAlchemy (Flask glue can be added via extensions):
- Context-managed CRUD with nested savepoints:
with CRUD(Model) as crud: - Function-level transactions via
@CRUD.transaction()with join semantics - Configurable error policy (
error_policy="raise"|"status_only") and pluggable logger - Type-friendly
CRUDQuerywrapper for common chainable operations
Install
pip install flask-sqlalchemy-crud
# or
pip install -e .
Requires Python 3.11+ with sqlalchemy>=1.4 (optional Flask integration can be added separately).
Quick Start (pure SQLAlchemy)
from sqlalchemy import String, Integer, create_engine
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, sessionmaker
from flask_sqlalchemy_crud import CRUD
engine = create_engine("sqlite:///./crud_example.db", echo=False)
SessionLocal = sessionmaker(bind=engine, expire_on_commit=False)
class Base(DeclarativeBase):
pass
class User(Base):
__tablename__ = "example_user"
id: Mapped[int] = mapped_column(Integer, primary_key=True)
email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False)
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
CRUD.configure(session_provider=SessionLocal, error_policy="raise")
with CRUD(User) as crud:
user = crud.add(email="demo@example.com")
print("created", user)
with CRUD(User, email="demo@example.com") as crud:
print("fetched", crud.first())
Function-Level Transactions
from flask_sqlalchemy_crud import CRUD
CRUD.configure(session_provider=SessionLocal, error_policy="raise")
@CRUD.transaction(error_policy="raise")
def create_two_users():
with CRUD(User) as crud1:
crud1.add(email="a@example.com")
with CRUD(User) as crud2:
crud2.add(email="b@example.com")
create_two_users()
- The outermost call commits or rolls back; inner CRUD contexts only mark status when exceptions occur.
- With
error_policy="status_only", SQLAlchemyError is rolled back and caught; checkcrud.status/crud.errorinstead.
Docs & Examples
- Full example:
docs/examples/basic_crud.py - Transaction refactor notes/TODO:
docs/crud_refactor_todo.md - Typing directions:
docs/todo.md
Testing
- Provide a DB URI via env or
.env:TEST_DB=sqlite:///./test.db(or another driver). - Install test deps, then:
pytest -q
Notes
- SQLAlchemy-first; optional Flask integration can be layered via extensions.
- Always call
CRUD.configure(session_provider=...)before using CRUD instances.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_sqlalchemy_crud-0.1.0.tar.gz.
File metadata
- Download URL: flask_sqlalchemy_crud-0.1.0.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e606573608051ac1296349f77a41aee3ef21e3f00972bd83e64230cbefa6b4ef
|
|
| MD5 |
bfc6448c233a082eb6756732a5148a23
|
|
| BLAKE2b-256 |
54586db75bd38ef30193180d1032ca12f5fcc8e8592562eb21dde466650454ac
|
Provenance
The following attestation bundles were made for flask_sqlalchemy_crud-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on ZM-Kimu/flask_sqlalchemy_crud
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flask_sqlalchemy_crud-0.1.0.tar.gz -
Subject digest:
e606573608051ac1296349f77a41aee3ef21e3f00972bd83e64230cbefa6b4ef - Sigstore transparency entry: 768147816
- Sigstore integration time:
-
Permalink:
ZM-Kimu/flask_sqlalchemy_crud@26d7e7c7c68747942164b94f21fc50fabefa01ad -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ZM-Kimu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@26d7e7c7c68747942164b94f21fc50fabefa01ad -
Trigger Event:
push
-
Statement type:
File details
Details for the file flask_sqlalchemy_crud-0.1.0-py3-none-any.whl.
File metadata
- Download URL: flask_sqlalchemy_crud-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc953273f3c9973ddf0ef9d19cf12200c55a4cc2a65ae9c8c6bbb98120280b48
|
|
| MD5 |
bfda35c82b3fa871643906fff56dcf74
|
|
| BLAKE2b-256 |
cb4c476fcb0cfe9e4eced5d329e5ae924771951051e600e33d979ab94b4d1a31
|
Provenance
The following attestation bundles were made for flask_sqlalchemy_crud-0.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on ZM-Kimu/flask_sqlalchemy_crud
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flask_sqlalchemy_crud-0.1.0-py3-none-any.whl -
Subject digest:
cc953273f3c9973ddf0ef9d19cf12200c55a4cc2a65ae9c8c6bbb98120280b48 - Sigstore transparency entry: 768147819
- Sigstore integration time:
-
Permalink:
ZM-Kimu/flask_sqlalchemy_crud@26d7e7c7c68747942164b94f21fc50fabefa01ad -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ZM-Kimu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@26d7e7c7c68747942164b94f21fc50fabefa01ad -
Trigger Event:
push
-
Statement type: