Dropbox
Dropbox 是一个文件托管服务,它将所有内容——传统文件、云内容和网页快捷方式——集中在一个地方。
本笔记本介绍了如何从Dropbox加载文档。除了常见的文件类型如文本和PDF文件外,它还支持Dropbox Paper文件。
先决条件
- 创建一个Dropbox应用。
- 给应用程序这些范围权限:
files.metadata.read
和files.content.read
。 - 生成访问令牌:https://www.dropbox.com/developers/apps/create。
pip install dropbox
(需要pip install "unstructured[pdf]"
用于 PDF 文件类型).
说明
`DropboxLoader` 需要你创建一个 Dropbox 应用并生成一个访问令牌。这可以通过 https://www.dropbox.com/developers/apps/create 完成。你还需要安装 Dropbox Python SDK(pip install dropbox)。
DropboxLoader 可以从一系列 Dropbox 文件路径或单个 Dropbox 文件夹路径加载数据。这两个路径都应相对于与访问令牌关联的 Dropbox 账户的根目录。
pip install dropbox
Requirement already satisfied: dropbox in /Users/rbarragan/.local/share/virtualenvs/langchain-kv0dsrF5/lib/python3.11/site-packages (11.36.2)
Requirement already satisfied: requests>=2.16.2 in /Users/rbarragan/.local/share/virtualenvs/langchain-kv0dsrF5/lib/python3.11/site-packages (from dropbox) (2.31.0)
Requirement already satisfied: six>=1.12.0 in /Users/rbarragan/.local/share/virtualenvs/langchain-kv0dsrF5/lib/python3.11/site-packages (from dropbox) (1.16.0)
Requirement already satisfied: stone>=2 in /Users/rbarragan/.local/share/virtualenvs/langchain-kv0dsrF5/lib/python3.11/site-packages (from dropbox) (3.3.1)
Requirement already satisfied: charset-normalizer<4,>=2 in /Users/rbarragan/.local/share/virtualenvs/langchain-kv0dsrF5/lib/python3.11/site-packages (from requests>=2.16.2->dropbox) (3.2.0)
Requirement already satisfied: idna<4,>=2.5 in /Users/rbarragan/.local/share/virtualenvs/langchain-kv0dsrF5/lib/python3.11/site-packages (from requests>=2.16.2->dropbox) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/rbarragan/.local/share/virtualenvs/langchain-kv0dsrF5/lib/python3.11/site-packages (from requests>=2.16.2->dropbox) (2.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /Users/rbarragan/.local/share/virtualenvs/langchain-kv0dsrF5/lib/python3.11/site-packages (from requests>=2.16.2->dropbox) (2023.7.22)
Requirement already satisfied: ply>=3.4 in /Users/rbarragan/.local/share/virtualenvs/langchain-kv0dsrF5/lib/python3.11/site-packages (from stone>=2->dropbox) (3.11)
Note: you may need to restart the kernel to use updated packages.
from langchain_community.document_loaders import DropboxLoader
API Reference:DropboxLoader
# Generate access token: https://www.dropbox.com/developers/apps/create.
dropbox_access_token = "<DROPBOX_ACCESS_TOKEN>"
# Dropbox root folder
dropbox_folder_path = ""
loader = DropboxLoader(
dropbox_access_token=dropbox_access_token,
dropbox_folder_path=dropbox_folder_path,
recursive=False,
)
documents = loader.load()
File /JHSfLKn0.jpeg could not be decoded as text. Skipping.
File /A REPORT ON WILES’ CAMBRIDGE LECTURES.pdf could not be decoded as text. Skipping.
for document in documents:
print(document)