skillfed

sqlalchemy-easy-softdelete

Easily add soft-deletion to your SQLAlchemy Models.

sqlalchemy-easy-softdelete v0.9.1 174.4K downloads/30d#10,282 on PyPI73
Permissive license BSD-3-Clause Active released

What it is and what it does

sqlalchemy-easy-softdelete is a mixin generator that adds soft-deletion semantics to SQLAlchemy models without requiring schema changes or explicit WHERE clauses in every query. Instead of deleting records, you mark them with a timestamp (by default `deleted_at`), and the library installs a query hook that automatically filters out soft-deleted rows from all SELECT statements—both in direct queries and through model relationships. You generate a customized mixin class, apply it to your models, and gain `.delete()` and `.undelete()` methods plus automatic query rewriting.

The mixin is fully configurable: you can choose the field name, its type, whether to include delete/undelete methods, and which tables the hook should ignore. This approach preserves audit trails and referential integrity while keeping deleted data invisible by default—queries return only active records unless you explicitly pass `include_deleted=True` to override the filter.

Use it for:

  • Implement audit trails in business applications where deleted records must remain in the database for compliance or recovery.
  • Build multi-tenant systems where soft-deleted data must be excluded from user-facing queries but retained for administrative review.
  • Add undo/restore functionality to applications without requiring complex transaction rollback or backup restoration.
  • Maintain referential integrity in systems where cascading hard deletes would break historical reporting or linked records.
  • Simplify query logic by removing the need to manually add `WHERE deleted_at IS NULL` conditions throughout the codebase.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Adds soft-deletion support to SQLAlchemy models with automatic query filtering and customizable mixin generation.

Yes. The package is actively maintained, has no known vulnerabilities, carries a permissive license, and solves a common ORM problem with minimal friction. The single dependency on sqlalchemy and low install overhead make it a safe addition. Use it if your application needs soft-deletion semantics; skip it if you never need to preserve deleted records or audit trails.

Install

sqlalchemy-easy-softdelete on PyPI

pip

pip install sqlalchemy-easy-softdelete

uv

uv add sqlalchemy-easy-softdelete

poetry

poetry add sqlalchemy-easy-softdelete

Installing sqlalchemy-easy-softdelete

Before you install

Low install friction; single dependency on sqlalchemy. Actively maintained with recent releases and a stable codebase marked as Production/Stable.

License in practice

BSD-3-Clause permissive license allows commercial and private use with minimal restrictions.

Quickstart

pip install sqlalchemy-easy-softdelete

from sqlalchemy_easy_softdelete.mixin import generate_soft_delete_mixin_class
from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, Integer

class SoftDeleteMixin(generate_soft_delete_mixin_class()):
    pass

Base = declarative_base()

class Fruit(Base, SoftDeleteMixin):
    __tablename__ = "fruit"
    id = Column(Integer, primary_key=True)

# Soft-delete: session.query(Fruit).all() excludes deleted rows
fruit.delete()
# Include deleted: session.query(Fruit).execution_options(include_deleted=True).all()

Requires Python 3.10 or later; SQLAlchemy must be installed separately.

Verify before relying

  • Whether the automatic query rewriting works correctly with all SQLAlchemy relationship types and lazy-loading strategies.
  • Performance impact of the hook on large-scale queries or complex relationship chains.
  • Compatibility with SQLAlchemy's async session and asyncio workflows.

Package facts

License BSD-3-Clause (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 1 — sqlalchemy
Maintenance actively maintained — 59 days since the last release
Last repo commit
First released
Downloads 174,407/month — #10,282 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: sqlalchemy_easy_softdelete-0.9.1-py3-none-any.whl

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseNatural Language :: EnglishProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Typing :: Typed

Tags

sqlalchemy soft deletesoft deletion mixinlogical delete sqlalchemyexclude deleted records automaticallysoft-delete hooksqlalchemy deleted_at fieldautomatic query filtering deleted
soft-deleteaudit-trailorm-pattern

More Database packages

psycopg2-binary

psycopg2-binary is a PostgreSQL database…

copyleft · top 1,000 on PyPI

redis

Python client library for connecting to and…

permissive · top 1,000 on PyPI

ydb

YDB Python SDK is the official client library…

permissive · top 1,000 on PyPI

snowflake-connector-python

Connects Python applications to Snowflake data…

permissive · top 1,000 on PyPI

sqlparse

sqlparse tokenizes SQL text into a tree of…

permissive · top 1,000 on PyPI

dbt-adapters

Provides base adapter protocols and shared…

permissive · top 1,000 on PyPI

django-soft-delete

Adds soft deletion to Django models by marking…

permissive · top 15,000 on PyPI

django-safedelete

Provides soft-delete functionality for Django…

permissive · top 5,000 on PyPI

sqlalchemy-filters

Adds filtering, sorting, and pagination…

permissive · top 15,000 on PyPI

sqlalchemy-mixins

Provides Active Record-style mixins for…

permissive · top 15,000 on PyPI

SQLAlchemy-Continuum

SQLAlchemy-Continuum adds automatic versioning…

permissive · top 5,000 on PyPI

sqlalchemy-repr

Adds automatic, human-readable repr() output to…

unclear · top 15,000 on PyPI

sqlalchemy-serializer

Adds a `.to_dict()` method to SQLAlchemy model…

permissive · top 15,000 on PyPI

mock-alchemy

Provides mock helpers for SQLAlchemy sessions…

permissive · top 15,000 on PyPI

sqlalchemy-json

Provides mutation-tracked JSON column types for…

permissive · top 5,000 on PyPI

alchemy-mock

Provides mock helpers for SQLAlchemy sessions…

permissive · top 15,000 on PyPI