You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"source": "### Sample Code: Downloading Notebooks/Files from Git.\n\nThis example demonstrates how to download notebook/files from Git as ZIP and extract them to AIDP Workspace. It uses requests python library.\n\n\n**Note:** \n\n- Replace all placeholders (e.g., `<GIT_USERNAME>`, `<GIT_PAT>`, `<AIDP_WORKSPACE_PATH>`, `<GIT_REPO_NAME>`, `<GIT_BRANCH>` etc.) with values specific to your environment before running the notebook. \n- Use with caution: Notebook is designed for downloading all files from repo and unarchive to provided workspace path.\n- This notebook should be executed from AIDP.",
"source": "import requests\nimport zipfile\nimport io\nimport os\n\nif not git_pat:\n raise ValueError(\"GIT_PERSONAL_ACCESS_TOKEN not set\")\n\nzip_url = f\"https://api.github.com/repos/{git_username}/{git_repo_name}/zipball/{git_branch}\"\n\ntry:\n # Headers for PAT authentication\n headers = {\n \"Authorization\": f\"token {git_pat}\",\n \"Accept\": \"application/vnd.github.v3+json\"\n }\n\n print(f\"Downloading ZIP from {zip_url}...\")\n response = requests.get(zip_url, headers=headers, stream=True)\n response.raise_for_status()\n\n # Extract the ZIP content\n with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:\n \n top_level_folder = os.path.commonprefix(zip_ref.namelist())\n # Extract all files\n zip_ref.extractall(aidp_path)\n print(\"Repository downloaded and extracted successfully.\")\n\nexcept requests.exceptions.RequestException as e:\n print(f\"Error downloading repository: {e}\")\nexcept zipfile.BadZipFile:\n print(\"Downloaded file is not a valid ZIP file.\")\nexcept Exception as e:\n print(f\"An unexpected error occurred: {e}\")\n",
51
+
"metadata": {
52
+
"execution": {
53
+
"iopub.status.busy": "2025-11-04T14:37:29.146Z"
54
+
},
55
+
"type": "python",
56
+
"trusted": true
57
+
},
58
+
"outputs": [
59
+
{
60
+
"data": {
61
+
"text/plain": "Downloading ZIP from https://api.github.com/repos/nishgit/git-sdk-test/zipball/main...\n"
62
+
},
63
+
"metadata": {},
64
+
"output_type": "display_data"
65
+
},
66
+
{
67
+
"data": {
68
+
"text/plain": "Repository downloaded and extracted successfully.\n"
0 commit comments