Now available in preview: Python SDK for API v2

// By Alexandra Feldman • Jun 16, 2015

We've been hard at work on API v2, and today we're releasing a second preview SDK: the Dropbox Python SDK!

It's no secret that we love Python here at Dropbox, so we hope you’ll try out the SDK and send us your thoughts. This blog post will show you how to install the Python SDK and help you get started making calls using the Dropbox API v2.

If you're familiar with API v1, you'll notice a few differences in this new SDK. For more context on v2, including an overview of how we’re updating the Core API, check out this blog post.

Keep in mind that this is a preview version of the Python SDK and API v2. Both might change in the coming months, so please don't use them in production.

Install the Python SDK

In your directory of choice, install the SDK.

pip install dropbox-sdk-python-master.zip

Now you can do “import dropbox” in your python app, or in a python interpreter.

import dropbox

Register a Dropbox API app

If you haven’t already, you’ll need to register a new app in the App Console. Select Dropbox API app and choose your app’s permission. You’ll need to use the app key created with this app to access API v2.

That’s it! You’re ready to start using the Python SDK v2 preview.

Link an account

In order to make calls to the API, you'll need a Dropbox instance. To instantiate, pass in the access token for the account you want to link. (Tip: You can generate an access token for your own account through the App Console).

dbx = dropbox.Dropbox('YOUR_ACCESS_TOKEN')

Test it out to make sure you've linked the right account:

dbx.users_get_current_account()

Try some API requests

You can use the Dropbox object you instantiated above to make API calls. Try out some of the files requests.

List all of the contents in the user’s root directory:

for entry in dbx.files_list_folder('').entries:
    print entry.name
 
# OUTPUT:
# Cavs vs Warriors

Upload a file (and take a wild guess at tomorrow's headline):

dbx.files_upload("Potential headline: Game 5 a nail-biter as Warriors inch out Cavs", '/cavs vs warriors/game 5/story.txt')

Get the metadata for a file (and prove that you called it before the game was over!):

print dbx.files_get_metadata('/Cavs vs Warriors/Game 5/story.txt').client_modified
 
# OUTPUT:
# 2015-06-15 02:45:12

Documentation

You can read more in the documentation. There's also a sample script called “updown.py" in the examples folder. Check it out!

// Copy Link