Skip to content

About

GitHub code scraper and search tool: search all public code on GitHub by file name or contents and export the results to CSV. Exact file names, newest first, past the 1,000-result limit. Official API, one Python file, no dependencies.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Code Search

Search and scrape all public code on GitHub by file name or by what's inside the files, and export the results to CSV. Exact file names, newest commits first, and more than GitHub's 1,000-result limit. One Python file, nothing to install.

A GitHub code scraper that does it the safe way: it collects GitHub's code search results through the official API, so there's no HTML parsing to break and no blocked IP address.

Python 3.8+ No dependencies Official GitHub API License: MIT

The search page: a search for files named exactly AGENTS.md, with 40 results sorted by last commit

Why not just search on github.com?

GitHub's website is great for looking at a few results. This tool is for when you want the list.

github.com search This tool
Export the results to CSV No Yes, one click
Files named exactly package.json No, you also get package-lock.json and others Yes
Sort by when the file was last changed No Yes, newest first
More than 1,000 results No Yes, splits big searches for you
Many searches at once (fastapi, flask, django…) One at a time Yes, merged without duplicates
Waits for GitHub's rate limit on its own n/a Yes, with a countdown

How much does "exact" matter? In a test, GitHub returned 126 files for filename:package.json tailwindcss. 106 of them weren't named package.json. For filename:mcp.json, 180 of 220 weren't.

Quick start

git clone https://github.com/husseinelsaadii/github-code-search.git
cd github-code-search
gh auth login        # once, if you haven't already (see "GitHub token" below)
python3 search.py

Your browser opens at http://127.0.0.1:8765. Type something, press Start search, then Download CSV.

On Windows, type py search.py instead of python3 search.py. Press Ctrl+C in the terminal to quit.

Ready-made searches

Not sure where to start? The page has one-click examples, and these all work today:

What you want Text inside the file File name Other filters
AI agent instruction files to learn from AGENTS.md
Claude Code project instructions CLAUDE.md
MCP server configurations mcpServers mcp.json
How people containerise FastAPI apps fastapi Dockerfile
Docker Compose setups that use Postgres postgres docker-compose.yml
Projects that use Tailwind CSS tailwindcss package.json
Real code that calls the Claude API from anthropic import Language: python
GitHub Actions workflows actions/checkout path:.github/workflows
Projects that use several libraries together useState, useEffect + all keywords

Good for: finding real-world examples of a library or API, collecting config files to compare, building a dataset of files for research, or finding every project that uses something you maintain.

How to use it

  1. Text inside the file: the words to look for, separated by commas. A keyword with spaces is searched as an exact phrase.
  2. File name (optional): only files with exactly this name, e.g. Dockerfile. Untick Exact name only to also get names that just contain it.
  3. Check the dark box under the form. It shows the exact query GitHub will run and how long the search can take.
  4. Press Start search. Files show up in the table as soon as GitHub returns them, sorted by when the file was last changed (newest first).
  5. Press Download CSV to save the results. They go to your Downloads folder.

With several keywords, any keyword runs one search per keyword and merges the results. All keywords runs a single search that needs every keyword. Files found more than once appear only once.

Exact file names

GitHub's own file-name search is loose: searching for Dockerfile also returns Dockerfile.dev, and package.json returns package-lock.json. With Exact name only on (the default), the tool checks every file GitHub returns and keeps only the ones named exactly what you typed (upper/lower case is ignored). Include the extension: settings.py, not settings.

Newest first

