Download from Dropbox, Google Drive, and Github

It’s also possible to download files from Github, Google Drive, and Dropbox. While you can go through a little extra effort to get a direct download link, download will try to make things a little bit easier for you.

from download import download
import matplotlib.pyplot as plt
import os.path as op
import shutil as sh

You can simply find the link to your content on GitHub and give it directly to Download. It will try to be smart about converting the link where necessary.

url = "https://drive.google.com/file/d/0B8VZ4vaOYWZ3c3Y1c2ZQX01yREk/view?usp=sharing"
path = download(url, "./downloaded/citation.png", replace=True)

fig, ax = plt.subplots()
im = plt.imread(path)
ax.imshow(im)
ax.set_axis_off()
../_images/sphx_glr_plot_download_providers_001.png

Out:

Downloading data from https://doc-0g-9c-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/5k38lin2cub2baoepd2f1h31d07bpljk/1587679275000/01085013503681928164/*/0B8VZ4vaOYWZ3c3Y1c2ZQX01yREk?e=download (35 kB)


file_sizes:   0%|                                   | 0.00/35.6k [00:00<?, ?B/s]
file_sizes: 100%|##########################| 35.6k/35.6k [00:00<00:00, 4.29MB/s]
Successfully downloaded file to ./downloaded/citation.png

The same works for Google Drive content.

Note

Make sure your sharing options let any user access the file.

url = "https://github.com/choldgraf/download/blob/master/examples/data/citation.png"
path2 = download(url, "./downloaded/citation2.png", replace=True)

fig, ax = plt.subplots()
im2 = plt.imread(path)
ax.imshow(im2)
ax.set_axis_off()
../_images/sphx_glr_plot_download_providers_002.png

Out:

Downloading data from https://github.com/choldgraf/download/blob/master/examples/data/citation.png (1 byte)


file_sizes:   0%|                                    | 0.00/1.00 [00:00<?, ?B/s]
file_sizes: 65.9kB [00:00, 5.02MB/s]
Successfully downloaded file to ./downloaded/citation2.png

Dropbox links also work, though in this case download will use the requests library to download the file. This is because Dropbox requires cookies and requests is smart about handling this.

url = "https://www.dropbox.com/s/rlndt99tss65418/citation.png?dl=0"
path3 = download(url, "./downloaded/citation3.png", replace=True)

fig, ax = plt.subplots()
im3 = plt.imread(path3)
ax.imshow(im)
ax.set_axis_off()

sh.rmtree("./downloaded")
plt.show()
../_images/sphx_glr_plot_download_providers_003.png

Out:

Successfully downloaded file to ./downloaded/citation3.png

Total running time of the script: ( 0 minutes 2.055 seconds)

Gallery generated by Sphinx-Gallery