gh-search

raw JSON →
0.9.2 verified Sat May 09 auth: no python

A command-line tool for searching GitHub repositories, code, issues, and more. Current version 0.9.2, requires Python >=3.12. Released sporadically; latest updates focus on maintenance and bug fixes.

pip install gh-search
error ModuleNotFoundError: No module named 'gh_search'
cause Trying to import gh_search as a Python module in code, but it is a CLI tool meant to be run as a script.
fix
Use subprocess.run(['gh-search', ...]) in Python, or run directly from command line.
error AttributeError: module 'gh_search' has no attribute '__version__'
cause The gh_search module does not export __version__; version info is only accessible via --version flag.
fix
Run 'gh-search --version' from command line, or check metadata from pip show gh-search.
error TypeError: 'NoneType' object is not iterable
cause No GITHUB_TOKEN set and rate limit exceeded for unauthenticated requests.
fix
Set GITHUB_TOKEN environment variable with a valid GitHub personal access token.
breaking Python 3.12+ only. Installing on older Python versions will fail.
fix Upgrade Python to >=3.12 or use gh-search <0.9.0 (which supports Python 3.7–3.11).
gotcha The tool requires a valid GitHub Personal Access Token for all operations except public searches (rate-limited). Environment variable GITHUB_TOKEN must be set.
fix Set environment variable GITHUB_TOKEN to a token with appropriate scopes, or use the --token option.
deprecated The --content-filter and --regex-content-filter options are deprecated as of 0.9.0.
fix Use --query or --AND instead. See documentation for new search syntax.

Run a GitHub code search via the CLI using subprocess. For direct Python usage, invoke the module with sys.argv.

import os
import subprocess

# Ensure GITHUB_TOKEN env var is set (optional for unauthenticated)
os.environ.setdefault('GITHUB_TOKEN', '')

# Example: search for code containing 'def foo' in Python repos
result = subprocess.run(["gh-search", "code", "def foo", "--language", "python"], capture_output=True, text=True)
print(result.stdout)