Suave Deletes
Suave Deletes is a Python library that provides a soft delete functionality for SQLAlchemy models.
Soft deletes allow you to mark records as deleted without actually removing them from the database, making it easy to recover or audit data as needed.
Features
- Soft delete: Mark records as deleted without permanently removing them from the database.
- Automatic Query Filtering: Automatically filter out soft-deleted records from your queries.
- Customizable: Configure which models and fields use soft delete functionality.
- Simple Integration: Easily integrate with your existing SQLAlchemy models.
Installation
You can install Suave Deletes using pip:
pip install suave-deletes
Usage
To use Suave Deletes, simply import and apply it to your SQLAlchemy models.
Here is a basic example:
Configuration
from sqlalchemy import create_engine
from suave_deletes.session import create_suave_delete_session
def create_session():
engine = create_engine(
"Your database URI"
)
current_session = create_suave_delete_session(engine)
with current_session() as session:
yield session
Implementation
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
from suave_deletes.mixins import SuaveDeleteMixin
from suave_deletes.sessions import create_suave_delete_session
DeclarativeBase = declarative_base()
session = create_suave_delete_session()
class Base(DeclarativeBase, SuaveDeleteMixin):
deleted_at = mapped_column(DateTime, default=None)
class MyModel(Base):
__tablename__ = 'my_model'
id = Column(Integer, primary_key=True)
name = Column(String)
# Creates instance
obj = MyModel(name="example")
session.add(obj)
session.commit()
# Soft delete the instance
session.delete(obj)
session.commit()
# Query only non-deleted records
non_deleted_records = session.query(MyModel).all()
# Query all records, including soft deleted ones
all_records = session.query(MyModel).with_deleted_at().all()
Contributing
Contributions are welcome! If you find a bug or have a feature request, please open an issue on GitHub. If you would like to contribute code, please fork the repository and submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgments
Thanks to the SQLAlchemy community for their excellent library and documentation.
Metadata
Release files for suave-deletes 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| suave_deletes-0.1.5.tar.gz | 5.2 kB | Without provenance | Details for suave_deletes-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| suave_deletes-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for suave_deletes-0.1.5-py3-none-any.whl |
Total release size: 11.9 kB
Release files / suave_deletes-0.1.5.tar.gz
| Download URL | suave_deletes-0.1.5.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17c94b7c834b88180bd698685383d3ffdc804247d54fab3a34d04a943bbc31b1
|
|
BLAKE2b-256 checksum How to use checksums |
331b4e4f95af319df3e0cfeb2263ca3a567ee6655cb0c77c424555568ca0ccd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|
Release files / suave_deletes-0.1.5-py3-none-any.whl
| Download URL | suave_deletes-0.1.5-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c49335cb2ae42ac022b9442c058ecb3bfa583d75f7ea4bb2560c5e21931ad2c9
|
|
BLAKE2b-256 checksum How to use checksums |
35da1c1305d7765d0089914e892ef35148781017ec75b8bb91ad1ada37d7a301
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|
Security for suave-deletes 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.