Dropbox ships a preview Python SDK for API v2

Dropbox has released a preview build of its Python SDK for the company's API v2. The announcement follows the initial API v2 preview from earlier this spring, and gives Python developers a second language option alongside the existing SDK offerings.

The SDK is available now from both GitHub and PyPI. Once installed, Python applications can import the module with a standard import dropbox statement.

pip install dropbox

If you don't yet have an app registered for API access, you'll need to create one in the App Console. Select Dropbox API app and choose the appropriate permission level; the resulting app key must be used when making API v2 calls.

Note that both the SDK and API v2 are still in preview and may change in the coming months. Anything built on top of them should not be used in production.

Getting started with a linked account

To issue API requests, you first need a Dropbox instance. The SDK's constructor takes an access token for whatever account you want to link. If you're connecting your own account, you can generate a token from the App Console.

You can verify the linked account with a simple call:

dbx = dropbox.Dropbox('YOUR_ACCESS_TOKEN')
print(dbx.users_get_current_account())

Common file operations

With the client object in hand, you can start exercising the files endpoints. The SDK exposes several common operations:

List the contents of the root directory:

for entry in dbx.files_list_folder('').entries:
    print(entry.name)

Upload a file:

with open('file.txt', 'rb') as f:
    dbx.files_upload(f.read(), '/file.txt')

Fetch metadata for a specific file:

print(dbx.files_get_metadata('/file.txt'))

Documentation and examples

Full documentation for the Python SDK is available on Read the Docs. The repository also includes a sample script, updown.py, in its examples folder, which demonstrates upload and download workflows. The Dropbox team says it is actively seeking developer feedback on the preview SDK as it prepares for the formal API v2 rollout.