GitHub's code search can't sort by date, so after each page of results the tool asks GitHub when each file was last committed to (on the repository's default branch) and sorts the table and the CSV by that date, newest first. These lookups use GitHub's GraphQL API, which has its own quota (about 1 point per 25 files out of 5,000 per hour), so they don't use the 10 searches per minute.

Note that this sorts the files the tool fetched. GitHub returns at most 1,000 files per search in its own order, so for a very common name raise Max files per search (or turn on Go past 1,000 files) to sort more of them.

More options

Option What it does
Exact name only Keep only files named exactly what you typed (on by default)
Newest commits first Look up each file's last commit date and sort by it (on by default)
Language Only files in this language, e.g. python
File extension Only files with this extension, e.g. json
Other GitHub filters Any GitHub code-search filter, e.g. user:octocat, repo:owner/name or path:.github/workflows
Max files per search Stops each search after this many files (GitHub's maximum is 1,000)
Go past 1,000 files Splits a big search by file size to get more results. Uses many more requests
Add stars and last update Looks up each repository's stars and last push date after the search
Searches at once How many searches run in parallel
Seconds between requests The gap between requests while there's quota left
GitHub token Use a different token for this session

GitHub token

Do I have to search my own GitHub? No. The tool searches all public code on GitHub. GitHub only requires you to be signed in to use code search, and the token is how you sign in.

The tool finds a token on its own, in this order:

  1. TOKEN in config.py
  2. The GITHUB_TOKEN environment variable
  3. The GitHub CLI, if you've run gh auth login

You can also paste a token in More options on the page. It's kept in memory only and is gone when you quit. To make one, go to github.com/settings/tokens; it doesn't need any scopes.

If your token can see your private repositories (the GitHub CLI's token usually can), your own private files can show up in the results too.

Privacy

  • Nothing is saved. No CSV, log or cache file is written to the project folder or anywhere else.
  • Results live in memory until you download them, start a new search, press Stop and clear / Clear results, or quit with Ctrl+C.
  • The terminal only shows the page address. Your searches and results are never printed.
  • The page only answers on 127.0.0.1, and other websites can't control it.
  • The token is never shown, logged or saved.

Limits (set by GitHub)

  • 10 code searches per minute per account. When they run out, the page shows a countdown and the search continues by itself. More workers or proxies can't raise this, because the limit belongs to your account.
  • 1,000 results per search. Turn on Go past 1,000 files to split a big search into smaller ones.
  • Only default branches and files under about 384 KB are searchable.

CSV columns

last_commit (with Newest commits first on, UTC), filename_filter, keyword, repo, repo_url, repo_description, is_fork, path, file_name, file_url, raw_url, sha. With Add stars and last update on, you also get stars and last_push.

Default settings

config.py pre-fills the form when the page opens. You never have to edit it, but it's handy for a search you run often. It also sets the page's port (PORT) and whether the browser opens by itself (OPEN_BROWSER).

python3 search.py --config my_search.py   # use another settings file

FAQ

How do I export GitHub code search results to CSV? Run python3 search.py, search on the page, and press Download CSV. Every file found becomes one row with the repository, path, links and last commit date. github.com itself has no export button.

How do I search GitHub for files with a specific name? Type the name in File name, for example Dockerfile or AGENTS.md, and leave Exact name only on. GitHub's own filename: search also returns similar names (like Dockerfile.dev); this tool removes them.

How do I get more than 1,000 results from GitHub code search? GitHub stops every search at 1,000 results. Turn on Go past 1,000 files under More options: the tool splits the search by file size into smaller searches that each stay under the limit, then merges them without duplicates.

How do I search GitHub code with Python? This project is a working example: search.py calls the GitHub code search API with only the Python standard library, handles the rate limit and pagination, and needs no pip install. Use the page, or read the code to see how it's done.

Is this a GitHub scraper? It does what people usually want a scraper for: it collects GitHub's code search results (repository, path, links, last commit) into a CSV. But it gets them from GitHub's official API instead of scraping web pages, so it doesn't break when GitHub changes its website, and your IP address doesn't get blocked.

Is this allowed by GitHub? Yes. It uses GitHub's official code search API with your own account, and stays within its rate limit. It doesn't scrape web pages, and it doesn't use extra accounts or proxies to get around the limit.

Why does a big search take a while? GitHub allows 10 code searches per minute. A search returns 100 files per request, so 1,000 files takes about a minute. The page shows how long a search can take before you start it.

Does it need the GitHub CLI? No. The CLI is just the easiest way to sign in. A token from github.com/settings/tokens works too.

Troubleshooting

Problem Fix
"No GitHub token" Run gh auth login and restart, or paste a token under More options
"GitHub rejected this token" The token expired or was mistyped. Create a new one
"Your Python can't check GitHub's security certificate" On a Mac with Python from python.org, open Applications > Python 3.x and double-click Install Certificates.command
Port 8765 is taken The tool picks the next free port. The terminal shows which one
"GitHub found no files" Try fewer or shorter keywords, or remove a filter
"None had exactly the file name you typed" Check the extension (settings.py, not settings), or untick Exact name only

Files

search.py        the search engine and the local web server
dashboard.html   the page
config.py        default settings for the form

Contributing

Issues and pull requests are welcome. Please keep it to the Python standard library (no pip install) and Python 3.8+. If something doesn't work, open an issue with what you searched for and the message the page showed.

If this saved you time, a ⭐ helps other people find it.

License

MIT

About

GitHub code scraper and search tool: search all public code on GitHub by file name or contents and export the results to CSV. Exact file names, newest first, past the 1,000-result limit. Official API, one Python file, no dependencies.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages