Skip to main content

Build Status

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, 3.4, 3.5)

  • 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(),
    }

Release files for django-datapurge 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-datapurge 0.0.2
File Size Uploaded
django-datapurge-0.0.2.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-datapurge 0.0.2
File Interpreter ABI Platform
django_datapurge-0.0.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 21.3 kB

Release files / django-datapurge-0.0.2.tar.gz

Download URL django-datapurge-0.0.2.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f6ca5512abfe1f183028ee6f6bdaa15c3729c4c77fbffb803871e98b41fffb5e
BLAKE2b-256 checksum
How to use checksums
79818fc41150f9007ebb157dce68aca022dfc39cd0adfc34cc1afee09d64ca65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_datapurge-0.0.2-py2.py3-none-any.whl

Download URL django_datapurge-0.0.2-py2.py3-none-any.whl
Size 13.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ad41df6319f18e9fd4d06c1c33f240af92ad3099f938fbcfb652eb8d8815efdf
BLAKE2b-256 checksum
How to use checksums
fcc6445768996faeb012bfa135cdbf0fd893c935bed3b8b086a59e653d3a427b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page