Skip to main content
Open In ColabOpen on GitHub

Airbyte Hubspot(已弃用)

注意:AirbyteHubspotLoader 已弃用。请改用 AirbyteLoader

LangChain AI开发框架是一个用于从API、数据库和文件到数据仓库和湖的ELT管道的数据集成平台。它拥有最大的ELT连接器目录,可以连接到数据仓库和数据库。

此加载器将 Hubspot 连接器暴露为文档加载器,允许您将各种 Hubspot 对象作为文档加载。

安装

首先,你需要安装LangChain Python 包。

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

示例

检查Airbyte 文档页面以了解如何配置读取器。 config 对象应遵循的 JSON schema 可在 Github 上找到: https://github.com/airbytehq/airbyte/blob/master/airbyte-integrations/connectors/source-hubspot/source_hubspot/spec.yaml.

The general shape looks like this:

{
"start_date": "<date from which to start retrieving records from in ISO format, e.g. 2020-10-20T00:00:00Z>",
"credentials": {
"credentials_title": "Private App Credentials",
"access_token": "<access token of your private app>"
}
}

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

from langchain_community.document_loaders.airbyte import AirbyteHubspotLoader

config = {
# your hubspot configuration
}

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

现在您可以通过常规方式加载文档

docs = loader.load()

As load 返回一个列表,它将在所有文档加载完成后才会阻塞。为了更好地控制这个过程,你也可以使用 lazy_load 方法,该方法返回的是一个迭代器:

docs_iterator = loader.lazy_load()

请记住,默认情况下页面内容为空,元数据对象包含所有记录的信息。要处理文档,请创建一个从基加载器继承的类,并自己实现_handle_records方法:

from langchain_core.documents import Document


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


loader = AirbyteHubspotLoader(
config=config, record_handler=handle_record, stream_name="products"
)
docs = loader.load()
API 参考:文档

增量加载

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

要利用这一点,请存储加载器的last_state属性,并在再次创建加载器时传递该值。这将确保仅加载新记录。

last_state = loader.last_state  # store safely

incremental_loader = AirbyteHubspotLoader(
config=config, stream_name="products", state=last_state
)

new_docs = incremental_loader.load()