Auto backup \2026-\04-\20

This commit is contained in:
Ubuntu
2026-07-29 16:00:02 +08:00
parent 32289a0f30
commit abd686d096
3 changed files with 63 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
---
name: notion-api
description: 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
```bash
pip install notion-client
```
Set environment variables: `NOTION_API_KEY` (integration token), `NOTION_PAGE_ID` (parent page ID).
## Create Page
```python
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
```python
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`:
```python
{"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` (with `language`), `bulleted_list_item`, `numbered_list_item`
- `column_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`.