cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use the Python SDK to download netcdf files

How to use the Python SDK to download netcdf files

tXiao95
New member | Level 2

I have some large netcdf4 files in my personal Dropbox on the order of about 12GB. I'd like to use the Python SDK to read these files directly into my session without having to download them locally but am not sure how to use the Response object that gets returned by files_download()? I work with .nc files primarily with the `xarray` package, so was wondering what the best way to get from the Response object specified by my path to a xarray object would be. The code I currently have is below. 

import dropbox 
import netCDF4
import xarray as xr

access_token = XXXXXX
dbx = dropbox.Dropbox(access_token)
db_path = "/MAXT.nc"
metadata, f = dbx.files_download(db_path)
1 Reply 1

Greg-DB
Dropbox Staff

The files_download method gives you a requests.Response object that you can read from, optionally in pieces, without downloading the entire file to your local filesystem.

For example, you might want to read it a piece at a time, like:

metadata, f = dbx.files_download(path)

for partial_data in f.iter_content(chunk_size=1024):
    print(partial_data)
    raw_input()  # whatever you need to do

I can't offer help with netCDF4 or xarray though, as those are not made by Dropbox.

 

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?