# django-celery-beat

> Database-backed Periodic Tasks.

- **URL**: https://www.freshcrate.ai/projects/django-celery-beat
- **Author**: Asif Saif Uddin
- **Category**: Databases
- **Latest version**: `2.9.0` (2026-04-21)
- **License**: BSD
- **Source**: https://github.com/celery/django-celery-beat
- **Language**: Python
- **GitHub**: 1,926 stars, 485 forks
- **Registry**: pypi (`django-celery-beat`)
- **Tags**: `beat`, `celery`, `database`, `django`, `periodic`, `pypi`, `task`

## Description

=====================================================================
 Database-backed Periodic Tasks
=====================================================================

|build-status| |coverage| |license| |wheel| |pyversion| |pyimp|

:Version: 2.8.1
:Web: http://django-celery-beat.readthedocs.io/
:Download: http://pypi.python.org/pypi/django-celery-beat
:Source: http://github.com/celery/django-celery-beat
:DeepWiki: |deepwiki|
:Keywords: django, celery, beat, periodic task, cron, scheduling

About
=====

This extension enables you to store the periodic task schedule in the
database.

The periodic tasks can be managed from the Django Admin interface, where you
can create, edit and delete periodic tasks and how often they should run.

Using the Extension
===================

Usage and installation instructions for this extension are available
from the `Celery documentation`_.

.. _`Celery documentation`:
    http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#using-custom-scheduler-classes

Important Warning about Time Zones
==================================

.. warning::
   If you change the Django ``TIME_ZONE`` setting your periodic task schedule
   will still be based on the old timezone.

   To fix that you would have to reset the "last run time" for each periodic task:

.. code-block:: Python

        >>> from django_celery_beat.models import PeriodicTask, PeriodicTasks
        >>> PeriodicTask.objects.all().update(last_run_at=None)
        >>> PeriodicTasks.update_changed()



.. note::
   This will reset the state as if the periodic tasks have never run before.


Models
======

- ``django_celery_beat.models.PeriodicTask``

This model defines a single periodic task to be run.

It must be associated with a schedule, which defines how often the task should
run.

- ``django_celery_beat.models.IntervalSchedule``

A schedule that runs at a specific interval (e.g. every 5 seconds).

- ``django_celery_beat.models.CrontabSchedule``

A schedule with fields like entries in cron:
``minute hour day-of-week day_of_month month_of_year``.

- ``django_celery_beat.models.PeriodicTasks``

This model is only used as an index to keep track of when the schedule has
changed.

Whenever you update a ``PeriodicTask`` a counter in this table is also
incremented, which tells the ``celery beat`` service to reload the schedule
from the database.

If you update periodic tasks in bulk, you will need to update the counter
manually:

.. code-block:: Python

        >>> from django_celery_beat.models import PeriodicTasks
        >>> PeriodicTasks.update_changed()

Example creating interval-based periodic task
---------------------------------------------

To create a periodic task executing at an interval you must first
create the interval object:

.. code-block:: Python

        >>> from django_celery_beat.models import PeriodicTask, IntervalSchedule

        # executes every 10 seconds.
        >>> schedule, created = IntervalSchedule.objects.get_or_create(
        ...     every=10,
        ...     period=IntervalSchedule.SECONDS,
        ... )

That's all the fields you need: a period type and the frequency.

You can choose between a specific set of periods:


- ``IntervalSchedule.DAYS``
- ``IntervalSchedule.HOURS``
- ``IntervalSchedule.MINUTES``
- ``IntervalSchedule.SECONDS``
- ``IntervalSchedule.MICROSECONDS``

.. note::
    If you have multiple periodic tasks executing every 10 seconds,
    then they should all point to the same schedule object.

There's also a "choices tuple" available should you need to present this
to the user:


.. code-block:: Python

        >>> IntervalSchedule.PERIOD_CHOICES


Now that we have defined the schedule object, we can create the periodic task
entry:

.. code-block:: Python

        >>> PeriodicTask.objects.create(
        ...     interval=schedule,                  # we created this above.
        ...     name='Importing contacts',          # simply describes this periodic task.
        ...     task='proj.tasks.import_contacts',  # name of task.
        ... )


Note that this is a very basic example, you can also specify the arguments
and keyword arguments used to execute the task, the ``queue`` to send it
to[*], and set an expiry time.

Here's an example specifying the arguments, note how JSON serialization is
required:

.. code-block:: Python

        >>> import json
        >>> from datetime import datetime, timedelta

        >>> PeriodicTask.objects.create(
        ...     interval=schedule,                  # we created this above.
        ...     name='Importing contacts',          # simply describes this periodic task.
        ...     task='proj.tasks.import_contacts',  # name of task.
        ...     args=json.dumps(['arg1', 'arg2']),
        ...     kwargs=json.dumps({
        ...        'be_careful': True,
        ...     }),
        ...     expires=datetime.utcnow() + timedelta(seconds=30)
        ... )


