未提供项目描述
项目描述
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_pages
为True
,则这些页面的所有子页面也将被导出。
项目详情
下载文件
下载适用于您平台的应用程序文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码分发
notion_haystack-1.0.0.tar.gz (8.4 kB 查看散列)
构建分发
关闭
notion_haystack-1.0.0.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 3e86e60040259390f31d7c2d47acd8c9856b37b611e1c07c140315140bee1ef8 |
|
MD5 | 640e208abc67206e6cb298df14294c25 |
|
BLAKE2b-256 | 4c07ee12199a77860a0c937c7a15bcb4ec96443e20b1441383799ddfd7f56091 |
关闭
notion_haystack-1.0.0-py3-none-any.whl 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | d554f8b1a04eacddc872240daad35faa05ed70990543a5ed6e744d4780387f5a |
|
MD5 | bd68f726669d12aa76f7bc7e4dd5e1f9 |
|
BLAKE2b-256 | 345427d483254f27ff5a755984850f3b9b17e00e2d4f9d8c4879c145f4439ce2 |