Skip to main content

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

Project description

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"
}

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_realtime_chat-1.3.7.tar.gz (50.9 kB view details)

Uploaded Source

Built Distribution

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

django_realtime_chat-1.3.7-py3-none-any.whl (58.0 kB view details)

Uploaded Python 3

File details

Details for the file django_realtime_chat-1.3.7.tar.gz.

File metadata

  • Download URL: django_realtime_chat-1.3.7.tar.gz
  • Upload date:
  • Size: 50.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for django_realtime_chat-1.3.7.tar.gz
Algorithm Hash digest
SHA256 65a64e7f86ccb612de6c69fdd50c25e2ae2c182c81c02cf6913b64f9e23d1a98
MD5 76c576e3a0b814437319bbad9f487411
BLAKE2b-256 a8e151deb0862606622dfd3e2be409565f8699aafb6c8decb8c27be54f6b9402

See more details on using hashes here.

File details

Details for the file django_realtime_chat-1.3.7-py3-none-any.whl.

File metadata

File hashes

Hashes for django_realtime_chat-1.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d0fedabe3500ec2933f53d4831ba6f60ec3cf3e0e9fe08ac91381c1d5274aa96
MD5 22686221d48e79dd3fdd2c0331ff5945
BLAKE2b-256 dfd61aa609e6c1172b91fd7b6f95d08abf2d9189a7a549c4335a4cc62b3ed54d

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