Skip to main content

dj-raincheck ☔️

Schedule functions to run after a request in Django without additional infrastructure.

Background tasks are great, but they are often overpowered for certain tasks and can require additional services. dj-raincheck is a simpler alternative. It will execute code after the request is complete, without the need for additional background tasks, daemons, or queues.

Installation 💻

uv add dj-raincheck

OR

pip install dj-raincheck

Usage 🧑‍🔧

  1. Add dj_raincheck to your INSTALLED_APPS in settings.py.
# settings.py

INSTALLED_APPS = (
    ...
    "dj_raincheck",
)
  1. Create a function that you want to run after the current request/response lifecycle.
# tasks.py

from django.core.mail import send_mail
from dj_raincheck import raincheck

@raincheck
def send_email(to: str, subject: str, body: str) -> None:
    send_mail(subject, body, 'me@example.com', [to])
  1. Queue the function in view code to be run after the current request/response lifecycle by calling its schedule method and passing in the necessary args or kwargs.
# views.py

from .tasks import send_email

# Function-based view example
def index(request):
    ...

    send_email.schedule('customer@example.com', 'Confirm Signup', body)

    return render(...)

# Class-based view example
class IndexView(View):
    def get(self, request, *args, **kwargs):
        ...
        
        send_email.schedule('customer@example.com', 'Confirm Signup', body)

        return render(...)

Settings ⚙️

RAINCHECK_RUN_ASYNC

True by default. Set to False to execute the jobs in the current thread as opposed to starting a new thread for each function.

NOTE: This is primarily for debugging purposes. When set to False, Django will wait for all scheduled functions to complete before closing the request, which can significantly increase response times.

RAINCHECK_IMMEDIATE

False by default. Set to True to execute scheduled functions immediately when schedule() is called, rather than queuing them to run after the response is completed.

NOTE: When set to True, functions will execute synchronously during the request/response cycle.

How does this work? ✨

  1. dj-raincheck attaches a callback to the request_finished signal provided by Django
  2. Using the @raincheck decorator adds a schedule function to the original function
  3. Calling schedule() queues the original function, args, and kwargs
  4. When the current request is complete, dj-raincheck pops all scheduled functions from the queue and starts a new thread for each one

Drawbacks 😢

dj-raincheck does not persist data to the disk or a database, so there are no guarantees if will be executed if the current request thread hangs or dies.

This is an explicit design trade-off to provide operational simplicity. dj-raincheck is useful for "fire-and-forget" tasks which, if they happen to fail, would be ok. If an application requires transactional guarantees, I recommend using django-tasks instead.

Supported Webservers 🕸️

  • ✅ Django development server
  • ✅ gunicorn
  • 🤷 uWSGI (might require enabling threads)

Please make a PR for other production webservers with your findings.

Inspiration 🙏

Metadata

Release files for dj-raincheck 0.5.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 dj-raincheck 0.5.0
File Size Uploaded Provenance
dj_raincheck-0.5.0.tar.gz 5.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dj-raincheck 0.5.0
File Interpreter ABI Platform
dj_raincheck-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.4 kB

Release files / dj_raincheck-0.5.0.tar.gz

Download URL dj_raincheck-0.5.0.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
aa48a47fa7c35806ceb4ba9c0b2e07c97e70d3ee6b6d36e531e156ba66a32804
BLAKE2b-256 checksum
How to use checksums
13141f5d3415c82d8bc298dfa9f9e236ca4458528e5f8a0cf399d6eab48564a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 31, 2025.

Transparency log

Release files / dj_raincheck-0.5.0-py3-none-any.whl

Download URL dj_raincheck-0.5.0-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9bb9513ee10fb5491b42877fd01b45e331d712e6a4cd89d9d4065d12d982469c
BLAKE2b-256 checksum
How to use checksums
27300db59d3217b7be75c82baeb5f4e61020323bdd09586d7f3d9ea965296952
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 31, 2025.

Transparency log

Security for dj-raincheck 0.5.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dj_raincheck-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 31, 2025.

Transparency log

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.

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