# Python SDK

## 在项目中引用

使用 pip&#x20;

```bash
pip install wx-connector-pysdk
```

或使用 uv

```bash
uv pip install wx-connector-pysdk
```

简单的代码示例可以查看 Python SDK 的 README 页面

{% embed url="<https://github.com/El1mir/wx-connector-pysdk/blob/main/README.md>" %}

## 方法文档

### set\_url

设置 WxConnectorProvider 提供 api 的 url\
格式一般为 localhost:\<port> —— localhost:8022

| 参数             | 参数意义                             |
| -------------- | -------------------------------- |
| base\_url: str | WxConnectorProvider 提供 api 的 url |

### start\_event\_listen

启动本包的事件监听器，用于加载event对象

### strat\_wx

用于启动 WeChat

| 参数            | 参数意义            |
| ------------- | --------------- |
| wx\_path: str | WeChat 主程序的完整路径 |

### start\_listeners

用于打开监听窗口并启动 WxConnectorProvider 端的事件监听

| 参数                    | 参数意义              |
| --------------------- | ----------------- |
| listeners: List\[str] | 监听对象（用户备注名和群名备注名） |

### send\_text

用于向指定窗口发送普通文本消息（支持排版和wx表情）

| 参数            | 参数意义                                                    |
| ------------- | ------------------------------------------------------- |
| msg: str      | 需要发送的消息文本内容                                             |
| send\_to: str | <p>用于发送的窗口（同listeners）<br>也就是监听对象的备注名，开始监听时传的什么就用什么</p> |

### send\_file

用于向指定窗口发送本地文件消息

| 参数              | 参数意义                                                    |
| --------------- | ------------------------------------------------------- |
| file\_path: str | 需要发送的本地文件的完整路径                                          |
| send\_to: str   | <p>用于发送的窗口（同listeners）<br>也就是监听对象的备注名，开始监听时传的什么就用什么</p> |

### event

是一个 EventManager 对象，全局单例，用于处理 WxConnectorProvider 的 Websocket 传递的事件

#### on

一个含参数装饰器，用于定义 Event 处理函数

支持的 Event 事件类型请查看 WxConnectorProvider 的 api 文档的事件监听部分

{% embed url="<https://3rr385280j.apifox.cn/3621830w0>" %}
WxConnectorProvider Api 文档
{% endembed %}

使用示例

```python
@event.on("NewMessageWithoutSelfEvent")
def handle_new_msg(msg: WMessage) -> None:
    print(f"从{msg.MsgFromWindow}窗口收到{msg.MsgSenderName}的信息说：{msg.MsgContent}")
```

### at\_by\_username\_in\_group

用于在群内使用用户备注名at对方

| 参数                 | 参数意义          |
| ------------------ | ------------- |
| username: str      | 需要 at 的用户的备注名 |
| window\_title: str | 群独立聊天窗口       |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://el1mirs-organization.gitbook.io/wxconnector/sdk-wen-dang/python-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
