documents
feishu.docx.documents
¶
DocxNamespace
¶
Bases: Namespace
新版文档(Docx)接口命名空间。
封装飞书云文档(Docx)相关的服务端接口,包括创建文档、获取文档元信息与纯文本内容, 以及获取、追加、更新文档块(block)等能力。文档由若干块组成,块是文档内容的最小结构单元。
通常无需直接实例化,应通过客户端的 client.docx 访问。
飞书文档
源代码位于: feishu/docx/documents.py
| Python | |
|---|---|
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
append_blocks
async
¶
append_blocks(document_id: str, children: list[dict[str, Any]], *, block_id: str | None = None, index: int | None = None) -> NestedDict
在指定块下创建子块。
将 children 作为子块追加到目标块下;block_id 为空时以文档根块(即 document_id)
为父块。index 控制插入位置(自 0 起),为空时追加到末尾。仅将显式传入的字段写入请求体。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
文档的唯一标识。 |
必需 |
|
list[dict[str, Any]]
|
待创建的子块对象列表,每个元素描述一个块(含 |
必需 |
|
str | None
|
父块的唯一标识;为空时使用文档根块 |
None
|
|
int | None
|
插入位置(自 0 起);为空时追加到子块末尾。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
NestedDict
|
创建结果数据,含新建的 |
引发:
| 类型 | 描述 |
|---|---|
FeishuError
|
请求失败或返回错误码时抛出。 |
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/docx/documents.py
batch_update_blocks
async
¶
batch_update_blocks(document_id: str, requests: list[dict[str, Any]]) -> NestedDict
批量更新文档块。
在一次请求中对多个块执行更新操作,requests 为更新操作列表,每个元素与
feishu.docx.documents.DocxNamespace.patch_block 的 update 同构,并额外携带
其作用的 block_id。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
文档的唯一标识。 |
必需 |
|
list[dict[str, Any]]
|
更新操作列表,每个元素形如
|
必需 |
返回:
| 类型 | 描述 |
|---|---|
NestedDict
|
批量更新结果数据,含更新后的 |
引发:
| 类型 | 描述 |
|---|---|
FeishuError
|
请求失败或返回错误码时抛出。 |
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/docx/documents.py
create
async
¶
create(title: str, *, folder_token: str | None = None) -> NestedDict
创建文档。
在指定文件夹(或用户云空间根目录)下创建一篇新的空白文档。仅将显式传入的字段 写入请求体,未设置的字段会被省略。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
文档标题。 |
必需 |
|
str | None
|
目标文件夹 token;为空时创建在云空间根目录下。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
NestedDict
|
创建后的文档数据,含 |
引发:
| 类型 | 描述 |
|---|---|
FeishuError
|
请求失败或返回错误码时抛出。 |
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/docx/documents.py
get
async
¶
get(document_id: str) -> NestedDict
获取文档基本信息。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
文档的唯一标识。 |
必需 |
返回:
| 类型 | 描述 |
|---|---|
NestedDict
|
文档元信息数据,含 |
引发:
| 类型 | 描述 |
|---|---|
FeishuError
|
请求失败或返回错误码时抛出。 |
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/docx/documents.py
get_block
async
¶
get_block(document_id: str, block_id: str) -> NestedDict
获取指定块的内容。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
文档的唯一标识。 |
必需 |
|
str
|
块的唯一标识。 |
必需 |
返回:
| 类型 | 描述 |
|---|---|
NestedDict
|
块数据,含 |
引发:
| 类型 | 描述 |
|---|---|
FeishuError
|
请求失败或返回错误码时抛出。 |
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/docx/documents.py
list_blocks
async
¶
list_blocks(document_id: str, *, page_size: int = 500, max_items: int | None = None) -> list[NestedDict]
获取文档所有块。
自动翻页并将各页结果拼接为单个列表返回,返回的块按文档顺序排列(含各级嵌套块)。
page_size 会被限制在 [feishu.docx.documents.MAX_BLOCK_PAGE_SIZE][] 以内。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
文档的唯一标识。 |
必需 |
|
int
|
每页条数,默认为 500,超过上限时按上限截断。 |
500
|
|
int | None
|
最多返回的条数;为空表示返回全部。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
list[NestedDict]
|
文档块数据列表,每个元素含 |
引发:
| 类型 | 描述 |
|---|---|
FeishuError
|
请求失败或返回错误码时抛出。 |
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/docx/documents.py
patch_block
async
¶
patch_block(document_id: str, block_id: str, update: dict[str, Any]) -> NestedDict
更新指定块的内容。
update 是描述更新操作的请求体,原样作为 JSON 发送,常见键包括
update_text_elements、update_text_style、update_table_property 等。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
文档的唯一标识。 |
必需 |
|
str
|
待更新块的唯一标识。 |
必需 |
|
dict[str, Any]
|
更新操作请求体,例如 |
必需 |
返回:
| 类型 | 描述 |
|---|---|
NestedDict
|
更新后的块数据及文档 |
引发:
| 类型 | 描述 |
|---|---|
FeishuError
|
请求失败或返回错误码时抛出。 |
示例:
| Python Console Session | |
|---|---|
源代码位于: feishu/docx/documents.py
raw_content
async
¶
raw_content(document_id: str, *, lang: int | None = None) -> str
获取文档纯文本内容。
返回文档去除格式后的纯文本,便于做检索、摘要等文本处理。lang 用于控制
文档中 @ 提及(如人员、文档)等内容的展示语言。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
|
str
|
文档的唯一标识。 |
必需 |
|
int | None
|
内容语言, |
None
|
返回:
| 类型 | 描述 |
|---|---|
str
|
文档的纯文本内容字符串(取自响应数据的 |
引发:
| 类型 | 描述 |
|---|---|
FeishuError
|
请求失败或返回错误码时抛出。 |
示例: