First, choose for scoped access. This way you can choose what permissions your app will have, and thus what your app can do (read, write, delete...). Next, you can choose for either App folder (if you want your app to only have access to a specific folder) or Full Dropbox access (if your app can access everything in your Dropbox). If you choose for the former option, make sure to put the files you want to access into this folder. This folder will automatically be created and named after your app name. Finally, you can choose this name of your app.
On the next page, on the Permissions tab, you can now choose what permissions your app can have. To set up a basic read connection to your workspace, you will need at least the
files.content.readpermission. When you select this option, all other required options will automatically get selected. If you also would like to write to your Dropbox files, you will also need the
When you go back to the Settings tab, you can generate your access token. Copy this access token and define it as an environment variable in your workspace as follows. If you want to learn more about environment variables and how you can store them securely in DataCamp Workspace; check out this article.
# Import the packages
import pandas as pd
from io import StringIO
from dropbox import Dropbox
dbx = Dropbox(os.environ["DROPBOX_ACCESS_TOKEN"])
def read_file(file_name, index_col=None):
metadata, res = dbx.files_download(path="/"+filename)
s = str(res.content, "utf-8")
data = StringIO(s)
return pd.read_csv(data, index_col=index_col)
df = read_file("filename.csv", index_col = "index_col_name")
Without creating your own Dropbox integration as explained above, you can also use the Dropbox credentials we set up for you to try out. These credentials will give you access to three example data files. Together, they form a small dummy database of an online shoe retailer. You can find more information on these files in this template. If you want to connect to this Dropbox folder, set your environment variable as follows in the integration tab:
DROPBOX_ACCESS_TOKEN = qkNTnH6VnFwAAAAAAAAAAUTOP8JdAlD8eAstrXhOO7jTghDWIOI5QwNzNE0PWhtU
After setting up this integration and connecting it to your workspace, everything will be ready to run.