A Django app for background task execution with multiple backends.
Project description
Django EZ Tasks
A lightweight Django app built on top of Django 6's Task framework that allows you to run threaded tasks in background, without a database or worker process.
Why?
For small projects and debugging.
Django's built-in ImmediateBackend is blocking your request and waits for the task to complete.
The DatabaseBackend from django-tasks requires a database connection and a separate worker process.
Installation
uv add git+https://github.com/al-eax/django_ez_tasks.git
# or
pip install git+https://github.com/al-eax/django_ez_tasks.git
Quick Start
1. Add to INSTALLED_APPS
In your Django settings.py:
INSTALLED_APPS = [
# ... other apps
"django_ez_tasks",
]
2. Configure Task Backends
Add your task configuration to settings.py:
TASKS = {
"default": {
"BACKEND": "django_ez_tasks.backends.ThreadedBackend",
}
}
Or use ThreadPoolBackend for a managed thread pool with configurable workers:
TASKS = {
"default": {
"BACKEND": "django_ez_tasks.backends.ThreadPoolBackend",
"OPTIONS": {
"max_workers": 4, # Number of threads in the pool
}
}
}
3. Usage
Define a task using the @task decorator:
from django.tasks import task, default_task_backend
from django.tasks.signals import task_enqueued, task_started, task_finished
# Define tasks
@task
def send_welcome_email(user_id: int) -> str:
"""Send a welcome email to a new user."""
user = User.objects.get(id=user_id)
# Send email logic here...
return f"Email sent to {user.email}"
# Connect signals (e.g., in your AppConfig.ready())
task_enqueued.connect(lambda sender, task_result, **kw: print(f"Task {task_result.id} enqueued"))
task_started.connect(lambda sender, task_result, **kw: print(f"Task {task_result.id} started"))
task_finished.connect(lambda sender, task_result, **kw: print(f"Task {task_result.id} finished: {task_result.status}, return value: {task_result.return_value}"))
# This returns immediately - the task runs in a background thread
result = send_welcome_email.enqueue(user_id=42)
task_id = result.id # Save the task ID for later
# Retrieve the result later from anywhere in your code
task_result = default_task_backend.get_result(task_id)
print(task_result.status) # e.g., TaskResultStatus.SUCCESSFUL
print(task_result.return_value) # e.g., "Email sent to user@example.com"
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues and questions, please visit the GitHub repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_ez_tasks-0.0.1.tar.gz.
File metadata
- Download URL: django_ez_tasks-0.0.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f175fa3576736ffdf0077c74f388c15708926812990163033d1625ab6cd8dc12
|
|
| MD5 |
5f545e6e31bfba853fbfcd2f0a7d8096
|
|
| BLAKE2b-256 |
84c0195648237839e343c0eb0dbbe68cc8b8d8f70673188a669075c873c12a73
|
File details
Details for the file django_ez_tasks-0.0.1-py3-none-any.whl.
File metadata
- Download URL: django_ez_tasks-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
718681b7edc366d27eb3b569a1ff5876e0018f3246e7dcfa653257391f3d0864
|
|
| MD5 |
258768e753c7dff536a33597529d481f
|
|
| BLAKE2b-256 |
f61ff3e98a9d574600d130c5b8e4177763930b6ad1843b66b055a46ec2a5ad06
|