feishu-docx-python
2
总安装量
2
周安装量
#70324
全站排名
安装命令
npx skills add https://github.com/tkorays/zero-skills --skill feishu-docx-python
Agent 安装分布
amp
2
gemini-cli
2
github-copilot
2
codex
2
kimi-cli
2
cursor
2
Skill 文档
Feishu Document (docx) Python SDK
Use lark_oapi package to create and manipulate Feishu (é£ä¹¦) cloud documents.
Quick Start
pip install lark-oapi
Core Workflow
1. Initialize Client
import lark_oapi as lark
from lark_oapi.api.docx.v1 import *
client = lark.Client.builder() \
.app_id("your_app_id") \
.app_secret("your_app_secret") \
.build()
2. Create Document
request = CreateDocumentRequest.builder() \
.request_body(CreateDocumentRequestBody.builder()
.folder_token("fldxxxxxxxx")
.title("ææ¡£æ é¢")
.build()) \
.build()
response = client.docx.v1.document.create(request)
document_id = response.data.document.document_id
3. Add Blocks
Critical: Must set BOTH block_type AND content method.
from lark_oapi.api.docx.v1.model import *
# Define constants (SDK doesn't include these)
class BlockType:
TEXT = 2; HEADING1 = 3; HEADING2 = 4; HEADING3 = 5
BULLET = 13; ORDERED = 14; CODE = 17; QUOTE = 18; DIVIDER = 19
# Helper: create text element
def text(content: str) -> TextElement:
return TextElement.builder().text_run(
TextRun.builder().content(content).build()
).build()
# Create block: heading + paragraph
blocks = [
Block.builder()
.block_type(BlockType.HEADING1)
.heading1(Text.builder().elements([text("æ é¢")]).build())
.build(),
Block.builder()
.block_type(BlockType.TEXT)
.text(Text.builder().elements([text("æ£æå
容")]).build())
.build(),
]
# Add to document root
request = CreateDocumentBlockChildrenRequest.builder() \
.document_id(document_id) \
.block_id(document_id) \
.request_body(CreateDocumentBlockChildrenRequestBody.builder()
.children(blocks).index(-1).build()) \
.build()
client.docx.v1.document_block_children.create(request)
Key Points
- block_type is required: Always set BOTH
.block_type()AND content method (.heading1(),.text(), etc.) - Root block: Use
document_idasblock_idto add to document root - folder_token: Required for creating documents – get from drive API
- Error handling: Check
response.success()before accessing data
References
- Block types: See block-types.md for complete type constants and builder methods
- API methods: See api-methods.md for all available methods
- Error codes: See error-codes.md for complete error codes and solutions
- Helper functions: See helpers.py for reusable code