channel-box-0.4.0
توضیحات
channel-box it is a simple tool for Starlette framework that allows you to make named webscoket channels.
| ویژگی | مقدار |
|---|---|
| سیستم عامل | OS Independent |
| نام فایل | channel-box-0.4.0 |
| نام | channel-box |
| نسخه کتابخانه | 0.4.0 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Sobolev Andrey |
| ایمیل نویسنده | email.asobolev@gmail.com |
| آدرس صفحه اصلی | https://github.com/Sobolev5/channel-box |
| آدرس اینترنتی | https://pypi.org/project/channel-box/ |
| مجوز | - |
# channel-box
`channel-box` it is a simple tool for Starlette framework that allows you send messages to named websocket channels.
Example of use:
- group chats
- notifications from backend
- alerts
```no-highlight
https://github.com/Sobolev5/channel-box
```
## Install
To install run:
```no-highlight
pip install channel-box
```
## [important!] see full working example `example/app.py`
```sh
https://channel-box.andrey-sobolev.ru/
https://github.com/Sobolev5/channel-box/tree/master/example
```
## NGINX websocket setup
```sh
http://nginx.org/en/docs/http/websocket.html
```
## Check uvicorn installation
```sh
pip install uvicorn[standard]
```
## Setup channel
```python
class Channel(ChannelBoxEndpoint):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.expires = 1600
self.encoding = "json"
async def on_connect(self, websocket):
channel_name = websocket.query_params.get("channel_name", "MySimpleChat") # channel name */ws?channel_name=MySimpleChat
await self.channel_get_or_create(channel_name, websocket)
await websocket.accept()
async def on_receive(self, websocket, data):
message = data["message"]
username = data["username"]
if message.strip():
payload = {
"username": username,
"message": message,
}
await self.channel_send(payload, history=True)
```
## Send messages
Send message to any channel from any part of your code:
```python
from channel_box import channel_box
await channel_box.channel_send(channel_name="MySimpleChat", payload={"username": "Message HTTPEndpoint", "message": "hello from Message"}, history=True)
```
Get & flush channels:
```python
await channel_box.channels()
await channel_box.channels_flush()
```
Get & flush history:
```python
await channel_box.history()
await channel_box.history_flush()
```
## TODO
```python
typing
__doc__ strings
```
## Try my free time tracker
My free time tracker for developers [Workhours.space](https://workhours.space/).
نیازمندی
| مقدار | نام |
|---|---|
| >=0.20.4 | starlette |
| >=1.0.9 | shortuuid |
| >=0.18.3 | uvicorn[standart] |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.8 | Python |
نحوه نصب
نصب پکیج whl channel-box-0.4.0:
pip install channel-box-0.4.0.whl
نصب پکیج tar.gz channel-box-0.4.0:
pip install channel-box-0.4.0.tar.gz