# GitHub Code Search API (`automly/github-code-search-api`) Actor

GitHub Code Search API: Search public GitHub code by query, language, repository, file name or path: file link, repository, path, matched text and repository stars and forks for each hit. Export to CSV, JSON or Excel, schedule runs or use the API.

- **URL**: https://apify.com/automly/github-code-search-api.md
- **Developed by:** [Automly](https://apify.com/automly) (community)
- **Categories:** Developer tools, Lead generation, AI
- **Features:** Limited permissions
- **Stats:** 28 total users, 6 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.00 / 1,000 code hit produceds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## GitHub Code Search API

### What is GitHub Code Search API?

**GitHub Code Search API** is a tool that lets you **scrape code search results from GitHub**: the files that match your search, with file name and path, a link to the file, the matching lines, the language, and the repository's name, description, stars, forks and owner. Type a search such as `requests language:Python`, click **Start**, and download the code hits as Excel, CSV or JSON.

- 🔎 **GitHub search syntax:** keywords plus filters for language, repository, file name and path
- 📁 **Repository context:** every code hit comes with the repository's stars, forks, description and owner type
- 🔓 **One repository, no key:** search inside any one public repository without a GitHub key; searching all of GitHub needs your own free GitHub key
- 💸 **Free to try:** the $5 of free usage every Apify account gets each month covers about 5,000 code hits

### What can GitHub Code Search API do?

- Search public GitHub code by keyword
- Find which repositories use a library, package or API
- Search GitHub code by programming language
- Search code inside one GitHub repository
- Find files by name across GitHub, such as `package.json` or `requirements.txt`
- Search GitHub code in a folder path such as `src/` or `docs/`
- Get the matching lines of code for each file when GitHub shows them
- Export GitHub code search results to Excel, CSV, JSON, HTML or XML

### What data can you extract from GitHub code search?

| | | |
|---|---|---|
| 📄 File name | 📂 File path | 🔗 Link to the file |
| 🧾 Matching lines | 💻 Language | 🎯 Match score |
| 📦 Repository name and URL | 📝 Repository description | ⭐ Stars and 🍴 forks |
| 👤 Owner login | 🏢 Owner type (user or organization) | 🔎 Your search query |

### How to scrape GitHub code search results

1. [Create a free Apify account](https://console.apify.com/sign-up) (no credit card needed).
2. Open **GitHub Code Search API**.
3. Type a **Search query**. To search all of GitHub, paste your own GitHub personal access key in the last field of the form; to search one repository, fill in **Repository filter** instead.
4. Add a **Language filter**, **Filename filter** or **Path filter** if you want, set **Maximum results**, and click **Start**.
5. When the run finishes, download your code hits as Excel, CSV, JSON, HTML or XML.

### How to get a free GitHub key for searching all of GitHub

GitHub only lets signed-in users search code across all of GitHub, so this one setting needs your own key. It is free and takes a minute:

1. Sign in to GitHub and open [github.com/settings/tokens](https://github.com/settings/tokens).
2. Create a new personal access key. It needs **no permissions**, because the actor only reads public code.
3. Paste it into the last field of the input form. Apify stores it as a secret.

You don't need a key to search inside one public repository: put `repo:owner/name` in the query or fill in **Repository filter**.

### How much does it cost to scrape GitHub code search results?

You pay **$1.00 per 1,000 code hits**. Apify platform usage is included in this price, so there is nothing else to pay for the run.

For example, 1,000 code hits cost $1.00 on the Free plan, and a run that returns 100 code hits costs $0.10.

Every Apify account gets **$5 of free usage each month**. See the **Pricing** tab for details.

### ⬇️ Input

| Setting | What it does |
|---|---|
| Search query | Keywords plus optional GitHub filters, such as `language:Python`, `repo:owner/name`, `filename:requirements.txt` or `path:src/` (required) |
| Maximum results | How many code hits to return (default 50, up to 100) |
| Language filter | Only code in this programming language |
| Repository filter | Only code in this repository, as `owner/name`, e.g. `psf/requests` |
| Filename filter | Only files with this name, e.g. `package.json` or `README.md` |
| Path filter | Only files under this path, e.g. `src/` or `docs/` |
| Your GitHub key | Needed only to search all of GitHub (see above) |

Example: Python code that uses `requests` (needs your GitHub key).

```json
{
  "query": "requests language:Python",
  "maxResults": 20
}
```

Example: search one repository, no key needed.

```json
{
  "query": "HTTPAdapter repo:psf/requests",
  "maxResults": 20
}
```

Example: search the README of one repository.

```json
{
  "query": "api key",
  "repo": "psf/requests",
  "filename": "README.md",
  "maxResults": 10
}
```

### ⬆️ Output

You get one row per matching file. You can view the rows as a table in Apify Console or download them as Excel, CSV, JSON, HTML or XML. `matchedText` holds the matching lines when GitHub shows them.

```json
{
  "recordType": "code-hit",
  "query": "requests language:Python",
  "repositoryFullName": "psf/requests",
  "repositoryUrl": "https://github.com/psf/requests",
  "repositoryDescription": "Python HTTP for Humans.",
  "repositoryStars": 53500,
  "repositoryForks": 9700,
  "repositoryOwnerLogin": "psf",
  "repositoryOwnerType": "Organization",
  "fileName": "__init__.py",
  "filePath": "requests/__init__.py",
  "htmlUrl": "https://github.com/psf/requests/blob/main/requests/__init__.py",
  "gitUrl": "https://api.github.com/repos/psf/requests/git/blobs/...",
  "apiUrl": "https://api.github.com/repos/psf/requests/contents/requests/__init__.py",
  "score": 1,
  "language": "Python",
  "matchedText": "..."
}
```

### How can I use GitHub code search data?

- **Library and API adoption:** find real examples of how a library, SDK or API is used, and which projects use it
- **Developer prospecting:** list the repositories and organizations whose code mentions your product or a competitor's
- **Code research:** compare patterns and implementation styles across public projects
- **Package and dependency discovery:** find `package.json`, `requirements.txt` or other files that name a package
- **Mention monitoring:** run the same search on a schedule to see new code mentions of your package
- **Examples for AI prompts:** collect real code examples to add to your own prompts and docs

### Scrape more GitHub and developer data

| Actor | What it gets |
|---|---|
| [GitHub Repository Scraper - Repos, Issues & Pull Requests](https://apify.com/automly/github-repo-scraper) | Repository details, open issues, pull requests and contributor profiles |
| [GitHub Issues Scraper - Issues & Pull Requests Monitor](https://apify.com/automly/github-issues-pr-monitor) | New, updated, closed and merged issues and pull requests, on a schedule |
| [GitHub Users Scraper - Developers by Location & Company](https://apify.com/automly/github-users-search-api) | GitHub users and organizations by keyword, location, company and follower count |
| [npm Scraper - Package Metadata, Versions & Maintainers](https://apify.com/automly/npm-package-metadata-api) | npm package details, versions and maintainers |
| [PyPI Scraper - Python Package Versions & Downloads](https://apify.com/automly/pypi-package-metadata-api) | Python package metadata, versions and project links |
| [Stack Overflow Scraper - Questions, Tags & Scores](https://apify.com/automly/stack-exchange-questions-api) | Stack Overflow and Stack Exchange questions with tags, scores and answer counts |

### 🤖 Use with AI agents (MCP)

This actor works as a tool for AI agents. Connect any MCP-compatible AI assistant or agent to the Apify MCP server at [mcp.apify.com](https://mcp.apify.com) (sign in with your Apify account), and it can find this actor, fill in the input and read the results by itself. Ask in plain words, for example *"Find the files in psf/requests that use HTTPAdapter"*, and the agent runs `automly/github-code-search-api` with an input like `{"query": "HTTPAdapter repo:psf/requests", "maxResults": 20}`. Every input and output field has a plain description, so the agent knows what to type and what each column means. Agent runs cost the same as runs you start yourself.

### ❓FAQ

#### How much does GitHub Code Search API cost?

$1.00 per 1,000 code hits, platform usage included. See the cost section above and the **Pricing** tab.

#### Do I need a GitHub account or key?

To search all of GitHub, yes: GitHub only allows that for signed-in users. Create a free personal access key at [github.com/settings/tokens](https://github.com/settings/tokens); it needs no permissions, because the actor reads public code only. To search inside one public repository you need nothing: put `repo:owner/name` in the query or fill in **Repository filter**. Results then include every file that contains all your words, best matches first, and `score` counts how often the words appear.

#### Can I search a single repository?

Yes. Use `repo:owner/name` in the query or the **Repository filter** field.

#### How many code hits can I get per run?

Up to 100 per run. For more, split your search into narrower ones, for example by language, path or repository, and run each one.

#### Can I search private code?

No. It returns public code search results only.

#### Why are some `matchedText` values empty?

GitHub does not show the matching lines for every result. When it doesn't, the row still has the file, its link and the repository details.

#### What if my run charge limit is reached?

The actor stops after the last result your limit covers and keeps every code hit it already produced.

#### Can I connect GitHub Code Search API to other tools or AI agents?

Yes. Start runs and download results with the Apify API or the Python and JavaScript clients, send results to Make, Zapier, n8n, Google Sheets or Slack with Apify integrations and webhooks. AI assistants and agents can run it through the Apify MCP server, see the **Use with AI agents (MCP)** section above.

#### Is it legal to scrape GitHub?

This actor only returns public code that anyone can find with GitHub search. Code and repository details can still contain personal data, such as names or email addresses in files, which may be protected by laws such as GDPR, and code is covered by its license. Only use it for a legitimate reason and ask a lawyer if you are unsure. You can read more in [Is web scraping legal?](https://blog.apify.com/is-web-scraping-legal/)

GitHub Code Search API is an independent tool. It is not affiliated with, endorsed by or sponsored by GitHub.

#### Something isn't working?

Open the **Issues** tab and tell us your search query and what you expected.

### ⭐ Your feedback

Have an idea or found a problem? Tell us on the **Issues** tab. If GitHub Code Search API saved you time, a short review on the **Reviews** tab helps other people find it.

# Actor input Schema

## `query` (type: `string`):

GitHub code search query. Use keywords plus optional qualifiers like language:Python, repo:owner/name, filename:requirements.txt, or path:src/. Without a token, include one repository (repo:owner/name or the Repository filter).

## `maxResults` (type: `integer`):

How many code matches to return, e.g. 20. Up to 100 per run.

## `language` (type: `string`):

Optional programming language appended to the search query. Leave empty for all languages.

## `repo` (type: `string`):

Optional repository filter in owner/name format, e.g. psf/requests. Without a token, the search runs inside this one public repository.

## `filename` (type: `string`):

Optional filename filter, e.g. package.json or README.md.

## `path` (type: `string`):

Optional path filter, e.g. src/ or docs/.

## `token` (type: `string`):

Your GitHub token. GitHub only allows searching all of GitHub for signed-in users. Create one at https://github.com/settings/tokens; it needs no permissions. Without a token, the actor searches one public repository.

## Actor input object example

```json
{
  "query": "Session repo:psf/requests",
  "maxResults": 20,
  "language": "",
  "repo": "",
  "filename": "",
  "path": ""
}
```

# Actor output Schema

## `records` (type: `string`):

All records produced by this run.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "query": "Session repo:psf/requests",
    "maxResults": 20
};

// Run the Actor and wait for it to finish
const run = await client.actor("automly/github-code-search-api").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "query": "Session repo:psf/requests",
    "maxResults": 20,
}

# Run the Actor and wait for it to finish
run = client.actor("automly/github-code-search-api").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "query": "Session repo:psf/requests",
  "maxResults": 20
}' |
apify call automly/github-code-search-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,automly/github-code-search-api"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/ioAxDiM559mptfi33/builds/vgWbGd1Ya1SNmaPZh/openapi.json
