Skip to content
Related Articles

Related Articles

How to Automate the Storage using Dropbox API in Python ?

Improve Article
Save Article
Like Article
  • Last Updated : 21 Apr, 2021

In this Data Era Storing, Managing, and organizing the Data is an important factor considered by every business. Dropbox is one of the most popular cloud storage systems on the market, and it continues to improve its features.  In this article, we will be demonstrating how one can connect to dropbox API using Python and perform Storage Automation efficiently.

Get Secret Key to Connect To Your Dropbox

  • In the Oauth2 Section, Set Access Token Expiration to “No Expiration“, generate an Access Token.

  • Go to Permissions Tab, Select Appropriate Permissions that are required, and click Submit.

  • With The Token Key Generated from the Above steps, We can use this token to connect to dropbox and perform storage Automation. You can install the python library using the below command:
pip install dropbox 

Demonstration video to generate a token:

Using the token key to connect to Dropbox:

Use the token generated to connect to dropbox and create an object.


# importing necessary libraries
import dropbox
# Token Generated from dropbox
TOKEN = "access_token"
# Establish connection
def connect_to_dropbox():
        dbx = dropbox.Dropbox(TOKEN)
        print('Connected to Dropbox successfully')
    except Exception as e:
    return dbx
dbx = connect_to_dropbox()


Connected to Dropbox successfully

We have successfully connected to Dropbox. We can now list folders/files, read files, upload files, delete files, etc.  

Listing Files in a Folder

First, call the above method to connect and create a dropbox object, then assign a path for the folder to be scanned, then iterate through the older using file_list_folder() method and for a loop.


# explicit function to list files
def list_files_in_folder():
    # here dbx is an object which is obtained
    # by connecting to dropbox via token
    dbx = connect_to_dropbox()
        folder_path = "/folder_path"
        # dbx object contains all functions that 
        # are required to perform actions with dropbox
        files = dbx.files_list_folder(folder_path).entries
        print("------------Listing Files in Folder------------ ")
        for file in files:
            # listing
    except Exception as e:


Now we have successfully connected to dropbox using python, Listed the Folders present in it.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!