# 企业微信SDK - Python语言实现
[更新日志](./CHANGELOG.md)
## 项目介绍
本项目通过封装企业微信服务端API开发了一个企业微信SDK,具备基础常用功能,以便提高相关脚本、程序开发效率。
项目基于异步开发,能有效提高请求效率,具有以下模块:
- `WecomBaseClient` 基本模块,获取access_token(具备内存缓存机制)
- `WecomDepartmentClient` 部门处理模块,具有增删改查部门功能
- `WecomMessageClient` 消息发送模块,兼容多种方式发送消息
- `WecomUsersClient` 用户管理模块,具有查询信息、学工号转换功能(不通用)
- `HttpxRequest` Httpx请求库封装,具有`GET`、`POST`方法
基于以上模块,Mixin后成为 `Wecom` 类,可通过`from wecom-sdk import Wecom`进行实例化
项目使用`Pydantic`库对数据建模,具有完备的类型提示与数据校验功能。
项目各类、各方法、各数据模型均有文档注释,可读性高。
可访问`test`文件夹查看用例。
## 项目架构
```bash
-- wecom_sdk
|-- exceptions
| `-- general.py # 异常类
|-- modules
| |-- base.py # 基本模块
| |-- department.py # 部门处理模块
| |-- message.py # 消息发送模块
| |-- mixin.py # Mixin类
| `-- users.py # 用户管理模块
|-- schemas
| |-- base.py # 基础模型
| |-- departments.py # 部门模型
| |-- message.py # 消息模型
| |-- token.py # 密钥模型
| `-- users.py # 用户模型
`-- utils
|-- convert.py # 学工号转换
`-- requests.py # Httpx库封装
```
## 使用方法
1. 安装`wecom-sdk`库
```bash
pip install wecom-sdk
```
2. 在项目中引用`wecom-sdk`库
```python
from wecom_sdk import Wecom
from wecom_sdk.schemas.message import MessageParams
from wecom_sdk.exceptions.general import SDKException
client = Wecom(corpid="your_corpid", corpsecret="your_corpsecret")
# 发送消息
async def send_message():
try:
data = MessageParams(
touser="821175643076",
agentid=48,
msgtype="text",
text={
"content": '你的快递已到,请携带工卡前往邮件中心领取。\n出发前可查看<a href="http://work.weixin.qq.com">邮件中心视频实况</a>,聪明避开排队。'
},
)
msgid = await setup.send_message(data)
except SDKException:
...
```
## 软件协议
本项目遵循[License: MIT](./LICENSE)协议
Raw data
{
"_id": null,
"home_page": "https://github.com/TAHD3R/wecom-sdk",
"name": "wecom_sdk",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9,<4.0",
"maintainer_email": "",
"keywords": "wecom,sdk",
"author": "Jasar Ayiken",
"author_email": "jaasaar@126.com",
"download_url": "https://files.pythonhosted.org/packages/4b/a4/16e280930b7570384f03f0e0e55a746aed3293275e6c4ea259c635778aa6/wecom_sdk-1.0.0.tar.gz",
"platform": null,
"description": "# \u4f01\u4e1a\u5fae\u4fe1SDK - Python\u8bed\u8a00\u5b9e\u73b0\n\n[\u66f4\u65b0\u65e5\u5fd7](./CHANGELOG.md) \n\n## \u9879\u76ee\u4ecb\u7ecd\n\n\u672c\u9879\u76ee\u901a\u8fc7\u5c01\u88c5\u4f01\u4e1a\u5fae\u4fe1\u670d\u52a1\u7aefAPI\u5f00\u53d1\u4e86\u4e00\u4e2a\u4f01\u4e1a\u5fae\u4fe1SDK\uff0c\u5177\u5907\u57fa\u7840\u5e38\u7528\u529f\u80fd\uff0c\u4ee5\u4fbf\u63d0\u9ad8\u76f8\u5173\u811a\u672c\u3001\u7a0b\u5e8f\u5f00\u53d1\u6548\u7387\u3002\n\n\u9879\u76ee\u57fa\u4e8e\u5f02\u6b65\u5f00\u53d1\uff0c\u80fd\u6709\u6548\u63d0\u9ad8\u8bf7\u6c42\u6548\u7387\uff0c\u5177\u6709\u4ee5\u4e0b\u6a21\u5757\uff1a\n\n- `WecomBaseClient` \u57fa\u672c\u6a21\u5757\uff0c\u83b7\u53d6access_token(\u5177\u5907\u5185\u5b58\u7f13\u5b58\u673a\u5236)\n\n- `WecomDepartmentClient` \u90e8\u95e8\u5904\u7406\u6a21\u5757\uff0c\u5177\u6709\u589e\u5220\u6539\u67e5\u90e8\u95e8\u529f\u80fd\n\n- `WecomMessageClient` \u6d88\u606f\u53d1\u9001\u6a21\u5757\uff0c\u517c\u5bb9\u591a\u79cd\u65b9\u5f0f\u53d1\u9001\u6d88\u606f\n\n- `WecomUsersClient` \u7528\u6237\u7ba1\u7406\u6a21\u5757\uff0c\u5177\u6709\u67e5\u8be2\u4fe1\u606f\u3001\u5b66\u5de5\u53f7\u8f6c\u6362\u529f\u80fd\uff08\u4e0d\u901a\u7528\uff09\n\n- `HttpxRequest` Httpx\u8bf7\u6c42\u5e93\u5c01\u88c5\uff0c\u5177\u6709`GET`\u3001`POST`\u65b9\u6cd5\n\n\u57fa\u4e8e\u4ee5\u4e0a\u6a21\u5757\uff0cMixin\u540e\u6210\u4e3a `Wecom` \u7c7b\uff0c\u53ef\u901a\u8fc7`from wecom-sdk import Wecom`\u8fdb\u884c\u5b9e\u4f8b\u5316\n\n\u9879\u76ee\u4f7f\u7528`Pydantic`\u5e93\u5bf9\u6570\u636e\u5efa\u6a21\uff0c\u5177\u6709\u5b8c\u5907\u7684\u7c7b\u578b\u63d0\u793a\u4e0e\u6570\u636e\u6821\u9a8c\u529f\u80fd\u3002\n\n\u9879\u76ee\u5404\u7c7b\u3001\u5404\u65b9\u6cd5\u3001\u5404\u6570\u636e\u6a21\u578b\u5747\u6709\u6587\u6863\u6ce8\u91ca\uff0c\u53ef\u8bfb\u6027\u9ad8\u3002\n\n\u53ef\u8bbf\u95ee`test`\u6587\u4ef6\u5939\u67e5\u770b\u7528\u4f8b\u3002\n\n## \u9879\u76ee\u67b6\u6784\n\n```bash\n-- wecom_sdk\n |-- exceptions\n | `-- general.py # \u5f02\u5e38\u7c7b\n |-- modules\n | |-- base.py # \u57fa\u672c\u6a21\u5757\n | |-- department.py # \u90e8\u95e8\u5904\u7406\u6a21\u5757\n | |-- message.py # \u6d88\u606f\u53d1\u9001\u6a21\u5757\n | |-- mixin.py # Mixin\u7c7b\n | `-- users.py # \u7528\u6237\u7ba1\u7406\u6a21\u5757\n |-- schemas\n | |-- base.py # \u57fa\u7840\u6a21\u578b\n | |-- departments.py # \u90e8\u95e8\u6a21\u578b\n | |-- message.py # \u6d88\u606f\u6a21\u578b\n | |-- token.py # \u5bc6\u94a5\u6a21\u578b\n | `-- users.py # \u7528\u6237\u6a21\u578b\n `-- utils\n |-- convert.py # \u5b66\u5de5\u53f7\u8f6c\u6362\n `-- requests.py # Httpx\u5e93\u5c01\u88c5\n```\n\n## \u4f7f\u7528\u65b9\u6cd5\n\n1. \u5b89\u88c5`wecom-sdk`\u5e93\n\n```bash\npip install wecom-sdk\n```\n\n2. \u5728\u9879\u76ee\u4e2d\u5f15\u7528`wecom-sdk`\u5e93\n\n```python\nfrom wecom_sdk import Wecom\nfrom wecom_sdk.schemas.message import MessageParams\nfrom wecom_sdk.exceptions.general import SDKException\n\nclient = Wecom(corpid=\"your_corpid\", corpsecret=\"your_corpsecret\")\n\n# \u53d1\u9001\u6d88\u606f\nasync def send_message():\n try:\n data = MessageParams(\n touser=\"821175643076\",\n agentid=48,\n msgtype=\"text\",\n text={\n \"content\": '\u4f60\u7684\u5feb\u9012\u5df2\u5230\uff0c\u8bf7\u643a\u5e26\u5de5\u5361\u524d\u5f80\u90ae\u4ef6\u4e2d\u5fc3\u9886\u53d6\u3002\\n\u51fa\u53d1\u524d\u53ef\u67e5\u770b<a href=\"http://work.weixin.qq.com\">\u90ae\u4ef6\u4e2d\u5fc3\u89c6\u9891\u5b9e\u51b5</a>\uff0c\u806a\u660e\u907f\u5f00\u6392\u961f\u3002'\n },\n )\n msgid = await setup.send_message(data)\n except SDKException:\n ...\n\n```\n\n## \u8f6f\u4ef6\u534f\u8bae\n\n\u672c\u9879\u76ee\u9075\u5faa[License: MIT](./LICENSE)\u534f\u8bae\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Wecom SDK for Python",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/TAHD3R/wecom-sdk",
"Repository": "https://github.com/TAHD3R/wecom-sdk"
},
"split_keywords": [
"wecom",
"sdk"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cbd623f22b650991bc5eaba68d350b593ef89c714849d7930112ee6fb43c1880",
"md5": "6cb3ce6ec1ae2ba126bdf868eed4a926",
"sha256": "0636c47fc6850ef2f6605e43893da8a8af7f515d3aae63ede52b13a7b88c3cb5"
},
"downloads": -1,
"filename": "wecom_sdk-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6cb3ce6ec1ae2ba126bdf868eed4a926",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9,<4.0",
"size": 12920,
"upload_time": "2024-03-14T11:52:30",
"upload_time_iso_8601": "2024-03-14T11:52:30.869336Z",
"url": "https://files.pythonhosted.org/packages/cb/d6/23f22b650991bc5eaba68d350b593ef89c714849d7930112ee6fb43c1880/wecom_sdk-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4ba416e280930b7570384f03f0e0e55a746aed3293275e6c4ea259c635778aa6",
"md5": "7dde46b2ae158bdc5a3bb90c2e909c39",
"sha256": "38456e35f8789968c4c78783295298b89002ff19472504e214ec3f381ead908c"
},
"downloads": -1,
"filename": "wecom_sdk-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "7dde46b2ae158bdc5a3bb90c2e909c39",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9,<4.0",
"size": 9737,
"upload_time": "2024-03-14T11:52:32",
"upload_time_iso_8601": "2024-03-14T11:52:32.769263Z",
"url": "https://files.pythonhosted.org/packages/4b/a4/16e280930b7570384f03f0e0e55a746aed3293275e6c4ea259c635778aa6/wecom_sdk-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-14 11:52:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "TAHD3R",
"github_project": "wecom-sdk",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "wecom_sdk"
}