PyDGLab-WS
一个用于创建郊狼 3.0 DG-Lab App Socket 控制终端和服务端的 Python 库
💡 特性
- 通过该库可开发 Python 程序,接入 DG-Lab App
- 完全使用 asyncio 异步,并发执行各项操作
- 可部署第三方终端与 Socket 服务一体的服务端,降低部署复杂度和延迟
- 使用异步生成器、上下文管理器等,结合语言特性
- 通过 Pydantic, 枚举 管理消息结构和常量,便于开发
🔧 DG-Lab App 的 Socket 被控功能支持的操作
- 获取 A, B 通道强度 以及 通道强度上限 的数据更新
- 对 A, B 通道强度进行操作,支持增加、减少、设定到指定值
- 向 App 发送持续一段时间的波形操作数据
- 清空 App 波形操作队列
- 获取 App 按下反馈按钮的通知
🚀 快速开始
📖 更多用法和完整 API 请查看文档:https://pydglab-ws.readthedocs.io
🔨 安装
pip3 install pydglab-ws
📡 搭建服务端
import asyncio
from pydglab_ws.server import DGLabWSServer
async def main():
async with DGLabWSServer("0.0.0.0", 5678, 60) as server:
while True:
print(f"已连接的 WebSocket 客户端(终端/App):{list(server.uuid_to_ws.keys())}")
print(f"已连接的本地终端:{list(server.local_client_ids)}")
print(f"关系绑定:{server.client_id_to_target_id}")
await asyncio.sleep(5)
if __name__ == "__main__":
asyncio.run(main())
更多演示请查看 examples/server.py
🕹️ 搭建客户端 / 第三方终端
当进入 DGLabWSServer 的异步生成器时,从 WebSocket 服务端获取 clientId 的操作会 自动完成
import asyncio
from websockets import ConnectionClosedOK
from pydglab_ws import DGLabWSConnect
def print_qrcode(_: str):
"""输出二维码到终端界面"""
...
async def main():
try:
async with DGLabWSConnect("ws://192.168.1.161:5678") as client:
# 获取二维码
url = client.get_qrcode()
print("请用 DG-Lab App 扫描二维码以连接")
print_qrcode(url)
# 等待绑定
await client.bind()
print(f"已与 App {client.target_id} 成功绑定")
# 从 App 接收数据更新,并进行远控操作
async for data in client.data_generator():
print(f"收取到数据:{data}")
except ConnectionClosedOK:
print("Socket 服务端断开连接")
if __name__ == "__main__":
asyncio.run(main())
更多演示请查看 examples/ws_client.py
🕹️ 搭建与第三方终端一体的 WebSocket 服务端
这段代码不仅提供 DG-Lab WebSocket 服务端服务,还生成了一个本地终端可供 App 连接。
import asyncio
from pydglab_ws import DGLabWSServer
def print_qrcode(_: str):
"""输出二维码到终端界面"""
...
async def main():
async with DGLabWSServer("0.0.0.0", 5678, 60) as server:
client = server.new_local_client()
url = client.get_qrcode("ws://192.168.1.161:5678")
print("请用 DG-Lab App 扫描二维码以连接")
print_qrcode(url)
# 等待绑定
await client.bind()
print(f"已与 App {client.target_id} 成功绑定")
# 从 App 接收数据更新,并进行远控操作
async for data in client.data_generator():
print(f"收取到数据:{data}")
if __name__ == "__main__":
asyncio.run(main())
更多演示请查看 examples/local_client_with_server.py
📌 更多
🔗 链接
- PyPI: 🔗pydglab-ws
📐 代码覆盖率
许可证
PyDGLab-WS 使用 BSD 3-Clause 许可证.
Copyright © 2024 by Ljzd-PRO.
Metadata
Release files for pydglab-ws 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pydglab_ws-1.1.0.tar.gz | 18.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydglab_ws-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 39.4 kB
Release files / pydglab_ws-1.1.0.tar.gz
| Download URL | pydglab_ws-1.1.0.tar.gz |
|---|---|
| Size | 18.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8af349331e1b495c427e56fb1c55ee9c1fa6f5824992d62c0414f02108ee17f5
|
|
BLAKE2b-256 checksum How to use checksums |
0b84aff0da3e59cfaf15607576d11523097af7fe417eb36bbe6571670fd69e00
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1021-azure
|
Release files / pydglab_ws-1.1.0-py3-none-any.whl
| Download URL | pydglab_ws-1.1.0-py3-none-any.whl |
|---|---|
| Size | 21.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eaf5ca66aeec998cd53775df943eb4ff43232de2154edf82b9434952188ca7fd
|
|
BLAKE2b-256 checksum How to use checksums |
4bc24a53f7ead244e1302c60bd90ca4c69d110a7d756256d2e293de571a5cc6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1021-azure
|
Security for pydglab-ws 1.1.0
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.