GitHub Downloader (gh-download)
gh-download is a Python command-line tool that allows you to download files from GitHub repositories, including private ones, using GH_TOKEN/GITHUB_TOKEN environment variables or 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.
- Supports authentication via
GH_TOKEN/GITHUB_TOKENenvironment variables or theghCLI. - Automatically prompts for
gh auth loginif no token is available. - Provides clear, user-friendly output and error messages using the Rich library.
- Simple command-line interface.
Prerequisites
- Python: Version 3.11 or higher.
- Authentication (one of the following):
- Environment variable: Set
GH_TOKENorGITHUB_TOKEN(works in CI, Docker, and non-interactive environments). - GitHub CLI (
gh): 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.
- Environment variable: Set
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'). │
│ [required] │
│ * repo_name TEXT The name of the repository (e.g., 'Spoon-Knife'). │
│ [required] │
│ * file_path TEXT The path to the file or folder within the │
│ repository (e.g., 'README.md' or │
│ 'src/my_folder'). │
│ [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
Authentication
gh-download checks for authentication in this order:
- Environment variables: Checks
GH_TOKEN, thenGITHUB_TOKEN. This is the recommended approach for CI/CD pipelines, Docker builds, and other non-interactive environments. ghCLI: Falls back togh auth tokento get an OAuth token from the GitHub CLI.- Interactive login: If neither is available, prompts you to run
gh auth login.
Examples
# Using an environment variable (CI/Docker)
GH_TOKEN=ghp_xxx gh-download owner repo path/to/file
# Using gh CLI authentication (interactive)
gh auth login # one-time setup
gh-download owner repo path/to/file
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.
Metadata
Release files for gh-download 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gh_download-0.6.1.tar.gz | 24.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gh_download-0.6.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 39.7 kB
Release files / gh_download-0.6.1.tar.gz
| Download URL | gh_download-0.6.1.tar.gz |
|---|---|
| Size | 24.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a88e9ab7154a4a89a3b300662cf816749fb665d09fb58aefd2ec524e2d6e8b4
|
|
BLAKE2b-256 checksum How to use checksums |
bed3e7a7fcad96b19fe3ea78caf33b4bbb30c3a532d256068b451d9e09cc7cc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 27, 2026.
Transparency logRelease files / gh_download-0.6.1-py3-none-any.whl
| Download URL | gh_download-0.6.1-py3-none-any.whl |
|---|---|
| Size | 15.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb13fb8cf06d70b7ff9f0a5980ec0f4aaeb9f8dd0014b33c7fae39c2d59612f3
|
|
BLAKE2b-256 checksum How to use checksums |
4af9eb6a8c0aa55fe7f486ebcd36e94cc55864d89276d826eb02e641ef2be232
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 27, 2026.
Transparency log