Skip to main content

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, using GH_TOKEN/GITHUB_TOKEN environment variables or your existing gh (GitHub CLI) authentication.

[!TIP] If using uv, just run:

  1. uvx dotbins get cli/cli --name gh to install the GitHub CLI.
  2. uvx gh-download --help to see the help message.
[ToC] ๐Ÿ“š

Features

  • Download files from public and private GitHub repositories.
  • Supports authentication via GH_TOKEN/GITHUB_TOKEN environment variables or the gh CLI.
  • Automatically prompts for gh auth login if 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_TOKEN or GITHUB_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 run uvx dotbins get cli/cli --name gh to install it.

Installation

Install gh-download using pip:

pip install gh-download

Or for development:

  1. Clone the repository:

    git clone git@github.com:basnijholt/gh-download.git
    cd gh-download
    
  2. 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:

  1. Environment variables: Checks GH_TOKEN, then GITHUB_TOKEN. This is the recommended approach for CI/CD pipelines, Docker builds, and other non-interactive environments.
  2. gh CLI: Falls back to gh auth token to get an OAuth token from the GitHub CLI.
  3. 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:

  1. Install pre-commit:

    pip install pre-commit
    
  2. Install the hooks:

    pre-commit install
    

    Now, 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

gh_download-0.6.0.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gh_download-0.6.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file gh_download-0.6.0.tar.gz.

File metadata

  • Download URL: gh_download-0.6.0.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gh_download-0.6.0.tar.gz
Algorithm Hash digest
SHA256 7ad11a847124d0475c03a63632b67719f87e2b145a31afe5f27309579323e0b5
MD5 07e2036d09df9e318de3a1c96a9131c5
BLAKE2b-256 0016c4550927d9f7222483985b5b076e93ed1cdac364d0dcc3a8afd65cdbe47e

See more details on using hashes here.

Provenance

The following attestation bundles were made for gh_download-0.6.0.tar.gz:

Publisher: release.yml on basnijholt/gh-download

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gh_download-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: gh_download-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gh_download-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c49c5f28b1de6db5eb2cb2fe2e0e4340eb3a3fa679ca6b3629a15686f58a1bf9
MD5 0ae26690bd9c9dd02b7e03cdd3b2c892
BLAKE2b-256 9833e931c95d705d369133a5b061646fb5259cf5a30b3d97570f24ab6a4d7dfb

See more details on using hashes here.

Provenance

The following attestation bundles were made for gh_download-0.6.0-py3-none-any.whl:

Publisher: release.yml on basnijholt/gh-download

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page