Skip to main content

A simple Django app to easily handle cleanup of old data (sessions, nonces, etc.)

Project description

Build Status

Django Datapurge

Simple app to help purging old data like sesions, nonces, logs etc.. It’s like clearsessions command but gives you possibility to purge anything. Simpliest way to use datapurge is to run management command (manually or via cron):

python purge

It’s easy to integrate datapurge with celery or kronos. Just wrap datapurge.actions.purge function with code corresponding to your task backend and run it the way you want.


  • Python (2.6, 2.7, 3.4, 3.5)
  • Django>=1.3.7


Install from PyPI using pip:

pip install django-datapurge

Or clone this repo:

git clone

Add 'datapurge' to your INSTALLED_APPS setting.



Add DATAPURGE_MODELS to your settings file and specify which models should be purged:

    'app_name.ModelName1': {
        # policy settings
    'app_name.ModelName2': {

Available purge policies

There are a few available policies for your use. Use what you find most convienient. Policy is guessed from set parameters provided.


Deletes all objects which expire_field datetime is older than


  • 'expire_field' - name of datetime field holding expiration date


    "sessions.Session": {
        "expire_field": "expire_date",


Deletes all objects which are older than specified lifetime


  • 'lifetime' - timedelta object specifying maximum lifetime of object
  • 'created_field' - name of datetime field holding object creation time


from timezone import timedelta

    "oauth_provider.Nonce": {
        "lifetime": timedelta(seconds=300),
        "created_field": "timestamp",


Deletes all objects from query returned by provided callable


  • 'callable' - function accepting model class and returning QuerySet


    "some_app.Log": {
        "callable": lambda model: model.objects.all(),

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-datapurge, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size django_datapurge-0.0.2-py2.py3-none-any.whl (13.4 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size django-datapurge-0.0.2.tar.gz (8.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page