CheeseAPI-websocket


NameCheeseAPI-websocket JSON
Version 0.0.4 PyPI version JSON
download
home_pagehttps://github.com/CheeseUnknown/CheeseAPI_websocket
Summary基于CheeseAPI的升级版websocket
upload_time2023-08-09 17:53:45
maintainer
docs_urlNone
authorCheese Unknown
requires_python>=3.11
licenseMIT
keywords cheeseapi websocket redis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # **CheeseAPI_websocket**

## **介绍**

一款基于[CheeseAPI](https://github.com/CheeseUnknown/CheeseAPI)的升级版websocket,它能够解决在多worker下websocket的通讯问题,前提是需要引入redis。

## **安装**

```bash
pip install CheeseAPI_websocket
```

你需要在CheeseAPI中导入该模块:

```python
app.modules = [ 'CheeseAPI_websocket' ]
```

## **使用**

```python
from CheeseAPI import app
from CheeseAPI_websocket import websocket

app.modules = [ 'CheeseAPI_websocket' ]

websocket.init() # 初始化

# 开启一个websocket接口
@app.route.websocket('/myWebsocket')
async def a():
    ...

@app.route.get('/test')
async def b():
    await websocket.async_send('你好', '/myWebsocket') # 在协程环境下广播信息
    ...

...

websocket.send('你好', '/myWebsocket') # 在非协程环境下广播信息
```

## **API**

### **`websocket`**

```python
from CheeseAPI_websocket import websocket
```

- **`websocket.init(host: CheeseType.network.IPv4 = '127.0.0.1', port: CheeseType.network.Port = 6379, db: CheeseType.NonNegativeInt = 0, password: str | None = None, username: str | None = None)`**

    初始化连接redis。

- **`websocket.send(message: any, path: str, sid: str | list[str] | None = None)`**

    非协程环境下发送消息。`sid`为`None`时为广播,`sid`为`str`或`list[str]`时为指定客户端发送。如果该消息未有对应的接收方,则不会做出任何响应。

- **`await websocket.async_send(self, message: any, path: str, sid: str | list[str] | None = None)`**

    在协程环境下发送消息,与`websocket.send`相同。

- **`websocket.close(path: str, sid: str | list[str] | None = None)`**

    非协程环境下关闭客户端。`sid`为`None`时关闭该路径的所有的客户端连接,`sid`为`str`或`list[str]`时关闭该路径下指定的客户端连接。如果未有对应的客户端连接,则不做出任何响应。

- **`await websocket.close(path: str, sid: str | list[str] | None = None)`**

    协程环境下关闭客户端。与`websocket.close`相同。

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/CheeseUnknown/CheeseAPI_websocket",
    "name": "CheeseAPI-websocket",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "CheeseAPI websocket redis",
    "author": "Cheese Unknown",
    "author_email": "cheese@cheese.ren",
    "download_url": "https://files.pythonhosted.org/packages/91/0e/6810e92aca8bd56997e32ca9bf7f693593256835445182856c67f4ee50ca/CheeseAPI_websocket-0.0.4.tar.gz",
    "platform": null,
    "description": "# **CheeseAPI_websocket**\n\n## **\u4ecb\u7ecd**\n\n\u4e00\u6b3e\u57fa\u4e8e[CheeseAPI](https://github.com/CheeseUnknown/CheeseAPI)\u7684\u5347\u7ea7\u7248websocket\uff0c\u5b83\u80fd\u591f\u89e3\u51b3\u5728\u591aworker\u4e0bwebsocket\u7684\u901a\u8baf\u95ee\u9898\uff0c\u524d\u63d0\u662f\u9700\u8981\u5f15\u5165redis\u3002\n\n## **\u5b89\u88c5**\n\n```bash\npip install CheeseAPI_websocket\n```\n\n\u4f60\u9700\u8981\u5728CheeseAPI\u4e2d\u5bfc\u5165\u8be5\u6a21\u5757\uff1a\n\n```python\napp.modules = [ 'CheeseAPI_websocket' ]\n```\n\n## **\u4f7f\u7528**\n\n```python\nfrom CheeseAPI import app\nfrom CheeseAPI_websocket import websocket\n\napp.modules = [ 'CheeseAPI_websocket' ]\n\nwebsocket.init() # \u521d\u59cb\u5316\n\n# \u5f00\u542f\u4e00\u4e2awebsocket\u63a5\u53e3\n@app.route.websocket('/myWebsocket')\nasync def a():\n    ...\n\n@app.route.get('/test')\nasync def b():\n    await websocket.async_send('\u4f60\u597d', '/myWebsocket') # \u5728\u534f\u7a0b\u73af\u5883\u4e0b\u5e7f\u64ad\u4fe1\u606f\n    ...\n\n...\n\nwebsocket.send('\u4f60\u597d', '/myWebsocket') # \u5728\u975e\u534f\u7a0b\u73af\u5883\u4e0b\u5e7f\u64ad\u4fe1\u606f\n```\n\n## **API**\n\n### **`websocket`**\n\n```python\nfrom CheeseAPI_websocket import websocket\n```\n\n- **`websocket.init(host: CheeseType.network.IPv4 = '127.0.0.1', port: CheeseType.network.Port = 6379, db: CheeseType.NonNegativeInt = 0, password: str | None = None, username: str | None = None)`**\n\n    \u521d\u59cb\u5316\u8fde\u63a5redis\u3002\n\n- **`websocket.send(message: any, path: str, sid: str | list[str] | None = None)`**\n\n    \u975e\u534f\u7a0b\u73af\u5883\u4e0b\u53d1\u9001\u6d88\u606f\u3002`sid`\u4e3a`None`\u65f6\u4e3a\u5e7f\u64ad\uff0c`sid`\u4e3a`str`\u6216`list[str]`\u65f6\u4e3a\u6307\u5b9a\u5ba2\u6237\u7aef\u53d1\u9001\u3002\u5982\u679c\u8be5\u6d88\u606f\u672a\u6709\u5bf9\u5e94\u7684\u63a5\u6536\u65b9\uff0c\u5219\u4e0d\u4f1a\u505a\u51fa\u4efb\u4f55\u54cd\u5e94\u3002\n\n- **`await websocket.async_send(self, message: any, path: str, sid: str | list[str] | None = None)`**\n\n    \u5728\u534f\u7a0b\u73af\u5883\u4e0b\u53d1\u9001\u6d88\u606f\uff0c\u4e0e`websocket.send`\u76f8\u540c\u3002\n\n- **`websocket.close(path: str, sid: str | list[str] | None = None)`**\n\n    \u975e\u534f\u7a0b\u73af\u5883\u4e0b\u5173\u95ed\u5ba2\u6237\u7aef\u3002`sid`\u4e3a`None`\u65f6\u5173\u95ed\u8be5\u8def\u5f84\u7684\u6240\u6709\u7684\u5ba2\u6237\u7aef\u8fde\u63a5\uff0c`sid`\u4e3a`str`\u6216`list[str]`\u65f6\u5173\u95ed\u8be5\u8def\u5f84\u4e0b\u6307\u5b9a\u7684\u5ba2\u6237\u7aef\u8fde\u63a5\u3002\u5982\u679c\u672a\u6709\u5bf9\u5e94\u7684\u5ba2\u6237\u7aef\u8fde\u63a5\uff0c\u5219\u4e0d\u505a\u51fa\u4efb\u4f55\u54cd\u5e94\u3002\n\n- **`await websocket.close(path: str, sid: str | list[str] | None = None)`**\n\n    \u534f\u7a0b\u73af\u5883\u4e0b\u5173\u95ed\u5ba2\u6237\u7aef\u3002\u4e0e`websocket.close`\u76f8\u540c\u3002\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\u57fa\u4e8eCheeseAPI\u7684\u5347\u7ea7\u7248websocket",
    "version": "0.0.4",
    "project_urls": {
        "Homepage": "https://github.com/CheeseUnknown/CheeseAPI_websocket"
    },
    "split_keywords": [
        "cheeseapi",
        "websocket",
        "redis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "79f64aa152699f21dda1a2a848171da56688b54afe7d0d7751ca017e2eae159f",
                "md5": "c31d12f322ca1fb7aa7132d7ab7902f1",
                "sha256": "d49cd69431ec0f8bc96d992d1bfc60b424ddde9f0a46ef9c29b49f4288b1701d"
            },
            "downloads": -1,
            "filename": "CheeseAPI_websocket-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c31d12f322ca1fb7aa7132d7ab7902f1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 4712,
            "upload_time": "2023-08-09T17:53:43",
            "upload_time_iso_8601": "2023-08-09T17:53:43.363467Z",
            "url": "https://files.pythonhosted.org/packages/79/f6/4aa152699f21dda1a2a848171da56688b54afe7d0d7751ca017e2eae159f/CheeseAPI_websocket-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "910e6810e92aca8bd56997e32ca9bf7f693593256835445182856c67f4ee50ca",
                "md5": "c99179a19f2989cdc1e0b8d0e46d8600",
                "sha256": "b090b05bb7c15a15b049c16d5c9d35dc036287ec4906b125af54755e5dfdeba7"
            },
            "downloads": -1,
            "filename": "CheeseAPI_websocket-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "c99179a19f2989cdc1e0b8d0e46d8600",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 3983,
            "upload_time": "2023-08-09T17:53:45",
            "upload_time_iso_8601": "2023-08-09T17:53:45.016894Z",
            "url": "https://files.pythonhosted.org/packages/91/0e/6810e92aca8bd56997e32ca9bf7f693593256835445182856c67f4ee50ca/CheeseAPI_websocket-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-09 17:53:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "CheeseUnknown",
    "github_project": "CheeseAPI_websocket",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "cheeseapi-websocket"
}
        
Elapsed time: 0.36646s