Notion Workspace
Automate your Notion workspace from the command line. Query and update databases, create and archive pages, append rich content blocks, and search across your entire workspace — all via the official Notion API with a single integration token.
Setup
CODEBLOCK0
Get your integration token: Notion → Settings → Connections → Develop or manage integrations → New integration.
Then share your database/pages with that integration.
Commands / Usage
CODEBLOCK1
Requirements
- - Python 3.8+
- INLINECODE0 (
pip install requests) - INLINECODE2 environment variable
- INLINECODE3 environment variable (optional, for default DB commands)
Notion 工作空间
通过命令行自动化你的 Notion 工作空间。查询和更新数据库、创建和归档页面、追加富内容块,以及在整个工作空间中搜索——全部通过官方 Notion API 和一个集成令牌完成。
设置
bash
export NOTIONAPIKEY=secret_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export NOTIONDATABASEID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # 可选的默认数据库
获取你的集成令牌:Notion → 设置 → 连接 → 开发或管理集成 → 新建集成。
然后将你的数据库/页面与该集成共享。
命令 / 用法
bash
── 数据库 ───────────────────────────────────────────
查询数据库(默认使用 NOTIONDATABASEID)
python3 scripts/notion_workspace.py db-query
python3 scripts/notion_workspace.py db-query --db-id abc123...
带筛选条件查询
python3 scripts/notion_workspace.py db-query --filter-prop 状态 --filter-value 进行中
在数据库中创建新条目(页面)
python3 scripts/notion_workspace.py db-create --title 我的任务 --props {状态: 待办, 优先级: 高}
更新数据库条目
python3 scripts/notion_workspace.py db-update --page-id def456... --props {状态: 已完成}
── 页面 ───────────────────────────────────────────────
创建独立页面(在父页面下)
python3 scripts/notion_workspace.py page-create --parent-id ghi789... --title 会议记录 --content 今天我们讨论了...
读取页面(元数据 + 内容预览)
python3 scripts/notion_workspace.py page-read --page-id def456...
更新页面标题/属性
python3 scripts/notion_workspace.py page-update --page-id def456... --title 更新后的标题
归档(软删除)页面
python3 scripts/notion_workspace.py page-archive --page-id def456...
── 块 ──────────────────────────────────────────────
获取页面或块的子块
python3 scripts/notion_workspace.py blocks-get --block-id def456...
追加段落块
python3 scripts/notion_workspace.py blocks-append --block-id def456... --text 此处为新的段落内容
追加标题
python3 scripts/notion
workspace.py blocks-append --block-id def456... --text 章节标题 --type heading2
追加待办事项
python3 scripts/notion
workspace.py blocks-append --block-id def456... --text 完成此任务 --type todo
追加无序列表项
python3 scripts/notion
workspace.py blocks-append --block-id def456... --text 列表要点 --type bulletedlist_item
追加代码块
python3 scripts/notion_workspace.py blocks-append --block-id def456... --text print(hello) --type code --language python
── 搜索 ──────────────────────────────────────────────
搜索整个工作空间
python3 scripts/notion_workspace.py search --query 项目路线图
仅搜索页面
python3 scripts/notion_workspace.py search --query 会议记录 --filter page
仅搜索数据库
python3 scripts/notion_workspace.py search --query 任务 --filter database
要求
- - Python 3.8+
- requests(pip install requests)
- NOTIONAPIKEY 环境变量
- NOTIONDATABASEID 环境变量(可选,用于默认数据库命令)