Dropbox API Client

12.0.2 · active · verified Thu Apr 09

The official Dropbox API Client for Python (v12.0.2) allows programmatic interaction with Dropbox services. It provides a comprehensive interface for file management, sharing, user account information, and more. The library maintains an active development cycle, with frequent updates often driven by API specification changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with the Dropbox API using an access token loaded from the `DROPBOX_ACCESS_TOKEN` environment variable and then list the contents of your Dropbox root folder.

import os
import dropbox
from dropbox.exceptions import AuthError, ApiError

DROPBOX_ACCESS_TOKEN = os.environ.get('DROPBOX_ACCESS_TOKEN', '')

if not DROPBOX_ACCESS_TOKEN:
    print("Error: DROPBOX_ACCESS_TOKEN environment variable not set.")
    print("Please set it to your Dropbox API access token.")
    exit(1)

try:
    # Initialize Dropbox client
    dbx = dropbox.Dropbox(DROPBOX_ACCESS_TOKEN)

    # Test connection by listing files in the root folder
    print("\nConnected to Dropbox. Listing root folder content...")
    response = dbx.files_list_folder('')
    
    for entry in response.entries:
        print(f"  {entry.name} ({type(entry).__name__})")

    print("\nSuccessfully listed folder content.")

except AuthError:
    print("Error: Invalid or expired access token. Please check DROPBOX_ACCESS_TOKEN.")
except ApiError as err:
    print(f"API Error: {err}")
except Exception as err:
    print(f"An unexpected error occurred: {err}")

view raw JSON →