Skip to main content

django-pgcron

django-pgcron is a Django library that enables you to manage scheduled cron jobs through Django's interface. It integrates with pg_cron, a Postgres extension that lets you schedule and automate database queries to run directly within PostgreSQL on a specified schedule, eliminating the need for Celery or another application-level job queuing library for simple database tasks.

Quick Start

Install django-pgcron and add pgcron to your INSTALLED_APPS setting:

INSTALLED_APPS = [
    ...
    "pgcron",
]

Jobs are intended to be scheduled in a jobs.py submodule of your app.

my_django_project/
│
├── my_app/
│   ├── __init__.py
│   ├── admin.py
│   ├── apps.py
│   ├── jobs.py <--- Add your jobs here
│   ├── migrations/
│   │   └── __init__.py
│   ├── models.py
│   ├── tests.py
│   ├── views.py
│   └── ...

Defining your jobs is as simple as decorating a function returning with @pgcron.job. Three types of jobs are supported: pgcron.Update, pgcron.Delete, and pgcron.SQLExpression.

Update

A pgcron.Update is an update statement on an ORM query.

import pgcron

@pgcron.job("0 0 1 1 *")
def my_job():
    return pgcron.Update(NameTestModel.objects.all().filter(name="test"), name="test2")

Delete

A pgcron.Delete is a delete statement on an ORM query.

import pgcron

@pgcron.job("0 0 1 1 *")
def my_job():
    return pgcron.Delete(NameTestModel.objects.all().filter(name="test"))

SQL Expressions

A pgcron.SQLExpression is a simple SQL expression to be executed by pgcron.

import pgcron

@pgcron.job("0 0 1 1 *")
def my_job():
    return pgcron.SQLExpression("INSERT INTO my_table (name) VALUES ('test');")

Syncing Jobs

Once you've defined your jobs, you can sync them to the database with the pgcron sync command.

python manage.py pgcron sync

This will register all of your current jobs, and drop any jobs that are no longer defined in your application. It's recommended to run this command as part of your application's deployment process alongside migrate.

Installation

Install django-pgcron with:

pip install django-pgcron

Installing pg_cron

In order to use django-pgcron, you must have pg_cron installed in your database.

For instructions on installing pg_cron, see the pg_cron documentation.

Compatibility

django-pgcron is compatible with Python 3.11 - 3.15, Django 5.0+, and Postgres 13 - 18. The minimum Postgres version also depends on Django: Django 5.2 and 6.0 require Postgres 14+, while Django 6.1 requires Postgres 15+.

Metadata

Release files for django-pgcron 0.2.0

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-pgcron 0.2.0
File Size Uploaded Provenance
django_pgcron-0.2.0.tar.gz 105.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-pgcron 0.2.0
File Interpreter ABI Platform
django_pgcron-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 119.4 kB

Release files / django_pgcron-0.2.0.tar.gz

Download URL django_pgcron-0.2.0.tar.gz
Size 105.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c476efda541c21900b203df032b277629f7db785c4c98639d72d090fcbfa2c94
BLAKE2b-256 checksum
How to use checksums
5feb784c427f6118b9cb58f6a5d122c074f2511e78799f4178610fbdae0c967a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / django_pgcron-0.2.0-py3-none-any.whl

Download URL django_pgcron-0.2.0-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
613fd3bd7f28b7cc01dabc31fefbdd1382caf61f87316982d4be52c2f8b4f70b
BLAKE2b-256 checksum
How to use checksums
5ac6ffcfe67611c056432061763c86e9f15d12908c619c22030ed52a8821a0c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for django-pgcron 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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