Skip to main content

Box

Box is the Intelligent Content Cloud, a single platform that enables organizations to fuel collaboration, manage the entire content lifecycle, secure critical content, and transform business workflows with enterprise AI. Founded in 2005, Box simplifies work for leading global organizations, including AstraZeneca, JLL, Morgan Stanley, and Nationwide.

In this package, we make available a number of ways to include Box content in your AI workflows.

Installation and setupโ€‹

pip install -U langchain-box

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

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,
...

If you wish to use OAuth2 with the authorization_code flow, please use BoxAuthType.TOKEN with the token you have acquired.

Document Loadersโ€‹

BoxLoaderโ€‹

See usage example

from langchain_box.document_loaders import BoxLoader

Retrieversโ€‹

BoxRetrieverโ€‹

See usage example

from langchain_box.retrievers import BoxRetriever


Was this page helpful?