Skip to main content

Wecom SDK for Python

Project description

企业微信SDK - Python语言实现

更新日志

项目介绍

本项目通过封装企业微信服务端API开发了一个企业微信SDK,具备基础常用功能,以便提高相关脚本、程序开发效率。

项目基于异步开发,能有效提高请求效率,具有以下模块:

  • WecomBaseClient 基本模块,获取access_token(具备内存缓存机制)

  • WecomDepartmentClient 部门处理模块,具有增删改查部门功能

  • WecomMessageClient 消息发送模块,兼容多种方式发送消息

  • WecomUsersClient 用户管理模块,具有查询信息、学工号转换功能(不通用)

  • HttpxRequest Httpx请求库封装,具有GETPOST方法

基于以上模块,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库封装

使用方法

  1. 安装wecom-sdk
pip install wecom-sdk
  1. 在项目中引用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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wecom_sdk-1.0.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

wecom_sdk-1.0.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

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

Hashes for wecom_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 38456e35f8789968c4c78783295298b89002ff19472504e214ec3f381ead908c
MD5 7dde46b2ae158bdc5a3bb90c2e909c39
BLAKE2b-256 4ba416e280930b7570384f03f0e0e55a746aed3293275e6c4ea259c635778aa6

See more details on using hashes here.

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

Hashes for wecom_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0636c47fc6850ef2f6605e43893da8a8af7f515d3aae63ede52b13a7b88c3cb5
MD5 6cb3ce6ec1ae2ba126bdf868eed4a926
BLAKE2b-256 cbd623f22b650991bc5eaba68d350b593ef89c714849d7930112ee6fb43c1880

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page