Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/GitHub/GitHub_Download_repository_from_URL.ipynb
2973 views
Kernel: Python 3

GitHub.png

GitHub - Download repository from URL

Give Feedback | Bug report

Tags: #github #download #repository #url #api #zip

Last update: 2023-04-24 (Created: 2023-04-10)

Description: This notebook explains how to download a repository from a URL.

References:

Input

Import libraries

import requests import urllib import os import zipfile

Setup Variables

  • url: URL of the repository to be downloaded

  • branch_master: Name of the master branch

  • output_dir: Path of the directory as output

# Inputs url = "https://github.com/jupyter-naas/data-product-framework" branch_master = "master" # Outputs output_dir = "."

Model

Download repository

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)

Unzip and rename reposistory

with zipfile.ZipFile(output_path, 'r') as zip_ref: # extract files on root dir zip_ref.extractall(output_dir) print("✅ Folder unzip")

Remove ZIP

os.remove(output_path) print("✅ ZIP removed from root folder")

Output

Display result

print("✅ Repo downloaded available in dir:", output_dir)