.. [*] you can also use low-level AMQP routing using the

## Recent releases

| Version | Date | Urgency | Changes |
| --- | --- | --- | --- |
| `2.9.0` | 2026-04-21 | Low | Imported from PyPI (2.9.0) |
| `v2.9.0` | 2026-02-28 | Low | ## What's Changed * Added DeepWiki to README by @Nusnus in https://github.com/celery/django-celery-beat/pull/893 * refactor: use in operator instead of regex operator in crontab query to fix mssql regression by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/900 * refactor: tzaware crontab is due method by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/899 * feat: enable translation to PeriodicTaskInline verbose name by @thalesbarbosab in https://github.c |
| `v2.9.0` | 2026-02-28 | Low | ## What's Changed * Added DeepWiki to README by @Nusnus in https://github.com/celery/django-celery-beat/pull/893 * refactor: use in operator instead of regex operator in crontab query to fix mssql regression by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/900 * refactor: tzaware crontab is due method by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/899 * feat: enable translation to PeriodicTaskInline verbose name by @thalesbarbosab in https://github.c |
| `v2.9.0` | 2026-02-28 | Low | ## What's Changed * Added DeepWiki to README by @Nusnus in https://github.com/celery/django-celery-beat/pull/893 * refactor: use in operator instead of regex operator in crontab query to fix mssql regression by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/900 * refactor: tzaware crontab is due method by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/899 * feat: enable translation to PeriodicTaskInline verbose name by @thalesbarbosab in https://github.c |
| `v2.9.0` | 2026-02-28 | Low | ## What's Changed * Added DeepWiki to README by @Nusnus in https://github.com/celery/django-celery-beat/pull/893 * refactor: use in operator instead of regex operator in crontab query to fix mssql regression by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/900 * refactor: tzaware crontab is due method by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/899 * feat: enable translation to PeriodicTaskInline verbose name by @thalesbarbosab in https://github.c |
| `v2.9.0` | 2026-02-28 | Low | ## What's Changed * Added DeepWiki to README by @Nusnus in https://github.com/celery/django-celery-beat/pull/893 * refactor: use in operator instead of regex operator in crontab query to fix mssql regression by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/900 * refactor: tzaware crontab is due method by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/899 * feat: enable translation to PeriodicTaskInline verbose name by @thalesbarbosab in https://github.c |
| `v2.9.0` | 2026-02-28 | Low | ## What's Changed * Added DeepWiki to README by @Nusnus in https://github.com/celery/django-celery-beat/pull/893 * refactor: use in operator instead of regex operator in crontab query to fix mssql regression by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/900 * refactor: tzaware crontab is due method by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/899 * feat: enable translation to PeriodicTaskInline verbose name by @thalesbarbosab in https://github.c |
| `v2.9.0` | 2026-02-28 | Low | ## What's Changed * Added DeepWiki to README by @Nusnus in https://github.com/celery/django-celery-beat/pull/893 * refactor: use in operator instead of regex operator in crontab query to fix mssql regression by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/900 * refactor: tzaware crontab is due method by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/899 * feat: enable translation to PeriodicTaskInline verbose name by @thalesbarbosab in https://github.c |
| `v2.9.0` | 2026-02-28 | Low | ## What's Changed * Added DeepWiki to README by @Nusnus in https://github.com/celery/django-celery-beat/pull/893 * refactor: use in operator instead of regex operator in crontab query to fix mssql regression by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/900 * refactor: tzaware crontab is due method by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/899 * feat: enable translation to PeriodicTaskInline verbose name by @thalesbarbosab in https://github.c |
| `v2.9.0` | 2026-02-28 | Low | ## What's Changed * Added DeepWiki to README by @Nusnus in https://github.com/celery/django-celery-beat/pull/893 * refactor: use in operator instead of regex operator in crontab query to fix mssql regression by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/900 * refactor: tzaware crontab is due method by @alirafiei75 in https://github.com/celery/django-celery-beat/pull/899 * feat: enable translation to PeriodicTaskInline verbose name by @thalesbarbosab in https://github.c |

## Citation

- HTML: https://www.freshcrate.ai/projects/django-celery-beat
- Markdown: https://www.freshcrate.ai/projects/django-celery-beat.md
- Dependencies JSON: https://www.freshcrate.ai/api/projects/django-celery-beat/deps

_Generated by freshcrate.ai. Indexes pypi releases for AI-agent ecosystem packages._
