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.1

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.1
File Size Uploaded Provenance Actions
django_realtime_chat-2.0.1.tar.gz 47.5 kB Without provenance Details for django_realtime_chat-2.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 96.9 kB

Release files / django_realtime_chat-2.0.1.tar.gz

Download URL django_realtime_chat-2.0.1.tar.gz
Size 47.5 kB
Tags Source
SHA-256 checksum
How to use checksums
228a6e6602153fe2a0cab01b86e338c167bdc229502ea83c789e7c153094fbaa
BLAKE2b-256 checksum
How to use checksums
3f2b41e6efe9ee5f5d65106633943bd4c31a0a4115d3ab7f913f6ab4076d4afb
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.1-py3-none-any.whl

Download URL django_realtime_chat-2.0.1-py3-none-any.whl
Size 49.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e63d9903098311a2dac79b4cc516f27c6d470a96d02a2a2135aafcf863f54c6c
BLAKE2b-256 checksum
How to use checksums
8f072c8798cf0613885a8cbc592cc00925d657f4a907e22b1a4d09b9ca05344c
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.1

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