Skip to main content

django-realtime-chat

Plugin Django de chat temps réel via WebSocket (Django Channels + JWT).

Installation

pip install django-realtime-chat

Configuration rapide

1. settings.py

INSTALLED_APPS = [
    ...
    "channels",
    "rest_framework",
    "django_realtime_chat",
]

# Django Channels
ASGI_APPLICATION = "monprojet.asgi.application"

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

2. urls.py du projet

from django.urls import path, include

urlpatterns = [
    ...
    path("chat/", include("django_realtime_chat.urls")),
]

3. asgi.py du projet

import os
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.auth import AuthMiddlewareStack
from django_realtime_chat.routing import websocket_urlpatterns

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "monprojet.settings")

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

Authentification JWT : passez ?token=<access_token> dans l'URL WebSocket pour utiliser le middleware JWT fourni à la place de AuthMiddlewareStack.

4. Migrations

python manage.py migrate

URLs disponibles

URL Nom Description
GET /chat/ django_realtime_chat:chat_home Interface principale
GET /chat/start/<user_id>/ django_realtime_chat:start_conversation Démarre une conversation
GET /chat/history/<conv_id>/ django_realtime_chat:message_history Historique JSON
POST /chat/upload/ django_realtime_chat:file_upload Upload de fichier
GET /chat/users/ django_realtime_chat:user_list Liste des utilisateurs JSON

WebSocket

ws://<host>/ws/chat/

Payload envoyé par le client :

{ "message": "Bonjour !", "receiver_id": 42 }

Payload reçu :

{
  "message": "Bonjour !",
  "sender_id": 1,
  "sender_username": "alice",
  "conversation_id": 7,
  "message_id": 123,
  "created_at": "2025-04-06T10:30:00.000Z"
}

Metadata

Release files for django-realtime-chat 2.0.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-realtime-chat 2.0.0
File Size Uploaded Provenance Actions
django_realtime_chat-2.0.0.tar.gz 47.9 kB Without provenance Details for django_realtime_chat-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-realtime-chat 2.0.0
File Interpreter ABI Platform Actions
django_realtime_chat-2.0.0-py3-none-any.whl Python 3 none any Details for django_realtime_chat-2.0.0-py3-none-any.whl

Total release size: 97.3 kB

Release files / django_realtime_chat-2.0.0.tar.gz

Download URL django_realtime_chat-2.0.0.tar.gz
Size 47.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f605344658cb93cffd6fea23911af78f3270a257664af3435c3fd6d86cfdf2f9
BLAKE2b-256 checksum
How to use checksums
172c037bece281b84f863bd84ddecf32bf91e4b823496f5a50b1b23a2840d96a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / django_realtime_chat-2.0.0-py3-none-any.whl

Download URL django_realtime_chat-2.0.0-py3-none-any.whl
Size 49.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fcf6b12c09ac628526eb659f011c96a3bfaeb717d0365dc47277f8e458ef1dae
BLAKE2b-256 checksum
How to use checksums
d79f7852406b1499d312d91a87ef9e70a44d7d6da8aea9bb838e85f7ac16a2c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Security for django-realtime-chat 2.0.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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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