Reusable SDK for Feishu bot messaging, Bitable, Docx, and Drive permissions.
Project description
feishu-bot-sdk
面向飞书机器人的轻量 Python SDK,提供:
- 飞书 tenant token 获取与缓存
- 机器人文本消息发送
- Drive 权限授予(Bitable / Docx)
- CSV 导入多维表格(Bitable)
- Markdown 追加写入 Docx
- 同步 / 异步两套 API
安装
# pip
pip install feishu-bot-sdk
# uv
uv add feishu-bot-sdk
1 分钟上手(同步)
from feishu_bot_sdk import FeishuClient, FeishuConfig, BitableService, DocxService
config = FeishuConfig(
app_id="cli_xxx",
app_secret="xxx",
base_url="https://open.feishu.cn/open-apis",
doc_url_prefix="https://your-tenant.feishu.cn/docx",
doc_folder_token="fldcnxxx", # 可选
member_permission="edit", # view/edit/full_access
)
client = FeishuClient(config)
# 1) 发消息
client.send_text_message("ou_xxx", "open_id", "你好,来自 SDK")
# 2) CSV -> Bitable
bitable = BitableService(client)
app_token, app_url = bitable.create_from_csv("final.csv", "任务结果", "结果表")
bitable.grant_edit_permission(app_token, "ou_xxx", "open_id")
print(app_url)
# 3) Markdown -> Docx
docx = DocxService(client)
doc_id, doc_url = docx.create_document("任务报告")
docx.append_markdown(doc_id, "# 标题\n\n这是正文。")
docx.grant_edit_permission(doc_id, "ou_xxx", "open_id")
print(doc_url or doc_id)
异步用法
from feishu_bot_sdk import AsyncFeishuClient, AsyncBitableService, FeishuConfig
config = FeishuConfig(app_id="cli_xxx", app_secret="xxx")
client = AsyncFeishuClient(config)
bitable = AsyncBitableService(client)
await client.send_text_message("ou_xxx", "open_id", "hello async")
app_token, app_url = await bitable.create_from_csv("final.csv", "异步结果", "Sheet1")
await client.aclose()
核心对象
FeishuClient/AsyncFeishuClient:飞书 API 基础客户端BitableService/AsyncBitableService:多维表格能力DocxService/AsyncDocxService:文档能力DrivePermissionService/AsyncDrivePermissionService:权限授予
英文说明见 README_EN.md。
示例脚本
uv run python examples/sync_demo.py --receive-id ou_xxx --receive-id-type open_id
uv run python examples/async_demo.py --receive-id ou_xxx --receive-id-type open_id
可选参数:
--csv final.csv:演示 CSV 导入 Bitable--markdown result.md:演示 Markdown 追加到 Docx
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
feishu_bot_sdk-0.1.0.tar.gz
(11.0 kB
view details)
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 feishu_bot_sdk-0.1.0.tar.gz.
File metadata
- Download URL: feishu_bot_sdk-0.1.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4eecb8b68245f4bcdbcba6b8ac20cdcba60c4a4d3213afd534305b686c76af0
|
|
| MD5 |
248dbe8a34be6bcfc292d9ce83aa46a1
|
|
| BLAKE2b-256 |
a94953e29f5e3544000f46ea5a41ac288e6e8ce49391287da19dbbc6f1749855
|
File details
Details for the file feishu_bot_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: feishu_bot_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89628270e13f7e9dc467ddf864c7313fedb2b27871a146fba3a0ad12e8bd3435
|
|
| MD5 |
584faa52a0b04709a3d541c1adb3e091
|
|
| BLAKE2b-256 |
0156354451baeec3ad350d067e97041a17d453b905ca69d0ea2f4cf522d727a4
|