A CLI tool to download files from GitHub repositories, including private ones, by leveraging your existing gh CLI authentication.
Project description
GitHub Downloader (gh-download)
gh-download is a Python command-line tool that allows you to download files from GitHub repositories, including private ones, by leveraging your existing gh (GitHub CLI) authentication.
[!TIP] If using
uv, just run:
uvx dotbins get cli/cli --name ghto install the GitHub CLI.uvx gh-download --helpto see the help message.
[ToC] ๐
Features
- Download files from public and private GitHub repositories.
- Utilizes your authenticated
ghCLI session to access private repositories. - Automatically prompts for
gh auth loginif you are not authenticated. - Provides clear, user-friendly output and error messages using the Rich library.
- Simple command-line interface.
Prerequisites
- Python: Version 3.11 or higher.
- GitHub CLI (
gh): Must be installed and in your system's PATH. You can install it from https://cli.github.com/ or use dotbins and runuvx dotbins get cli/cli --name ghto install it.
Installation
Install gh-download using pip:
pip install gh-download
Or for development:
-
Clone the repository:
git clone git@github.com:basnijholt/gh-download.git cd gh-download
-
Install in development mode:
uv sync source .venv/bin/activate # On Windows use `.venv\Scripts\activate`
Usage
After installation, you can use the gh-download command:
gh-download REPO_OWNER REPO_NAME FILE_PATH [OPTIONS]
See the output of gh-download -h
Usage: gh-download [OPTIONS] REPO_OWNER REPO_NAME FILE_PATH
Download a specific file from a GitHub repository.
โญโ Arguments โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ * repo_owner TEXT The owner of the repository (e.g., 'octocat'). โ
โ [default: None] โ
โ [required] โ
โ * repo_name TEXT The name of the repository (e.g., 'Spoon-Knife'). โ
โ [default: None] โ
โ [required] โ
โ * file_path TEXT The path to the file or folder within the โ
โ repository (e.g., 'README.md' or โ
โ 'src/my_folder'). โ
โ [default: None] โ
โ [required] โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --branch -b TEXT The branch, tag, or commit SHA to download from. โ
โ [default: main] โ
โ --output -o TEXT Local path to save the downloaded file or folder. If โ
โ downloading a file, this can be a new filename or a โ
โ directory. If downloading a folder, this is the โ
โ directory where the folder will be placed. Defaults โ
โ to the original filename/foldername in the current โ
โ directory. โ
โ --help -h Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Examples
# Download a file from a public repository
gh-download octocat Spoon-Knife README.md
# Download from a specific branch
gh-download octocat Spoon-Knife README.md --branch main
# Save to a specific location
gh-download octocat Spoon-Knife README.md --output ./my_readme.md
# Download from a different branch
gh-download microsoft vscode package.json --branch release/1.85
Arguments
REPO_OWNER: The owner of the repository (e.g., 'octocat')REPO_NAME: The name of the repository (e.g., 'Spoon-Knife')FILE_PATH: The path to the file within the repository (e.g., 'README.md')
Options
--branch, -b: The branch, tag, or commit SHA to download from (default: main)--output, -o: Local path to save the downloaded file (defaults to the original filename in the current directory)--help: Show help message
How it Works
- Checks for
ghCLI: Verifies that theghcommand-line tool is installed and accessible. - Checks Authentication: Runs
gh auth statusto see if you are logged into GitHub. - Prompts for Login: If not authenticated, it will ask if you want to run
gh auth login. If you agree, it initiates the standardghweb-based authentication flow. - Retrieves Token: Once authenticated, it uses
gh auth tokento get an OAuth token. - Downloads File: Uses the GitHub API with the retrieved token to download the specified file.
- Saves File: Saves the downloaded content to the specified local output path.
Development
Running Tests
The project uses pytest for testing. To run tests using uv:
uv run pytest
Pre-commit Hooks
This project uses pre-commit hooks (ruff for linting and formatting, mypy for type checking) to maintain code quality. To set them up:
-
Install pre-commit:
pip install pre-commit
-
Install the hooks:
pre-commit installNow, the hooks will run automatically before each commit.
Contributing
Contributions are welcome! If you find a bug or have a feature request, please open an issue. If you'd like to contribute code, please fork the repository and submit a pull request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gh_download-0.3.0.tar.gz.
File metadata
- Download URL: gh_download-0.3.0.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e912f5e82fe0952d20fb41544ceb5fd0cca8a1b97b7952077814ce16d0dc654e
|
|
| MD5 |
68ca9b6119e56fef7c5618c4bc48d196
|
|
| BLAKE2b-256 |
b9692b1ff1d68ffb067c0e92e723b58761cd920511aa7673af34507b84152c67
|
Provenance
The following attestation bundles were made for gh_download-0.3.0.tar.gz:
Publisher:
release.yml on basnijholt/gh-download
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gh_download-0.3.0.tar.gz -
Subject digest:
e912f5e82fe0952d20fb41544ceb5fd0cca8a1b97b7952077814ce16d0dc654e - Sigstore transparency entry: 440314904
- Sigstore integration time:
-
Permalink:
basnijholt/gh-download@b1942b3dbccbfc6c7fbd5e6b04cf69c5b3d67a80 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/basnijholt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b1942b3dbccbfc6c7fbd5e6b04cf69c5b3d67a80 -
Trigger Event:
release
-
Statement type:
File details
Details for the file gh_download-0.3.0-py3-none-any.whl.
File metadata
- Download URL: gh_download-0.3.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08fd8b645477f32dacaf526db15145542f3a991e124d88a9cc6cabb65a3b3a3d
|
|
| MD5 |
e9093cf29904508bb45a9d4c82e8bced
|
|
| BLAKE2b-256 |
9e6bab5b82df2cb7b7396463df0f39a64b614cc9246574c436db193b7caccc2f
|
Provenance
The following attestation bundles were made for gh_download-0.3.0-py3-none-any.whl:
Publisher:
release.yml on basnijholt/gh-download
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gh_download-0.3.0-py3-none-any.whl -
Subject digest:
08fd8b645477f32dacaf526db15145542f3a991e124d88a9cc6cabb65a3b3a3d - Sigstore transparency entry: 440314925
- Sigstore integration time:
-
Permalink:
basnijholt/gh-download@b1942b3dbccbfc6c7fbd5e6b04cf69c5b3d67a80 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/basnijholt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b1942b3dbccbfc6c7fbd5e6b04cf69c5b3d67a80 -
Trigger Event:
release
-
Statement type: