1.8 KiB
1.8 KiB
name, description
| name | description |
|---|---|
| notion-api | Use Notion API Python SDK to create pages, append blocks, and manage content in Notion. Triggers on "Notion", "同步到Notion", "notion API". |
Notion API Python SDK
Create and populate Notion pages programmatically.
Setup
pip install notion-client
Set environment variables: NOTION_API_KEY (integration token), NOTION_PAGE_ID (parent page ID).
Create Page
from notion_client import NotionClient
import os
client = NotionClient(auth=os.environ["NOTION_API_KEY"])
page = client.pages.create(
parent={"page_id": os.environ["NOTION_PAGE_ID"], "type": "page_id"},
properties={
"title": [{"type": "text", "text": {"content": "Title"}}]
}
)
page_id = page["id"]
Append Blocks
client.blocks.children.append(block_id=page_id, children=[
{"type": "heading_2", "heading_2": {"rich_text": [{"type": "text", "text": {"content": "Section"}}]}},
{"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "Text."}}]}},
{"type": "code", "code": {"language": "python", "rich_text": [{"type": "text", "text": {"content": "code"}}]}},
])
Column Layout
Content goes in nested children of column/column_2 inside column_list:
{"type": "column_list", "column_list": {"children": [
{"type": "column", "column": {"children": [left_block]}},
{"type": "column", "column": {"children": [right_block]}},
]}}
Block Types
heading_1/2/3,paragraph,code(withlanguage),bulleted_list_item,numbered_list_itemcolumn_list/column,bookmark,divider,to_do,callout- Rich text:
{"type": "text", "text": {"content": "..."}, "annotations": {"bold": true}}
Database Pages
Properties must match the database schema exactly — unknown keys cause ValidationError.