Metadata-Version: 2.4
Name: pywecom-server
Version: 3.0.0
Summary: 企业微信API服务端SDK，提供企业微信API的基础服务封装，支持同步和异步两种模式。
Home-page: https://gitee.com/guolei19850528/pywecom_server
Author: guolei
Author-email: 174000902@qq.com
License: MIT
Keywords: 企业微信 服务端SDK 素材上传 应用消息发送
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx
Requires-Dist: jsonschema
Requires-Dist: decorator
Requires-Dist: jsonpath-ng
Requires-Dist: diskcache
Requires-Dist: redis
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# pywecom-server

企业微信API服务端SDK，提供企业微信API的基础服务封装，支持同步和异步两种模式。

## 功能特性

- **Access Token管理**：自动获取和缓存Access Token，支持diskcache和redis缓存后端
- **消息发送**：支持多种消息类型（文本、图片、语音、视频、文件、图文等）
- **素材上传**：支持媒体文件上传和图片上传
- **IP白名单查询**：获取API域名IP和回调IP列表
- **同步/异步支持**：所有API均提供同步和异步版本

## 安装

```bash
pip install pywecom-server
```

## 快速开始

### 同步模式

```python
from pywecom_server import Server, Sender, Uploader

# 初始化服务端
server = Server(
    corpid="your_corpid",
    corpsecret="your_corpsecret",
    agentid="your_agentid"
)

# 刷新Access Token
server.refresh_access_token()

# 发送文本消息
sender = Sender(
    corpid="your_corpid",
    corpsecret="your_corpsecret",
    agentid="your_agentid"
)
sender.refresh_access_token()

from pywecom_server.msgtypes import Text, TextContent

content = Text(text=TextContent(content="Hello, World!"))
result = sender.send_text(content)
```

### 异步模式

```python
import asyncio
from pywecom_server import Server, Sender


async def main():
    server = Server(
        corpid="your_corpid",
        corpsecret="your_corpsecret",
        agentid="your_agentid",
        use_async_client=True
    )

    await server.async_refresh_access_token()

    sender = Sender(
        corpid="your_corpid",
        corpsecret="your_corpsecret",
        agentid="your_agentid",
        use_async_client=True
    )
    await sender.async_refresh_access_token()

    from pywecom_server.msgtypes import Text, TextContent
    content = Text(text=TextContent(content="Hello, World!"))
    result = await sender.async_send_text(content)


asyncio.run(main())
```

### 使用缓存

```python
import diskcache
from pywecom_server import Server

cache = diskcache.Cache("./cache")
server = Server(
    corpid="your_corpid",
    corpsecret="your_corpsecret",
    agentid="your_agentid",
    cache_config={
        "instance": cache,
        "key": "my_cache_key",
        "expire": 7100
    }
)
server.refresh_access_token()
```

## 支持的消息类型

- `Text` - 文本消息
- `Image` - 图片消息
- `Voice` - 语音消息
- `Video` - 视频消息
- `File` - 文件消息
- `TextCard` - 文本卡片消息
- `News` - 图文消息
- `MpNews` - 图文消息（mpnews）
- `Markdown` - Markdown消息
- `MiniprogramNotice` - 小程序通知
- `TemplateCard` - 模板卡片消息

## API文档

### Server类

#### 方法

- `gettoken()` - 获取Access Token
- `get_api_domain_ip()` - 获取API域名IP列表
- `getcallbackip()` - 获取回调IP列表
- `refresh_access_token()` - 刷新Access Token
- `async_gettoken()` - 异步获取Access Token
- `async_get_api_domain_ip()` - 异步获取API域名IP列表
- `async_getcallbackip()` - 异步获取回调IP列表
- `async_refresh_access_token()` - 异步刷新Access Token

### Sender类

#### 方法

- `send_text(content)` - 发送文本消息
- `send_image(content)` - 发送图片消息
- `send_voice(content)` - 发送语音消息
- `send_video(content)` - 发送视频消息
- `send_file(content)` - 发送文件消息
- `send_textcard(content)` - 发送文本卡片消息
- `send_news(content)` - 发送图文消息
- `send_mpnews(content)` - 发送图文消息（mpnews）
- `send_markdown(content)` - 发送Markdown消息
- `send_miniprogram_notice(content)` - 发送小程序通知
- `send_template_card(content)` - 发送模板卡片消息

### Uploader类

#### 方法

- `upload(file_type, **kwargs)` - 上传媒体文件
- `uploadimg(**kwargs)` - 上传图片
- `async_upload(file_type, **kwargs)` - 异步上传媒体文件
- `async_uploadimg(**kwargs)` - 异步上传图片

## 依赖

- httpx >= 0.24.0
- jsonschema >= 4.0.0
- jsonpath-ng >= 1.5.3
- diskcache >= 5.0.0 (可选)
- redis >= 4.0.0 (可选)
- pydantic >= 2.0.0

## 许可证

MIT License

## 作者

guolei <174000902@qq.com>

## 项目主页

[https://github.com/guolei/pywecom_server](https://github.com/guolei/pywecom_server)
