This release is a pre-release and may not be stable for production use.
django-dbtasks
Database backend and runner for Django tasks (new in 6.0).
django-dbtasks is tested on PostgreSQL, SQLite, and MySQL for versions of Python back to 3.12, including the free-threading builds.
Note when using SQLite it is recommended to set OPTIONS["transaction_mode"] = "IMMEDIATE" - see https://forum.djangoproject.com/t/sqlite-and-database-is-locked-error/26994 for more information.
Quickstart
Install the django-dbtasks package from PyPI, and configure your TASKS setting as follows:
TASKS = {
"default": {
"BACKEND": "dbtasks.backend.DatabaseBackend",
"OPTIONS": {
# Set this to True to execute tasks immediately (no need for a runner).
"immediate": False,
# Whether to send `task_enqueued`, `task_started`, and `task_finished`.
"signals": True,
# How long to retain ScheduledTasks in the database. Forever if not set.
"retain": datetime.timedelta(days=7),
# Tasks to run periodically.
"periodic": {
# Runs at 3:30am every Monday through Friday.
"myproject.tasks.maintenance": "30 3 * * 1-5",
},
},
},
}
Runner
django-dbtasks includes a dedicated taskrunner management command:
usage: manage.py taskrunner [-h] [-w WORKERS] [-i WORKER_ID] [--backend BACKEND]
[--delay DELAY] [--no-periodic]
It is also straightforward to run the runner in a thread of its own:
runner = Runner(workers=4, worker_id="in-process")
t = threading.Thread(target=runner.run)
t.start()
...
runner.stop()
t.join()
django-dbtasks itself is tested on free-threading builds of Python 3.13 and 3.14, but compatibility will depend on your database driver and other packages.
Periodic Tasks
As shown in the quickstart, periodic tasks are specified as a mapping in the backend OPTIONS under the periodic key. The keys of the mapping should be dotted paths to the tasks, and the values should either be a string in crontab format, or an instance of dbtasks.Periodic. Using a dbtasks.Periodic allows you to specify args and kwargs (as values or callables) that will be passed to the task, along with a custom retain duration.
Logging
Be sure to add a dbtasks logger to your LOGGING setting:
LOGGING = {
...
"loggers": {
"dbtasks": {
"handlers": ["console"],
"level": "INFO",
},
},
}
Testing
There is a RunnerTestCase that starts a runner for the duration of a test suite. See test_tasks.py for example usage.
Extras
django-dbtasks comes with a number of optional features for integration into various environments.
dbtasks.contrib.serve
This is a Django app you can add to INSTALLED_APPS to enable a serve management command that runs your site in a Granian server, with options to also start an integrated task runner. For instance, the following command will serve your site on 127.0.0.1:8000, start a runner, and reload your server (and tasks!) on code changes:
manage.py serve -k -r
Running an integrated task runner (with -k/--tasks) is not a great idea in production, but is excellent for development. Granian is a production-caliber server, so you can also use serve in production alongside a separate taskrunner command.
You can install the django-dbtasks[serve] extra to include Granian automatically.
uWSGI mule
You can run a uWSGI mule that starts a task runner by passing --mule=dbtasks.contrib.mule:taskrunner or specifying <mule>dbtasks.contrib.mule:taskrunner</mule> in your XML config.
Metadata
Release files for django-dbtasks 0.5.0.dev0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_dbtasks-0.5.0.dev0.tar.gz | 16.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_dbtasks-0.5.0.dev0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 40.5 kB
Release files / django_dbtasks-0.5.0.dev0.tar.gz
| Download URL | django_dbtasks-0.5.0.dev0.tar.gz |
|---|---|
| Size | 16.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14a5d2a2c68a9df3d6d50b7662e52ffa32c754c28cf69f0520ed1fb20b171392
|
|
BLAKE2b-256 checksum How to use checksums |
979b26a4286d5c04eeb7cef2693c09e77856280952a5d0f69a12c74b59dc22e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","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_dbtasks-0.5.0.dev0-py3-none-any.whl
| Download URL | django_dbtasks-0.5.0.dev0-py3-none-any.whl |
|---|---|
| Size | 24.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6b2743582583d351a96df0d767b808da67cfa536ed9b649e04c993a118a05f21
|
|
BLAKE2b-256 checksum How to use checksums |
b62ff30c7bdb68d16ffe52843102c3a013b314d2e74238edd16f45a78f50fcf6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","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-dbtasks 0.5.0.dev0
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.