Skip to main content

以个人身份操作飞书消息、文档、多维表格、通讯录的 Python 工具库

Project description

feishu-operator

个人身份user_access_token)操作飞书的 Python 工具库与 CLI。

支持:消息收发、文档与 Wiki、多维表格、通讯录、云盘、日历、妙记、任务、邮箱。


安装

pip install feishu-operator
# 或使用 uv
uv add feishu-operator

快速开始

# 首次授权(打开浏览器完成飞书 OAuth)
feishu-operator auth login

# 查看授权状态
feishu-operator auth status

# 发送私信
feishu-operator message send --to ou_xxx --text "Hello!"

# 查看收件箱
feishu-operator mail list

环境变量

变量 说明 默认值
FEISHU_SERVICE_URL ChatGPT 服务端地址 https://it.kxxxl.com
FEISHU_TOKEN_DIR token 缓存目录 ~/.config/feishu-operator
FEISHU_USER_TOKEN 直接传入 token,跳过本地缓存

FEISHU_APP_ID / FEISHU_APP_SECRET 不在客户端配置 。所有飞书 OAuth 凭证由服务端持有和管理,客户端零凭证。


认证流程

sequenceDiagram
    participant C as "客户端 (feishu-operator)"
    participant S as "服务端 (ChatGPT)"
    participant F as "飞书 OAuth"

    C->>S: POST /webhook/auth/session
    S-->>C: session_id + auth_url
    C->>F: 打开浏览器,用户授权
    F->>S: 回调 /webhook/oauth?code=xxx
    S->>F: 换取 user_access_token
    S-->>S: 存入 session(含 scopes)
    loop "轮询"
        C->>S: GET /webhook/auth/session/{id}
        S-->>C: status=done, token, scopes
    end
    C-->>C: 缓存至 credentials.json

token 缓存在本地 ~/.config/feishu-operator/credentials.json(权限 0600)。临近过期自动刷新,无需重复授权。


功能一览

模块 已实现功能 所需权限
消息 发送、回复、撤回、获取单条、群聊历史 im:message
文档 创建、获取元信息、读取正文 docx:document
Wiki 列出空间、列出节点、获取节点、创建节点、移动文档 wiki:wiki
多维表格 创建应用、获取应用、列出表格、记录增删改查 bitable:app
通讯录 获取用户信息、获取部门成员 contact:user.base:readonly
云盘 列目录、上传、下载、移动、复制、删除、创建文件夹 drive:drive drive:file
日历 获取主日历、列出日程、创建/更新/删除日程 calendar:calendar:readonly
妙记 获取详情、获取转写文字、获取统计信息(只读) minutes:minutes:readonly
任务 列出清单、列出任务、创建/获取/更新/完成/删除任务 task:task:read task:task:write
邮箱 列出邮件、获取邮件、发送邮件 mail:user_mailbox.message:readonly mail:user_mailbox.message:send

已知限制

限制 原因
无法列出私聊(p2p)历史消息 飞书 API 不支持 user token 读取 p2p 消息列表
无法按姓名搜索用户 search/v1/user 不支持 user token
无法获取无权限的部门列表 需要管理员权限
妙记为只读 飞书不提供 user token 写入妙记的接口
日历为只读 应用后台仅开通 calendar:calendar:readonly

模块结构

src/feishu_operator/
├── __init__.py          # 公开 API
├── _client.py           # lark.Client 单例
├── _credentials.py      # token 本地持久化
├── _scopes.py           # 权限定义与 InsufficientScopeError
├── _cli.py              # Click CLI 入口
├── auth.py              # OAuth 2.0 + PKCE 认证 & token 管理
├── message.py           # 消息操作
├── document.py          # 文档 & Wiki 操作
├── bitable.py           # 多维表格操作
├── contact.py           # 通讯录操作
├── drive.py             # 云盘文件管理
├── calendar.py          # 日历 & 日程
├── minutes.py           # 妙记(只读)
├── task.py              # 任务 v2
└── mail.py              # 个人邮箱收发

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

feishu_operator-0.1.0.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

feishu_operator-0.1.0-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file feishu_operator-0.1.0.tar.gz.

File metadata

  • Download URL: feishu_operator-0.1.0.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.12

File hashes

Hashes for feishu_operator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 877dbcf6698635d6cc317f81cf45a0c645848c89065604c32f0290f2fb2f430a
MD5 f7056104417e5cf303e4bf8cae299452
BLAKE2b-256 1eff6788dd96c047551b7737ea0a7bc4b0fc60bbc802b174624328cc9eb3e343

See more details on using hashes here.

File details

Details for the file feishu_operator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for feishu_operator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09fb90c51e344f62b06854fdf7c9f3e1bede80f13820ed813d60bf6711cda298
MD5 fcd9624c60b79dbd273ec9e3c175a7ab
BLAKE2b-256 2a191db2086c5108d99f7a8a67fd2d00c28f0da7f7d8cc892a22296dfcd589c0

See more details on using hashes here.

Supported by

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