Skip to main content

An integration package connecting Box and LangChain

Project description

langchain-box

This package contains the LangChain integration with Box. For more information about Box, check out our developer documentation.

Pre-requisites

In order to integrate with Box, you need a few things:

  • A Box instance — if you are not a current Box customer, sign up for a free dev account.
  • A Box app — more on how to create an app
  • Your app approved in your Box instance — This is done by your admin. The good news is if you are using a free developer account, you are the admin. Authorize your app

Installation

pip install -U langchain-box

Authentication

The box-langchain package offers some flexibility to authentication. The most basic authentication method is by using a developer token. This can be found in the Box developer console on the configuration screen. This token is purposely short-lived (1 hour) and is intended for development. With this token, you can add it to your environment as BOX_DEVELOPER_TOKEN, you can pass it directly to the loader, or you can use the BoxAuth authentication helper class.

We will cover passing it directly to the loader in the section below.

BoxAuth helper class

BoxAuth supports the following authentication methods:

  • Token — either a developer token or any token generated through the Box SDK
  • JWT with a service account
  • JWT with a specified user
  • CCG with a service account
  • CCG with a specified user

[!NOTE] If using JWT authentication, you will need to download the configuration from the Box developer console after generating your public/private key pair. Place this file in your application directory structure somewhere. You will use the path to this file when using the BoxAuth helper class.

For more information, learn about how to set up a Box application, and check out the Box authentication guide for more about our different authentication options.

Examples:

Token

from langchain_box.document_loaders import BoxLoader
from langchain_box.utilities import BoxAuth, BoxAuthType

auth = BoxAuth(
    auth_type=BoxAuthType.TOKEN,
    box_developer_token=box_developer_token
)

loader = BoxLoader(
    box_auth=auth,
    ...
)

JWT with a service account

from langchain_box.document_loaders import BoxLoader
from langchain_box.utilities import BoxAuth, BoxAuthType

auth = BoxAuth(
    auth_type=BoxAuthType.JWT,
    box_jwt_path=box_jwt_path
)

loader = BoxLoader(
    box_auth=auth,
    ...

JWT with a specified user

from langchain_box.document_loaders import BoxLoader
from langchain_box.utilities import BoxAuth, BoxAuthType

auth = BoxAuth(
    auth_type=BoxAuthType.JWT,
    box_jwt_path=box_jwt_path,
    box_user_id=box_user_id
)

loader = BoxLoader(
    box_auth=auth,
    ...

CCG with a service account

from langchain_box.document_loaders import BoxLoader
from langchain_box.utilities import BoxAuth, BoxAuthType

auth = BoxAuth(
    auth_type=BoxAuthType.CCG,
    box_client_id=box_client_id,
    box_client_secret=box_client_secret,
    box_enterprise_id=box_enterprise_id
)

loader = BoxLoader(
    box_auth=auth,
    ...

CCG with a specified user

from langchain_box.document_loaders import BoxLoader
from langchain_box.utilities import BoxAuth, BoxAuthType

auth = BoxAuth(
    auth_type=BoxAuthType.CCG,
    box_client_id=box_client_id,
    box_client_secret=box_client_secret,
    box_user_id=box_user_id
)

loader = BoxLoader(
    box_auth=auth,
    ...

Document Loaders

The BoxLoader class helps you get your unstructured content from Box in Langchain's Document format. You can do this with either a List[str] containing Box file IDs, or with a str containing a Box folder ID.

If getting files from a folder with folder ID, you can also set a Bool to tell the loader to get all sub-folders in that folder, as well.

:::info A Box instance can contain Petabytes of files, and folders can contain millions of files. Be intentional when choosing what folders you choose to index. And we recommend never getting all files from folder 0 recursively. Folder ID 0 is your root folder. :::

Load files

import os

from langchain_box.document_loaders import BoxLoader

os.environ["BOX_DEVELOPER_TOKEN"] = "df21df2df21df2d1f21df2df1"

loader = BoxLoader(
    box_file_ids=["12345", "67890"],
    character_limit=10000  # Optional. Defaults to no limit
)

docs = loader.lazy_load()

Load from folder

import os

from langchain_box.document_loaders import BoxLoader

os.environ["BOX_DEVELOPER_TOKEN"] = "df21df2df21df2d1f21df2df1"

loader = BoxLoader(
    box_folder_id="12345",
    recursive=False,  # Optional. return entire tree, defaults to False
    character_limit=10000  # Optional. Defaults to no limit
)

docs = loader.lazy_load()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_box-0.2.3.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

langchain_box-0.2.3-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file langchain_box-0.2.3.tar.gz.

File metadata

  • Download URL: langchain_box-0.2.3.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for langchain_box-0.2.3.tar.gz
Algorithm Hash digest
SHA256 d078afbddf7b199d0ef6dfe1abd6bfde4373dfa0bc4971e4bf8e7a292f5a96fd
MD5 bce32238ea7d15a7468b55c0458c4b09
BLAKE2b-256 b438b08e5475a81c98b6e92f875d20d6d968e35bdd1f2ec0e1a40c0521cbd0d9

See more details on using hashes here.

File details

Details for the file langchain_box-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_box-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 82599805699930379fa2c8944d9409b309673189621cba374feb8a8b7cbe0578
MD5 a6aadc6ac728dcea5819e6e247c25138
BLAKE2b-256 279ce5de43979d2b814e0eadecfdbcbec2cb8765c7d2bd3567bc8ac56a95bf8b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page