django-chelseru-chat


Namedjango-chelseru-chat JSON
Version 1.3.2 PyPI version JSON
download
home_pagehttps://pip-chat.chelseru.com
SummaryReal-time one-on-one chat system for Django projects, powered by WebSocket and JWT authentication.
upload_time2025-08-10 10:19:48
maintainerNone
docs_urlNone
authorSobhan Bahman Rashnu
requires_python>=3.11
licenseNone
keywords djangochelseruchat djangochat drfchat online-chat online real-time chat iran chelseru lor lur bahman rashnu sobhan چت سبحان بهمن رشنو چلسرو جنگو پایتون لر لور آنلاین ریل تایم
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django Chelseru Chat

A simple real-time chat package for Django using Django Channels and WebSocket. It enables one-on-one private messaging secured with JWT authentication.

---

## Installation

```bash
pip install django-chelseru-chat
```

---

## Configuration

Ensure your Django project is ASGI-compatible and set up with JWT authentication for WebSocket connections.

### 1. Add to `INSTALLED_APPS`:

```python
INSTALLED_APPS = [
    ...
    'channels',
    'chelseru_chat',
]
```

### 2. Set `ASGI_APPLICATION` and `CHANNEL_LAYERS` in `settings.py`:

```python
ASGI_APPLICATION = '<your_project_name>.asgi.application'
```

> Replace `<your_project_name>` with the actual name of your Django project folder (e.g., `myproject`).

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


### 3. Use your custom `asgi.py` with `JWTAuthMiddleware`:

```python
# <your_project_name>/asgi.py

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

# Set environment and initialize Django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '<your_project_name>.settings')
django.setup()

# Import routing and middleware AFTER setup
import chelseru_chat.routing
from chelseru_chat.middleware import JWTAuthMiddleware

application = ProtocolTypeRouter({
    "http": get_asgi_application(),
    "websocket": JWTAuthMiddleware(
        URLRouter(
            chelseru_chat.routing.websocket_urlpatterns
        )
    ),
})
```
> Again, replace `<your_project_name>` with your Django project's name.

---

## Models

### `ChatRoom`

```python
class ChatRoom(models.Model):
    user_1 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user1_chats')
    user_2 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user2_chats')
    created_at = models.DateTimeField(auto_now_add=True)
```

### `Message`

```python
class Message(models.Model):
    chat_room = models.ForeignKey(ChatRoom, on_delete=models.CASCADE, related_name='messages')
    sender = models.ForeignKey(User, on_delete=models.CASCADE)
    text = models.TextField()
    timestamp = models.DateTimeField(auto_now_add=True)
```

---

## WebSocket Connection

To send and receive messages, connect via WebSocket to:

```
ws://<your-domain>/ws/chat/<chat_room_id>/?token=<your_jwt_access_token>
```

**Example:**

```
ws://qesa.chelseru.com/ws/chat/3/?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
```

### To send a message:

```json
> {"message": "Sar barzi, Luria"}
```

### You will receive a response like:

```json
< {"message": "Sar barzi, Luria", "sender": "user"}
```

---

## Create ChatRoom Programmatically

```python
from chelseru_chat.models import ChatRoom
chat = ChatRoom.objects.create(user_1=user1, user_2=user2)
```

---

## JWT WebSocket Authentication

This package uses a custom `JWTAuthMiddleware` for authenticating users via JWT tokens.  
Token must be provided as a query parameter: `?token=...`

