Dropbox
If you just want to try out this integration by accessing predefined datafiles, you can skip the next part and go to the next section immediately.
If you want to access your own files, you will need to create a new app in the App Console.
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.read permission. 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 files.content.write permission.
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.
Once you have set up and connected your integration to your workspace, you can access your files from your workspace with following lines of code. You can also check out this example.
1
# Import the packages
2
import pandas as pd
3
import os
4
from io import StringIO
5
from dropbox import Dropbox
6
7
dbx = Dropbox(os.environ["DROPBOX_ACCESS_TOKEN"])
8
9
def read_file(file_name, index_col=None):
10
metadata, res = dbx.files_download(path="/"+filename)
11
s = str(res.content, "utf-8")
12
data = StringIO(s)
13
return pd.read_csv(data, index_col=index_col)
14
15
df = read_file("filename.csv", index_col = "index_col_name")
Copied!

Sample database: online shoe retail

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.
Last modified 21d ago