Skip to main content

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

Project description

[![Build Status](https://travis-ci.org/swistakm/django-datapurge.png)](https://travis-ci.org/swistakm/django-datapurge)


# Django Datapurge

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

python manage.py 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.

# Requirements

* Python (2.6, 2.7)
* Django>=1.3.7

# Installation

Install from PyPI using pip:

pip install django-datapurge

Or clone this repo:

git clone git@github.com:swistakm/django-datapurge.git

Add `'datapurge'` to your `INSTALLED_APPS` setting.

INSTALLED_APPS = (
...
'datapurge',
)

# Configuration

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

DATAPURGE_MODELS = {
'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.


## ExpireFieldPolicy

Deletes all objects which `expire_field` datetime is older than `timezone.now()`.

Parameters:

* `'expire_field'` - name of datetime field holding expiration date

Example:

DATAPURGE_MODELS = {
"sessions.Session": {
"expire_field": "expire_date",
}
}

## LifetimePolicy

Deletes all objects which are older than specified `lifetime`

Parameters:

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

Example:

from timezone import timedelta

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

## CallablePolicy

Deletes all objects from query returned by provided callable

Parameters:

* `'callable'` - function accepting model class and returning QuerySet

Example:

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

Project details


Download files

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

Source Distribution

django-datapurge-0.0.1.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file django-datapurge-0.0.1.tar.gz.

File metadata

File hashes

Hashes for django-datapurge-0.0.1.tar.gz
Algorithm Hash digest
SHA256 012001ebc5420b52cde50ad7b62698683b1bd33d654025e739f8e6c3938e3666
MD5 42362ba573f5ed3528a82fb439a7ea99
BLAKE2b-256 04d4471380aea27b59e94b9226682ea719465c2330aab45ea2ce7e561fec6977

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page