Box Python SDK

10.6.0 · active · verified Thu Apr 09

The `boxsdk` is the official Python SDK for integrating with the Box Content Cloud. The latest major versions (v10.x.x and above) are built entirely on an auto-generated package, `box_sdk_gen`, providing comprehensive API support and rapid updates. It supports Python 3.8 and above, with a release cadence of minor or patch releases every 2-3 months.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with a Developer Token and list the items in your Box root folder using the v10+ SDK's `box_sdk_gen` package. Ensure you replace 'YOUR_DEVELOPER_TOKEN' with an actual token or set the `BOX_DEVELOPER_TOKEN` environment variable.

import os
from box_sdk_gen import BoxClient, BoxDeveloperTokenAuth

# Get your Developer Token from the Box Developer Console for testing.
# It's recommended to use environment variables for sensitive information.
DEVELOPER_TOKEN = os.environ.get('BOX_DEVELOPER_TOKEN', 'YOUR_DEVELOPER_TOKEN')

def get_root_folder_items(token: str):
    if not token or token == 'YOUR_DEVELOPER_TOKEN':
        print("Please set the 'BOX_DEVELOPER_TOKEN' environment variable or replace 'YOUR_DEVELOPER_TOKEN' in the script.")
        return

    try:
        auth: BoxDeveloperTokenAuth = BoxDeveloperTokenAuth(token=token)
        client: BoxClient = BoxClient(auth=auth)

        # Get items in the root folder (folder ID '0')
        print("\nItems in your Box root folder:")
        for item in client.folders.get_folder_items('0').entries:
            print(f"- {item.name} ({item.type.value})")

    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == '__main__':
    get_root_folder_items(DEVELOPER_TOKEN)

view raw JSON →