You can use [`djangorestframework-simplejwt`](https://django-rest-framework-simplejwt.readthedocs.io/) to issue tokens.

---

## Features

- Private 1-on-1 chat
- Real-time messaging via WebSocket
- JWT-authenticated WebSocket
- Message history per room
- Simple model structure

---

## TODO

- Group chat support
- Message read status
- Typing indicators

---

## License

MIT License

Sobhan Bahman | Rashnu


            

Raw data

            {
    "_id": null,
    "home_page": "https://pip-chat.chelseru.com",
    "name": "django-chelseru-chat",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "djangochelseruchat djangochat drfchat online-chat online real-time chat iran chelseru lor lur bahman rashnu sobhan \u0686\u062a  \u0633\u0628\u062d\u0627\u0646 \u0628\u0647\u0645\u0646 \u0631\u0634\u0646\u0648 \u0686\u0644\u0633\u0631\u0648 \u062c\u0646\u06af\u0648 \u067e\u0627\u06cc\u062a\u0648\u0646 \u0644\u0631 \u0644\u0648\u0631 \u0622\u0646\u0644\u0627\u06cc\u0646 \u0631\u06cc\u0644 \u062a\u0627\u06cc\u0645",
    "author": "Sobhan Bahman Rashnu",
    "author_email": "bahmanrashnu@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/31/6c/98d58a53a5213c74e5692c2a0cd0afbca73811d6c0a1bba1df6533ab8192/django_chelseru_chat-1.3.2.tar.gz",
    "platform": null,
    "description": "# Django Chelseru Chat\n\nA simple real-time chat package for Django using Django Channels and WebSocket. It enables one-on-one private messaging secured with JWT authentication.\n\n---\n\n## Installation\n\n```bash\npip install django-chelseru-chat\n```\n\n---\n\n## Configuration\n\nEnsure your Django project is ASGI-compatible and set up with JWT authentication for WebSocket connections.\n\n### 1. Add to `INSTALLED_APPS`:\n\n```python\nINSTALLED_APPS = [\n    ...\n    'channels',\n    'chelseru_chat',\n]\n```\n\n### 2. Set `ASGI_APPLICATION` and `CHANNEL_LAYERS` in `settings.py`:\n\n```python\nASGI_APPLICATION = '<your_project_name>.asgi.application'\n```\n\n> Replace `<your_project_name>` with the actual name of your Django project folder (e.g., `myproject`).\n\n```python\nCHANNEL_LAYERS = {\n    \"default\": {\n        \"BACKEND\": \"channels_redis.core.RedisChannelLayer\",\n        \"CONFIG\": {\n            \"hosts\": [('127.0.0.1', 6379)],\n        },\n    },\n}\n```\n\n\n### 3. Use your custom `asgi.py` with `JWTAuthMiddleware`:\n\n```python\n# <your_project_name>/asgi.py\n\nimport os\nimport django\nfrom channels.routing import ProtocolTypeRouter, URLRouter\nfrom django.core.asgi import get_asgi_application\n\n# Set environment and initialize Django\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', '<your_project_name>.settings')\ndjango.setup()\n\n# Import routing and middleware AFTER setup\nimport chelseru_chat.routing\nfrom chelseru_chat.middleware import JWTAuthMiddleware\n\napplication = ProtocolTypeRouter({\n    \"http\": get_asgi_application(),\n    \"websocket\": JWTAuthMiddleware(\n        URLRouter(\n            chelseru_chat.routing.websocket_urlpatterns\n        )\n    ),\n})\n```\n> Again, replace `<your_project_name>` with your Django project's name.\n\n---\n\n## Models\n\n### `ChatRoom`\n\n```python\nclass ChatRoom(models.Model):\n    user_1 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user1_chats')\n    user_2 = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user2_chats')\n    created_at = models.DateTimeField(auto_now_add=True)\n```\n\n### `Message`\n\n```python\nclass Message(models.Model):\n    chat_room = models.ForeignKey(ChatRoom, on_delete=models.CASCADE, related_name='messages')\n    sender = models.ForeignKey(User, on_delete=models.CASCADE)\n    text = models.TextField()\n    timestamp = models.DateTimeField(auto_now_add=True)\n```\n\n---\n\n## WebSocket Connection\n\nTo send and receive messages, connect via WebSocket to:\n\n```\nws://<your-domain>/ws/chat/<chat_room_id>/?token=<your_jwt_access_token>\n```\n\n**Example:**\n\n```\nws://qesa.chelseru.com/ws/chat/3/?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...\n```\n\n### To send a message:\n\n```json\n> {\"message\": \"Sar barzi, Luria\"}\n```\n\n### You will receive a response like:\n\n```json\n< {\"message\": \"Sar barzi, Luria\", \"sender\": \"user\"}\n```\n\n---\n\n## Create ChatRoom Programmatically\n\n```python\nfrom chelseru_chat.models import ChatRoom\nchat = ChatRoom.objects.create(user_1=user1, user_2=user2)\n```\n\n---\n\n## JWT WebSocket Authentication\n\nThis package uses a custom `JWTAuthMiddleware` for authenticating users via JWT tokens.  \nToken must be provided as a query parameter: `?token=...`\n\nYou can use [`djangorestframework-simplejwt`](https://django-rest-framework-simplejwt.readthedocs.io/) to issue tokens.\n\n---\n\n## Features\n\n- Private 1-on-1 chat\n- Real-time messaging via WebSocket\n- JWT-authenticated WebSocket\n- Message history per room\n- Simple model structure\n\n---\n\n## TODO\n\n- Group chat support\n- Message read status\n- Typing indicators\n\n---\n\n## License\n\nMIT License\n\nSobhan Bahman | Rashnu\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Real-time one-on-one chat system for Django projects, powered by WebSocket and JWT authentication.",
    "version": "1.3.2",
    "project_urls": {
        "Documentation": "https://github.com/Chelseru/django-chelseru-chat-lour/",
        "Homepage": "https://pip-chat.chelseru.com",
        "Telegram Channel": "https://t.me/ChelseruCom",
        "Telegram Group": "https://t.me/bahmanpy"
    },
    "split_keywords": [
        "djangochelseruchat",
        "djangochat",
        "drfchat",
        "online-chat",
        "online",
        "real-time",
        "chat",
        "iran",
        "chelseru",
        "lor",
        "lur",
        "bahman",
        "rashnu",
        "sobhan",
        "\u0686\u062a",
        "",
        "\u0633\u0628\u062d\u0627\u0646",
        "\u0628\u0647\u0645\u0646",
        "\u0631\u0634\u0646\u0648",
        "\u0686\u0644\u0633\u0631\u0648",
        "\u062c\u0646\u06af\u0648",
        "\u067e\u0627\u06cc\u062a\u0648\u0646",
        "\u0644\u0631",
        "\u0644\u0648\u0631",
        "\u0622\u0646\u0644\u0627\u06cc\u0646",
        "\u0631\u06cc\u0644",
        "\u062a\u0627\u06cc\u0645"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "76d9ee8605419b89b3c630adf9b018c960af2dd56264961173b21087026b7bd2",
                "md5": "43ccf0f69dd05188fd96b055aa3072b1",
                "sha256": "2489e2f9956b94afe29f2057742b886ed7fc816cb6868321c55d9bfe79aad64b"
            },
            "downloads": -1,
            "filename": "django_chelseru_chat-1.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "43ccf0f69dd05188fd96b055aa3072b1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 9714,
            "upload_time": "2025-08-10T10:19:46",
            "upload_time_iso_8601": "2025-08-10T10:19:46.993670Z",
            "url": "https://files.pythonhosted.org/packages/76/d9/ee8605419b89b3c630adf9b018c960af2dd56264961173b21087026b7bd2/django_chelseru_chat-1.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "316c98d58a53a5213c74e5692c2a0cd0afbca73811d6c0a1bba1df6533ab8192",
                "md5": "8f3bda93a4fe7155532626738b23b544",
                "sha256": "7c0c94035dad8ef18af95d87f7e33ab4d0adee6efca7e4c0978268218ee9d6f6"
            },
            "downloads": -1,
            "filename": "django_chelseru_chat-1.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "8f3bda93a4fe7155532626738b23b544",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 7615,
            "upload_time": "2025-08-10T10:19:48",
            "upload_time_iso_8601": "2025-08-10T10:19:48.297334Z",
            "url": "https://files.pythonhosted.org/packages/31/6c/98d58a53a5213c74e5692c2a0cd0afbca73811d6c0a1bba1df6533ab8192/django_chelseru_chat-1.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-10 10:19:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Chelseru",
    "github_project": "django-chelseru-chat-lour",
    "github_not_found": true,
    "lcname": "django-chelseru-chat"
}
        
Elapsed time: 2.77120s