Wecom SDK for Python
Project description
企业微信SDK - Python语言实现
项目介绍
本项目通过封装企业微信服务端API开发了一个企业微信SDK,具备基础常用功能,以便提高相关脚本、程序开发效率。
项目基于异步开发,能有效提高请求效率,具有以下模块:
-
WecomBaseClient基本模块,获取access_token(具备内存缓存机制) -
WecomDepartmentClient部门处理模块,具有增删改查部门功能 -
WecomMessageClient消息发送模块,兼容多种方式发送消息 -
WecomUsersClient用户管理模块,具有查询信息、学工号转换功能(不通用) -
HttpxRequestHttpx请求库封装,具有GET、POST方法
基于以上模块,Mixin后成为 Wecom 类,可通过from wecom-sdk import Wecom进行实例化
项目使用Pydantic库对数据建模,具有完备的类型提示与数据校验功能。
项目各类、各方法、各数据模型均有文档注释,可读性高。
可访问test文件夹查看用例。
项目架构
-- 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库封装
使用方法
- 安装
wecom-sdk库
pip install wecom-sdk
- 在项目中引用
wecom-sdk库
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协议
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wecom_sdk-1.0.0.tar.gz.
File metadata
- Download URL: wecom_sdk-1.0.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38456e35f8789968c4c78783295298b89002ff19472504e214ec3f381ead908c
|
|
| MD5 |
7dde46b2ae158bdc5a3bb90c2e909c39
|
|
| BLAKE2b-256 |
4ba416e280930b7570384f03f0e0e55a746aed3293275e6c4ea259c635778aa6
|
File details
Details for the file wecom_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: wecom_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0636c47fc6850ef2f6605e43893da8a8af7f515d3aae63ede52b13a7b88c3cb5
|
|
| MD5 |
6cb3ce6ec1ae2ba126bdf868eed4a926
|
|
| BLAKE2b-256 |
cbd623f22b650991bc5eaba68d350b593ef89c714849d7930112ee6fb43c1880
|