---
title: ghapi
description: A delightful and complete interface to GitHub's amazing API
---
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

> **ghapi v2 (July 2026) is now async by default.** Every API call is now awaited: `res = await api.repos.get()`. Top-level `await` works directly in Jupyter and modern REPLs; in scripts, use `asyncio.run`. For sync code (which should be largely compatible with v1), use `GhApi(sync=True)`. See the [Sync usage](https://ghapi.fast.ai/core.html#sync-usage) section of the docs for details. To stay on the old version, pin `ghapi<2`.

[`ghapi`](cli.md#ghapi) provides Python and command-line access to the [GitHub REST API](https://docs.github.com/rest). It builds the Python API dynamically from a compact, pre-parsed copy of GitHub's [OpenAPI spec](https://docs.github.com/rest/overview/openapi-description).

Using [`ghapi`](cli.md#ghapi), you can automate nearly anything that you can do through the GitHub web interface or through the `git` client, such as:

- Open, list, comment on, or modify [issues](https://guides.github.com/features/issues/) or [pull requests](https://docs.github.com/github/collaborating-with-issues-and-pull-requests/about-pull-requests)
- Create, list, or modify [git tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging) or [GitHub releases](https://docs.github.com/github/administering-a-repository/managing-releases-in-a-repository), including uploading release assets
- Configure and run GitHub [Actions](https://github.com/features/actions) and [webhooks](https://docs.github.com/developers/webhooks-and-events/about-webhooks)
- Set up GitHub [users](https://docs.github.com/rest/reference/users) and [organizations](https://docs.github.com/github/setting-up-and-managing-organizations-and-teams/about-organizations)
- Manage your [deployments](https://docs.github.com/rest/guides/delivering-deployments)
- ...and much, much more.

There are two ways to use [`ghapi`](cli.md#ghapi): either through Python, or from the command line. An overview of each is provided below.

## Installation

To install, run `pip install ghapi`.

## How to use - Python

Throughout this documentation, you will see code inputs and outputs shown in this format:

```python
1+1
```

```output
2
```

We recommend reading the documentation on the [official site](https://ghapi.fast.ai/), rather than on GitHub, since not all the functionality described on this page is available through the GitHub viewer.

All of the documentation is available directly as Jupyter Notebooks, for instance the current page you're reading is available as a notebook [here](https://github.com/AnswerDotAI/ghapi/blob/main/ship/index.ipynb). To open any page as an interactive notebook in Google Colab, click the *Colab* badge at the top of the page.

To access the GitHub API, first create a [`GhApi`](core.md#ghapi) object. Note that as of v2, [`ghapi`](cli.md#ghapi) is async: every endpoint call is `await`ed. In Jupyter and modern Python REPLs top-level `await` just works, as shown below; in scripts, wrap your code in a function run with `asyncio.run`.

```python
from ghapi.all import GhApi
```

```python
api = GhApi()
```

Every part of the API includes documentation directly in the `api` object itself. For instance, here's how to explore the groups of functionality provided by the API by displaying the object:

```python
api
```

- [actions](https://docs.github.com/rest/reference/actions)
- [activity](https://docs.github.com/rest/reference/activity)
- [agent\_tasks](https://docs.github.com/rest/reference/agent-tasks)
- [agents](https://docs.github.com/rest/reference/agents)
- [api\_insights](https://docs.github.com/rest/reference/api-insights)
- [apps](https://docs.github.com/rest/reference/apps)
- [billing](https://docs.github.com/rest/reference/billing)
- [campaigns](https://docs.github.com/rest/reference/campaigns)
- [checks](https://docs.github.com/rest/reference/checks)
- [classroom](https://docs.github.com/rest/reference/classroom)
- [code\_quality](https://docs.github.com/rest/reference/code-quality)
- [code\_scanning](https://docs.github.com/rest/reference/code-scanning)
- [code\_security](https://docs.github.com/rest/reference/code-security)
- [codes\_of\_conduct](https://docs.github.com/rest/reference/codes-of-conduct)
- [codespaces](https://docs.github.com/rest/reference/codespaces)
- [copilot](https://docs.github.com/rest/reference/copilot)
- [copilot\_spaces](https://docs.github.com/rest/reference/copilot-spaces)
- [credentials](https://docs.github.com/rest/reference/credentials)
- [dependabot](https://docs.github.com/rest/reference/dependabot)
- [dependency\_graph](https://docs.github.com/rest/reference/dependency-graph)
- [emojis](https://docs.github.com/rest/reference/emojis)
- [enterprise\_team\_memberships](https://docs.github.com/rest/reference/enterprise-team-memberships)
- [enterprise\_team\_organizations](https://docs.github.com/rest/reference/enterprise-team-organizations)
- [enterprise\_teams](https://docs.github.com/rest/reference/enterprise-teams)
- [gists](https://docs.github.com/rest/reference/gists)
- [git](https://docs.github.com/rest/reference/git)
- [gitignore](https://docs.github.com/rest/reference/gitignore)
- [hosted\_compute](https://docs.github.com/rest/reference/hosted-compute)
- [interactions](https://docs.github.com/rest/reference/interactions)
- [issues](https://docs.github.com/rest/reference/issues)
- [licenses](https://docs.github.com/rest/reference/licenses)
- [markdown](https://docs.github.com/rest/reference/markdown)
- [meta](https://docs.github.com/rest/reference/meta)
- [migrations](https://docs.github.com/rest/reference/migrations)
- [oidc](https://docs.github.com/rest/reference/oidc)
- [orgs](https://docs.github.com/rest/reference/orgs)
- [packages](https://docs.github.com/rest/reference/packages)
- [private\_registries](https://docs.github.com/rest/reference/private-registries)
- [projects](https://docs.github.com/rest/reference/projects)
- [pull\_request\_stacks](https://docs.github.com/rest/reference/pull-request-stacks)
- [pulls](https://docs.github.com/rest/reference/pulls)
- [rate\_limit](https://docs.github.com/rest/reference/rate-limit)
- [reactions](https://docs.github.com/rest/reference/reactions)
- [repos](https://docs.github.com/rest/reference/repos)
- [search](https://docs.github.com/rest/reference/search)
- [secret\_scanning](https://docs.github.com/rest/reference/secret-scanning)
- [security\_advisories](https://docs.github.com/rest/reference/security-advisories)
- [teams](https://docs.github.com/rest/reference/teams)
- [users](https://docs.github.com/rest/reference/users)

Then we can explore the endpoints provided by the API in each group, e.g. for the `git` group:

```python
api.git
```

- [git.create\_blob](https://docs.github.com/rest/git/blobs#create-a-blob)(owner, repo, content, encoding): *Create a blob*
- [git.get\_blob](https://docs.github.com/rest/git/blobs#get-a-blob)(owner, repo, file\_sha): *Get a blob*
- [git.create\_commit](https://docs.github.com/rest/git/commits#create-a-commit)(owner, repo, message, tree, parents, author, committer, signature): *Create a commit*
- [git.get\_commit](https://docs.github.com/rest/git/commits#get-a-commit-object)(owner, repo, commit\_sha): *Get a commit object*
- [git.list\_matching\_refs](https://docs.github.com/rest/git/refs#list-matching-references)(owner, repo, ref): *List matching references*
- [git.get\_ref](https://docs.github.com/rest/git/refs#get-a-reference)(owner, repo, ref): *Get a reference*
- [git.create\_ref](https://docs.github.com/rest/git/refs#create-a-reference)(owner, repo, ref, sha): *Create a reference*
- [git.update\_ref](https://docs.github.com/rest/git/refs#update-a-reference)(owner, repo, ref, sha, force): *Update a reference*
- [git.delete\_ref](https://docs.github.com/rest/git/refs#delete-a-reference)(owner, repo, ref): *Delete a reference*
- [git.create\_tag](https://docs.github.com/rest/git/tags#create-a-tag-object)(owner, repo, tag, message, object, type, tagger): *Create a tag object*
- [git.get\_tag](https://docs.github.com/rest/git/tags#get-a-tag)(owner, repo, tag\_sha): *Get a tag*
- [git.create\_tree](https://docs.github.com/rest/git/trees#create-a-tree)(owner, repo, tree, base\_tree): *Create a tree*
- [git.get\_tree](https://docs.github.com/rest/git/trees#get-a-tree)(owner, repo, tree\_sha, recursive): *Get a tree*

Read an endpoint's full documentation on the generated object. Its display includes parameter descriptions, bound defaults, request controls, and async usage. With pyskills, use `doc(api.git.get_ref)` for the same documentation, or `xdir(api.git, 'ref')` to search names. Construction and discovery send no requests:

```python
api.git.get_ref
```

Get a reference

Docs: [https://docs.github.com/rest/git/refs\#get-a-reference](https://docs.github.com/rest/git/refs#get-a-reference)

Parameters:

- owner (str, required): The account owner of the repository. The name is not case sensitive.
- repo (str, required): The name of the repository without the `.git` extension. The name is not case sensitive.
- ref (str, required): The Git reference. For more information, see "[Git References](https://git-scm.com/book/en/v2/Git-Internals-Git-References)" in the Git documentation.

Jupyter provides full tab completion and parameter lists for every endpoint. Endpoints are called as standard Python methods:

```python
await api.git.get_ref(owner='fastai', repo='fastcore', ref='heads/master')
```

```python
{ 'node_id': 'MDM6UmVmMjI1NDYwNTk5OnJlZnMvaGVhZHMvbWFzdGVy',
  'object': { 'sha': 'c0608379fe60014534c8dffe2e381138e8160f53',
              'type': 'commit',
              'url': 'https://api.github.com/repos/AnswerDotAI/fastcore/git/commits/c0608379fe60014534c8dffe2e381138e8160f53'},
  'ref': 'refs/heads/master',
  'url': 'https://api.github.com/repos/AnswerDotAI/fastcore/git/refs/heads/master'}
```

To use authenticated operations (other than when running through GitHub Actions), you will need a GitHub [personal access token](https://docs.github.com/github/authenticating-to-github/creating-a-personal-access-token). If you don't have one, [click here](https://github.com/settings/tokens/new) to create it, choosing the scopes you need ("repo", "gist", "notifications", and "workflow" cover most uses). Save it as an environment variable named `GITHUB_TOKEN`, e.g. by adding this to your `.bashrc` or `.zshrc`:

```
export GITHUB_TOKEN=xxx
```

[`GhApi`](core.md#ghapi) uses that variable automatically, or you can pass `token=` explicitly.

As well as `token`, you can pass any parameters you want auto-inserted into relevant methods, such as `owner` and `repo`:

```python
api = GhApi(owner='fastai', repo='fastcore', token=github_token)
```

We can now repeat the previous method, but only need to pass `ref`:

```python
await api.git.get_ref('heads/master')
```

```python
{ 'node_id': 'MDM6UmVmMjI1NDYwNTk5OnJlZnMvaGVhZHMvbWFzdGVy',
  'object': { 'sha': 'c0608379fe60014534c8dffe2e381138e8160f53',
              'type': 'commit',
              'url': 'https://api.github.com/repos/AnswerDotAI/fastcore/git/commits/c0608379fe60014534c8dffe2e381138e8160f53'},
  'ref': 'refs/heads/master',
  'url': 'https://api.github.com/repos/AnswerDotAI/fastcore/git/refs/heads/master'}
```

Now that we've provided our token, we can use authenticated endpoints such as creating an issue:

```python
issue = await api.issues.create("Remember to check out GhApi!")
```

Since we've now checked out GhApi, let's close this issue. 😎

```python
await api.issues.update(issue.number, state='closed')
```

## Beyond the endpoints

The [GhApi details](https://ghapi.fast.ai/core.html) page covers helpers for common tasks:

- [`paged`](page.md#paged) and [`pages`](page.md#pages) fetch results from paginated endpoints.
- [`read_issue`](core.md#read_issue) and [`read_pr`](core.md#read_pr) collect issue or PR details, including comments, diffs and reviews as applicable.
- [`dep_graph`](core.md#dep_graph) and [`dep_order`](core.md#dep_order) find repository dependencies and put repositories in dependency order.
- Other helpers manage gists, releases, branches and repository files.

For CI, [`check_status`](core.md#check_status) combines commit statuses and check runs. [`failed_step_log`](core.md#failed_step_log) retrieves logs from a failed step. Here's the status of a branch:

```python
api = GhApi(owner='AnswerDotAI', repo='ghapi', token=github_token)
await api.check_status('main')
```

**failure**

- 93199230629  update-pip-graph: success (46s)
- 93199227080  deploy: failure (22s)

## GraphQL

Use the [GraphQL client](https://ghapi.fast.ai/graphql.html) to read several repositories in one query instead of making a REST call for each. Build query fragments by attribute chaining, with schema checks as you go. `batch` groups them into parallel requests.

Here we fetch several repositories' head commits. The GraphQL docs also cover interactive schema discovery, cursor pagination and raw queries:

```python
from ghapi.graphql import GhGql
```

```python
gql = GhGql()
await gql.batch(*[gql.repository(owner='AnswerDotAI', name=n).defaultBranchRef.target.oid
    for n in ('fastcore', 'fasthtml', 'ghapi')])
```

```output
['25c4f3228ccac3c5a63da71b5eaa4be3c428f602',
 'e5d967ae627c63035e296e6f319f220e278327e7',
 'ad07893daac86de6693bc9bb57ae7216c1b347d0']
```

## How to use - command line

You can use [`GhApi`](core.md#ghapi) via the command line, and can access nearly everything in the [GitHub API](https://docs.github.com/rest). We provide an overview here of one of the command line programs, [`ghapi`](cli.md#ghapi) -- see the full CLI docs page for details on all the programs available.

We strongly recommend enabling tab completion for [`ghapi`](cli.md#ghapi), which you can do by placing the following command at the end of your `~/.bashrc` or `~/.zshrc` file:

```bash
eval "$(completion-ghapi --install)"
```

To get started with the [`ghapi`](cli.md#ghapi) command, first find the name of the operation you wish to perform, for instance by searching the [full API reference](https://ghapi.fast.ai/fullapi.html).

To use [`ghapi`](cli.md#ghapi), pass the method name (exactly the same as you'd use in the Python API) as the first parameter, followed by any positional parameters required, and then keyword arguments with "`--`" before each parameter name.

For instance, [git.get\_ref](https://ghapi.fast.ai/fullapi.html#git) takes three parameters: `owner`, `repo`, and `ref`. If we wish to pass the first two as positional parameters, and the last as a named argument, then we'd call:

```bash
ghapi git.get_ref fastai ghapi-test --ref heads/master
```

If you have enabled tab completion, then after you've typed `ghapi g` try pressing <kbd>Tab</kbd>, and you'll see all the operation groups available in the GitHub API that start with `g`. If you keep typing, e.g. `ghapi git.`, and hit <kbd>Tab</kbd> again, you'll now see all the operations available in the `git` group, i.e:

```
git.create_blob git.create_commit git.create_ref git.create_tag git.create_tree git.delete_ref git.get_blob git.get_commit git.get_ref git.get_tag git.get_tree git.list_matching_refs git.name git.update_ref git.verbs
```

If you pass just `--help` after the operation name, you'll see a full list of all parameters accepted, and a link to the official GitHub documentation.

```bash
ghapi git.get_ref --help
>>> git.get_ref(owner, repo, ref)
>>> https://docs.github.com/rest/reference/git#get-a-reference
```

In addition to `--help` and the GitHub operation parameters, you can also pass the following:

- `--headers`: A list of extra headers to pass, JSON-encoded
- `--token`: A GitHub authentation token
- `--debug`: Print requests before sending them
