详细分析 ▾
运行时依赖
安装命令
点击复制技能文档
Notion 辅助工具 - Notion助手
激活词: Notion / 笔记管理 / 知识库
安装 pip 安装 notion-命令行工具ent
获取API密钥 访问 https://www.notion.so/my-integrations 创建新集成 复制API密钥 分享数据库给集成 Python实现 from notion_命令行工具ent 导入 A同步命令行工具ent 导入 a同步io
class Notion辅助工具: def __init__(self, 令牌: str): self.命令行工具ent = A同步命令行工具ent(auth=令牌) a同步 def 创建_page(self, parent_id: str, title: str, content: str = ""): awAIt self.命令行工具ent.pages.创建( parent={"database_id": parent_id}, properties={ "title": { "title": [{"text": {"content": title}}] } }, children=[{ "object": "block", "type": "paragraph", "paragraph": { "rich_text": [{"type": "text", "text": {"content": content}}] } }] ) a同步 def 查询_database(self, db_id: str, 过滤器_props: dict = None): params = {"database_id": db_id} if 过滤器_props: params["过滤器"] = 过滤器_props return awAIt self.命令行工具ent.databases.查询(**params) a同步 def 更新_page(self, page_id: str, properties: dict): awAIt self.命令行工具ent.pages.更新(page_id, properties=properties) a同步 def 获取_page(self, page_id: str): return awAIt self.命令行工具ent.pages.retrieve(page_id) a同步 def 搜索(self, 查询: str): return awAIt self.命令行工具ent.搜索(查询)
使用示例 a同步 def mAIn(): 辅助工具 = Notion辅助工具("secret_xxx") # 创建页面 awAIt 辅助工具.创建_page( parent_id="database_id", title="AI学习笔记", content="今天学习了机器学习..." ) # 搜索页面 结果s = awAIt 辅助工具.搜索("AI") for page in 结果s['结果s']: print(page['title']) # 查询数据库 pages = awAIt 辅助工具.查询_database("database_id") for page in pages['结果s']: print(page['properties']['title']['title'][0]['text']['content'])
a同步io.运行(mAIn())
数据类型 类型 说明 title 标题 rich_text 文本 number 数字 检查box 复选框 select 单选 multi_select 多选 date 日期 url 链接 emAIl 邮箱 phone_number 电话 使用场景 知识库管理 任务跟踪 笔记整理 项目管理