Skip to main content

Easily add live progress updates in Django using Django Channels.

Project description

🟢 Django LiveLoad

Django LiveLoad is a plug-and-play package for Django developers to show real-time progress updates on the frontend using WebSockets (powered by Django Channels and Daphne).

Ideal for long-running tasks like:

  • Data scraping
  • File processing
  • ML predictions
  • Background operations

✨ Built By

Sanat Jha - https://sanatjha.me



Demo Project: Live Load Django Demo on GitHub

🚀 Features

  • Live progress updates via WebSocket
  • Support for both status message and percentage complete
  • Works with Django templates or REST-based frontends
  • runlive command auto-starts Daphne server
  • Developer-friendly and production-ready

📦 Installation

✅ Step 1: Install the package

Install from PyPI (once published):

pip install django-liveload

⚙️ Django Project Setup

✅ Step 2: Add to INSTALLED_APPS

# settings.py

INSTALLED_APPS = [
    ...
    'channels',
    'liveload',
]

✅ Step 3: Configure ASGI

In settings.py:

ASGI_APPLICATION = 'your_project.routing.application' #Replace your_project name

Create routing.py in your project root (same level as settings.py):

# your_project/routing.py

from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application
from liveload.routing import websocket_urlpatterns

application = ProtocolTypeRouter({
    "http": get_asgi_application(),
    "websocket": URLRouter(websocket_urlpatterns),
})

✅ Step 4: Configure Channel Layer

For development (in-memory):

# settings.py

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels.layers.InMemoryChannelLayer"
    }
}

For production, use Redis:

pip install channels_redis
CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            "hosts": [("localhost", 6379)],
        },
    }
}

🔧 Usage

✅ Step 5: Use in your Django view

from liveload import ProgressTracker
import time

def long_task(request):
    tracker = ProgressTracker("mytask123")

    tracker.update(message="Starting...", percent=0)
    time.sleep(1)

    tracker.update(message="Step 1 complete", percent=30)
    time.sleep(1)

    tracker.update(percent=60)
    time.sleep(1)

    tracker.update(message="Finalizing...")
    time.sleep(1)

    tracker.update(message="✅ Done", percent=100)

    return render(request, "result.html")

You can send either message, percent, or both. At least one is required.


✅ Step 6: Add frontend WebSocket code

<script>
    const socket = new WebSocket(`ws://${window.location.host}/ws/progress/mytask123/`);
    socket.onmessage = function(event) {
        const data = JSON.parse(event.data);
        let text = '';
        if (data.percent !== undefined) text += `${data.percent}%`;
        if (data.status) text += (text ? ' - ' : '') + data.status;
        document.getElementById("progress-box").innerText = text;
    };
</script>

<div id="progress-box">Waiting...</div>

🧪 Running the Server

✅ Step 7: Use the custom runlive command

Instead of python manage.py runserver, use:

python manage.py runlive

This will:

  • Automatically start the Daphne ASGI server
  • Handle both HTTP and WebSocket traffic
  • Replace runserver in your dev workflow

🧠 Example Project Structure

your_project/
├── your_project/
│   ├── settings.py
│   ├── routing.py         ← Channels setup
│   └── ...
├── app/
│   └── views.py           ← Use ProgressTracker here
├── templates/
│   └── your_template.html ← Add WebSocket frontend here
└── manage.py

📬 Support

For issues and feature requests, open a GitHub issue or contact sanatjha4@gmail.com.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_liveload-0.1.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_liveload-0.1.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file django_liveload-0.1.1.tar.gz.

File metadata

  • Download URL: django_liveload-0.1.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for django_liveload-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9515d5e342345b9fb94a5ee189fd6517c883082b68d317f47ae082eb73b0a04d
MD5 a7d6457577475155670442c728d1f83d
BLAKE2b-256 64f6c904aeb886ffdd5668929c13cc44d46c0b66e86bfa4d0980ad3bbad8f68f

See more details on using hashes here.

File details

Details for the file django_liveload-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_liveload-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b045cb625ec2d74683e8441f3653f7a401b228e22e1e6ffa9934782ce1c77aa
MD5 0191ff500e82ed67e732932cde2f1c14
BLAKE2b-256 c8374f508d1e8c7bdccf12e2b7e201ee5815dc39da8c9bda549620f5b3cee892

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page