跳转到主要内容

Airbyte Shopify (已弃用)

注意:此连接器特定的加载器已弃用。请改用 AirbyteLoader

Airbyte 是一个数据集成平台,用于从 API、数据库和文件到仓库和湖泊的 ELT 管道。它拥有最大的数据仓库和数据库 ELT 连接器目录。

此加载器将 Shopify 连接器公开为文档加载器,允许您将各种 Shopify 对象加载为文档。

安装

首先,您需要安装 airbyte-source-shopify python 包。

%pip install --upgrade --quiet  airbyte-source-shopify

示例

有关如何配置读取器的详细信息,请查看 Airbyte 文档页面。 config 对象应遵循的 JSON 架构可以在 Github 上找到:https://github.com/airbytehq/airbyte/blob/master/airbyte-integrations/connectors/source-shopify/source_shopify/spec.json

一般形状如下所示

{
"start_date": "<date from which to start retrieving records from in ISO format, e.g. 2020-10-20T00:00:00Z>",
"shop": "<name of the shop you want to retrieve documents from>",
"credentials": {
"auth_method": "api_password",
"api_password": "<your api password>"
}
}

默认情况下,所有字段都作为元数据存储在文档中,并且文本设置为空字符串。通过转换读取器返回的文档来构造文档的文本。

from langchain_community.document_loaders.airbyte import AirbyteShopifyLoader

config = {
# your shopify configuration
}

loader = AirbyteShopifyLoader(
config=config, stream_name="orders"
) # check the documentation linked above for a list of all streams

现在您可以像往常一样加载文档

docs = loader.load()

由于 load 返回一个列表,它将阻塞直到所有文档都加载完毕。为了更好地控制此过程,您还可以使用 lazy_load 方法,该方法返回一个迭代器

docs_iterator = loader.lazy_load()

请记住,默认情况下页面内容为空,并且元数据对象包含记录中的所有信息。要以不同的方式创建文档,请在创建加载器时传入 record_handler 函数

from langchain_core.documents import Document


def handle_record(record, id):
return Document(page_content=record.data["title"], metadata=record.data)


loader = AirbyteShopifyLoader(
config=config, record_handler=handle_record, stream_name="orders"
)
docs = loader.load()
API 参考:Document

增量加载

某些流允许增量加载,这意味着源会跟踪同步的记录,并且不会再次加载它们。这对于具有大量数据并且经常更新的源非常有用。

要利用此功能,请存储加载器的 last_state 属性,并在再次创建加载器时传入它。这将确保仅加载新记录。

last_state = loader.last_state  # store safely

incremental_loader = AirbyteShopifyLoader(
config=config, stream_name="orders", state=last_state
)

new_docs = incremental_loader.load()

此页面是否对您有帮助?