Dropbox API Client
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
- breaking Starting with v12.0.0, the SDK no longer provides a hardcoded CA bundle. If your environment requires specific SSL certificate handling or you relied on the internal bundle, you may need to explicitly provide a `ca_certs` argument to the `Dropbox` client.
- gotcha Versions prior to v12.0.2 had incorrect or overly strict dependency pinning for `requests` and `urllib3`, which could lead to conflicts with other libraries in your environment. These issues were resolved in v12.0.2.
- gotcha The `dropbox.Dropbox` client constructor expects a long-lived 'access token' (e.g., for OAuth2 or personal apps), not a short-lived 'authorization code'. Attempting to use an authorization code directly will result in an `AuthError`.
Install
-
pip install dropbox
Imports
- Dropbox
import dropbox dbx = dropbox.Dropbox(...)
- AuthError
from dropbox.exceptions import AuthError
- ApiError
from dropbox.exceptions import ApiError
Quickstart
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}")