Template request | Bug report | Generate Data Product
Tags: #github #download #repository #url #api #zip
Author: Florent Ravenel
Description: This notebook explains how to download a repository from a URL.
References:
import requests
import urllib
import os
import zipfile
url
: URL of the repository to be downloadedbranch_master
: Name of the master branchoutput_dir
: Path of the directory as output
# Inputs
url = "https://github.com/jupyter-naas/data-product-framework"
branch_master = "master"
# Outputs
output_dir = "."
repo_name = url.split("/")[-1].split("/")[0]
zip_url = f"{url}/archive/refs/heads/{branch_master}.zip"
output_path = os.path.join(output_dir, f"{repo_name}.zip")
urllib.request.urlretrieve(zip_url, output_path)
print("✅ Repo archive downloaded:", output_path)
with zipfile.ZipFile(output_path, 'r') as zip_ref:
# extract files on root dir
zip_ref.extractall(output_dir)
print("✅ Folder unzip")
os.remove(output_path)
print("✅ ZIP removed from root folder")
print("✅ Repo downloaded available in dir:", output_dir)