跳转到主要内容

未提供项目描述

项目描述

notion-haystack:将Notion页面导出到Haystack文档

此Python包允许您通过提供Notion API令牌轻松将您的Notion页面导出到Haystack文档。

由于Notion API存在一些速率限制,此组件将自动重试失败的请求,并在重试之前等待速率限制重置。这在导出大量页面时特别有用。此外,此组件使用asyncio并行发送请求,这可以显著加快导出过程。

安装

pip install notion-haystack

使用方法

要使用此包,您需要一个Notion API令牌。您可以按照Notion文档中概述的步骤创建一个新的Notion集成,将其连接到您的页面,并获取您的API令牌。

要使您的Notion集成能够在特定页面及其Notion中的子页面上工作,请确保在页面的“连接”设置中启用它。

以下是最小示例,展示了如何将一系列页面导出到Haystack文档

from notion_haystack import NotionExporter

exporter = NotionExporter(api_token="<your-token>")
exported_pages = exporter.run(page_ids=["<list-of-page-ids>"])

# exported_pages will be a list of Haystack Documents where each Document corresponds to a Notion page

以下示例显示了如何在索引管道中使用NotionExporter

from haystack import Pipeline

from notion_haystack import NotionExporter
from haystack.components.preprocessors import DocumentSplitter
from haystack.components.writers import DocumentWriter
from haystack.document_stores import InMemoryDocumentStore

document_store = InMemoryDocumentStore()
exporter = NotionExporter(api_token='YOUR_NOTION_API_KEY')
splitter = DocumentSplitter()
writer = DocumentWriter(document_store=document_store)

indexing_pipeline = Pipeline()
indexing_pipeline.add_component(instance=exporter, name="exporter")
indexing_pipeline.add_component(instance=splitter, name="splitter")
indexing_pipeline.add_component(instance=writer, name="writer")

indexing_pipeline.connect("exporter.documents", "splitter.documents")
indexing_pipeline.connect("splitter", "writer")

indexing_pipeline.run(data={"exporter": {"page_ids": ["your_page_id"] }})
# The pages will now be indexed in the document store

NotionExporter类接受以下参数

  • api_token:您的Notion API令牌。您可以在Notion文档中找到有关获取API令牌的信息
  • export_child_pages:是否递归地导出提供的页面ID的所有子页面。默认为False
  • extract_page_metadata:是否从页面提取元数据并将其添加到Markdown的前置文件中。提取的元数据包括标题、作者、路径、URL、最后编辑者和页面最后编辑时间。默认值为False
  • exclude_title_containing:如果指定,则包含此字符串的标题的页面将被排除。例如,可以用于排除已存档的页面。默认值为None

NotionExporter.run方法接受以下参数

  • page_ids:要导出的页面ID列表。如果export_child_pagesTrue,则这些页面的所有子页面也将被导出。

项目详情


下载文件

下载适用于您平台的应用程序文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

notion_haystack-1.0.0.tar.gz (8.4 kB 查看散列)

上传时间 源代码

构建分发

notion_haystack-1.0.0-py3-none-any.whl (8.5 kB 查看散列)

上传时间 Python 3

由以下提供支持