Skip to main content

wecom-lite

轻量级企业微信消息发送库,支持发送文本、图片、文件、文本卡片和Markdown等消息。

安装

pip install wecom-lite

使用示例

from wecom_lite import WeChat

# 首先创建 .env 文件配置您的企业微信信息
# 参见 .env.example

wechat = WeChat()
wechat.send_text("测试消息")

配置

创建 .env 文件,包含以下内容:

WECOM_CORP_ID = '您的企业ID'
WECOM_AGENT_ID = '应用ID'
WECOM_SECRET = '应用Secret'
WECOM_TOUSER = '接收消息的用户ID'

功能特点

  • 支持多种消息类型:
    • 文本消息
    • 图片消息
    • 文件消息
    • 文本卡片
    • Markdown
  • 自动处理访问令牌
  • 简单易用的API
  • 内置日志记录功能,记录所有发送的消息及返回结果

日志功能

wecom-lite 自动记录所有发送消息的详情和返回结果。日志文件存储在项目根目录的 logs 文件夹中:

  • wecom.log: 包含基本的发送记录
  • wecom_details_YYYYMMDD.log: 包含每天详细的发送记录,包括完整的消息内容和返回结果

示例日志内容:

2023-05-08 10:58:25,123 - INFO - 发送text消息成功: {"timestamp": "2023-05-08 10:58:25", "msg_type": "text", "content": "测试消息", "result": {"errcode": 0, "errmsg": "ok"}, "touser": "UserID", "agent_id": 1000001}

开发

安装开发依赖

pip install -e ".[dev]"

运行测试

pytest

许可

MIT

Metadata

Release files for wecom-lite 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for wecom-lite 0.1.5
File Interpreter ABI Platform
wecom_lite-0.1.5-py3-none-any.whl Python 3 none any Details

Release files / wecom_lite-0.1.5-py3-none-any.whl

Download URL wecom_lite-0.1.5-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef1764403da16685c041c7070c44f953bd5ccc40d5cf8a24cc92d5d08b4b582f
BLAKE2b-256 checksum
How to use checksums
6281920d090791c05abade0c27b98cc75393a815a6bbae151127de47eaf6b096
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.17

Release history Release notifications | RSS feed

This release

0.1.5 This release

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page