ghapi 1.1.0__tar.gz → 2.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ghapi-1.1.0 → ghapi-2.0.1}/MANIFEST.in +0 -1
- ghapi-2.0.1/PKG-INFO +277 -0
- ghapi-2.0.1/README.md +248 -0
- ghapi-2.0.1/ghapi/__init__.py +1 -0
- {ghapi-1.1.0 → ghapi-2.0.1}/ghapi/_modidx.py +22 -25
- {ghapi-1.1.0 → ghapi-2.0.1}/ghapi/actions.py +4 -4
- ghapi-2.0.1/ghapi/build_lib.py +20 -0
- {ghapi-1.1.0 → ghapi-2.0.1}/ghapi/cli.py +7 -6
- ghapi-2.0.1/ghapi/core.py +517 -0
- {ghapi-1.1.0 → ghapi-2.0.1}/ghapi/event.py +14 -13
- ghapi-2.0.1/ghapi/gh_spec.py +16361 -0
- ghapi-2.0.1/ghapi/page.py +103 -0
- ghapi-2.0.1/ghapi/skill.py +112 -0
- {ghapi-1.1.0 → ghapi-2.0.1}/ghapi/templates.py +6 -6
- ghapi-2.0.1/ghapi.egg-info/PKG-INFO +277 -0
- {ghapi-1.1.0 → ghapi-2.0.1}/ghapi.egg-info/SOURCES.txt +1 -2
- {ghapi-1.1.0 → ghapi-2.0.1}/ghapi.egg-info/requires.txt +4 -3
- {ghapi-1.1.0 → ghapi-2.0.1}/pyproject.toml +3 -3
- ghapi-1.1.0/PKG-INFO +0 -331
- ghapi-1.1.0/README.md +0 -303
- ghapi-1.1.0/ghapi/__init__.py +0 -1
- ghapi-1.1.0/ghapi/_nbdev.py +0 -91
- ghapi-1.1.0/ghapi/build_lib.py +0 -59
- ghapi-1.1.0/ghapi/core.py +0 -470
- ghapi-1.1.0/ghapi/metadata.py +0 -1946
- ghapi-1.1.0/ghapi/page.py +0 -74
- ghapi-1.1.0/ghapi/skill.py +0 -68
- ghapi-1.1.0/ghapi.egg-info/PKG-INFO +0 -331
- {ghapi-1.1.0 → ghapi-2.0.1}/CONTRIBUTING.md +0 -0
- {ghapi-1.1.0 → ghapi-2.0.1}/LICENSE +0 -0
- {ghapi-1.1.0 → ghapi-2.0.1}/ghapi/all.py +0 -0
- {ghapi-1.1.0 → ghapi-2.0.1}/ghapi/auth.py +0 -0
- {ghapi-1.1.0 → ghapi-2.0.1}/ghapi/graphql.py +0 -0
- {ghapi-1.1.0 → ghapi-2.0.1}/ghapi/py.typed +0 -0
- {ghapi-1.1.0 → ghapi-2.0.1}/ghapi.egg-info/dependency_links.txt +0 -0
- {ghapi-1.1.0 → ghapi-2.0.1}/ghapi.egg-info/entry_points.txt +0 -0
- {ghapi-1.1.0 → ghapi-2.0.1}/ghapi.egg-info/top_level.txt +0 -0
- {ghapi-1.1.0 → ghapi-2.0.1}/setup.cfg +0 -0
ghapi-2.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ghapi
|
|
3
|
+
Version: 2.0.1
|
|
4
|
+
Summary: A python client for the GitHub API
|
|
5
|
+
Author-email: Jeremy Howard <info@fast.ai>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Repository, https://github.com/fastai/ghapi
|
|
8
|
+
Project-URL: Documentation, https://ghapi.fast.ai/
|
|
9
|
+
Keywords: github,api
|
|
10
|
+
Classifier: Natural Language :: English
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: fastcore>=1.14.5
|
|
19
|
+
Requires-Dist: fastspec>=0.1.0
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: fastgit; extra == "dev"
|
|
22
|
+
Requires-Dist: matplotlib; extra == "dev"
|
|
23
|
+
Requires-Dist: nbclassic; extra == "dev"
|
|
24
|
+
Requires-Dist: nbdev; extra == "dev"
|
|
25
|
+
Requires-Dist: pyyaml; extra == "dev"
|
|
26
|
+
Requires-Dist: pysym2md>=0.0.6; extra == "dev"
|
|
27
|
+
Requires-Dist: llms-txt>=0.0.6; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# ghapi
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
|
|
34
|
+
|
|
35
|
+
> **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`](https://docs.python.org/3/library/asyncio-runner.html#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`.
|
|
36
|
+
|
|
37
|
+
[`ghapi`](https://ghapi.fast.ai/cli.html#ghapi) provides 100% always-updated coverage of the entire [GitHub API](https://docs.github.com/rest). Because we automatically convert the [OpenAPI spec](https://docs.github.com/rest/overview/openapi-description) to a Pythonic API, [`ghapi`](https://ghapi.fast.ai/cli.html#ghapi) is always up to date with the latest changes to GitHub APIs. Furthermore, because this is all built dynamically from a compact pre-parsed copy of the spec, the package stays small and is always up to date.
|
|
38
|
+
|
|
39
|
+
Using [`ghapi`](https://ghapi.fast.ai/cli.html#ghapi), you can automate nearly anything that you can do through the GitHub web interface or through the `git` client, such as:
|
|
40
|
+
|
|
41
|
+
- 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)
|
|
42
|
+
- 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
|
|
43
|
+
- Configure and run GitHub [Actions](https://github.com/features/actions) and [webhooks](https://docs.github.com/developers/webhooks-and-events/about-webhooks)
|
|
44
|
+
- 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)
|
|
45
|
+
- Manage your [deployments](https://docs.github.com/rest/guides/delivering-deployments)
|
|
46
|
+
- …and much, much more.
|
|
47
|
+
|
|
48
|
+
There are two ways to use [`ghapi`](https://ghapi.fast.ai/cli.html#ghapi): either through Python, or from the command line. An overview of each is provided below.
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
To install, run `pip install ghapi`.
|
|
53
|
+
|
|
54
|
+
## How to use - Python
|
|
55
|
+
|
|
56
|
+
Throughout this documentation, you will see code inputs and outputs shown in this format:
|
|
57
|
+
|
|
58
|
+
``` python
|
|
59
|
+
1+1
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
2
|
|
63
|
+
|
|
64
|
+
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.
|
|
65
|
+
|
|
66
|
+
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/nbs/index.ipynb). To open any page as an interactive notebook in Google Colab, click the *Colab* badge at the top of the page.
|
|
67
|
+
|
|
68
|
+
To access the GitHub API, first create a [`GhApi`](https://ghapi.fast.ai/core.html#ghapi) object. Note that as of v2, [`ghapi`](https://ghapi.fast.ai/cli.html#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`](https://docs.python.org/3/library/asyncio-runner.html#asyncio.run).
|
|
69
|
+
|
|
70
|
+
``` python
|
|
71
|
+
from ghapi.all import GhApi
|
|
72
|
+
api = GhApi()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
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:
|
|
76
|
+
|
|
77
|
+
``` python
|
|
78
|
+
api
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
<div class="prose" markdown="1">
|
|
82
|
+
|
|
83
|
+
- [actions](https://docs.github.com/rest/reference/actions)
|
|
84
|
+
- [activity](https://docs.github.com/rest/reference/activity)
|
|
85
|
+
- [agent_tasks](https://docs.github.com/rest/reference/agent-tasks)
|
|
86
|
+
- [agents](https://docs.github.com/rest/reference/agents)
|
|
87
|
+
- [api_insights](https://docs.github.com/rest/reference/api-insights)
|
|
88
|
+
- [apps](https://docs.github.com/rest/reference/apps)
|
|
89
|
+
- [billing](https://docs.github.com/rest/reference/billing)
|
|
90
|
+
- [campaigns](https://docs.github.com/rest/reference/campaigns)
|
|
91
|
+
- [checks](https://docs.github.com/rest/reference/checks)
|
|
92
|
+
- [classroom](https://docs.github.com/rest/reference/classroom)
|
|
93
|
+
- [code_quality](https://docs.github.com/rest/reference/code-quality)
|
|
94
|
+
- [code_scanning](https://docs.github.com/rest/reference/code-scanning)
|
|
95
|
+
- [code_security](https://docs.github.com/rest/reference/code-security)
|
|
96
|
+
- [codes_of_conduct](https://docs.github.com/rest/reference/codes-of-conduct)
|
|
97
|
+
- [codespaces](https://docs.github.com/rest/reference/codespaces)
|
|
98
|
+
- [copilot](https://docs.github.com/rest/reference/copilot)
|
|
99
|
+
- [copilot_spaces](https://docs.github.com/rest/reference/copilot-spaces)
|
|
100
|
+
- [credentials](https://docs.github.com/rest/reference/credentials)
|
|
101
|
+
- [dependabot](https://docs.github.com/rest/reference/dependabot)
|
|
102
|
+
- [dependency_graph](https://docs.github.com/rest/reference/dependency-graph)
|
|
103
|
+
- [emojis](https://docs.github.com/rest/reference/emojis)
|
|
104
|
+
- [enterprise_team_memberships](https://docs.github.com/rest/reference/enterprise-team-memberships)
|
|
105
|
+
- [enterprise_team_organizations](https://docs.github.com/rest/reference/enterprise-team-organizations)
|
|
106
|
+
- [enterprise_teams](https://docs.github.com/rest/reference/enterprise-teams)
|
|
107
|
+
- [gists](https://docs.github.com/rest/reference/gists)
|
|
108
|
+
- [git](https://docs.github.com/rest/reference/git)
|
|
109
|
+
- [gitignore](https://docs.github.com/rest/reference/gitignore)
|
|
110
|
+
- [hosted_compute](https://docs.github.com/rest/reference/hosted-compute)
|
|
111
|
+
- [interactions](https://docs.github.com/rest/reference/interactions)
|
|
112
|
+
- [issues](https://docs.github.com/rest/reference/issues)
|
|
113
|
+
- [licenses](https://docs.github.com/rest/reference/licenses)
|
|
114
|
+
- [markdown](https://docs.github.com/rest/reference/markdown)
|
|
115
|
+
- [meta](https://docs.github.com/rest/reference/meta)
|
|
116
|
+
- [migrations](https://docs.github.com/rest/reference/migrations)
|
|
117
|
+
- [oidc](https://docs.github.com/rest/reference/oidc)
|
|
118
|
+
- [orgs](https://docs.github.com/rest/reference/orgs)
|
|
119
|
+
- [packages](https://docs.github.com/rest/reference/packages)
|
|
120
|
+
- [private_registries](https://docs.github.com/rest/reference/private-registries)
|
|
121
|
+
- [projects](https://docs.github.com/rest/reference/projects)
|
|
122
|
+
- [pulls](https://docs.github.com/rest/reference/pulls)
|
|
123
|
+
- [rate_limit](https://docs.github.com/rest/reference/rate-limit)
|
|
124
|
+
- [reactions](https://docs.github.com/rest/reference/reactions)
|
|
125
|
+
- [repos](https://docs.github.com/rest/reference/repos)
|
|
126
|
+
- [search](https://docs.github.com/rest/reference/search)
|
|
127
|
+
- [secret_scanning](https://docs.github.com/rest/reference/secret-scanning)
|
|
128
|
+
- [security_advisories](https://docs.github.com/rest/reference/security-advisories)
|
|
129
|
+
- [teams](https://docs.github.com/rest/reference/teams)
|
|
130
|
+
- [users](https://docs.github.com/rest/reference/users)
|
|
131
|
+
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
Then we can explore the endpoints provided by the API in each group, e.g. for the `git` group:
|
|
135
|
+
|
|
136
|
+
``` python
|
|
137
|
+
api.git
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
<div class="prose" markdown="1">
|
|
141
|
+
|
|
142
|
+
- [git.create_blob](https://docs.github.com/rest/git/blobs#create-a-blob)(owner, repo, content, encoding): *Create a blob*
|
|
143
|
+
- [git.get_blob](https://docs.github.com/rest/git/blobs#get-a-blob)(owner, repo, file_sha): *Get a blob*
|
|
144
|
+
- [git.create_commit](https://docs.github.com/rest/git/commits#create-a-commit)(owner, repo, message, tree, parents, author, committer, signature): *Create a commit*
|
|
145
|
+
- [git.get_commit](https://docs.github.com/rest/git/commits#get-a-commit-object)(owner, repo, commit_sha): *Get a commit object*
|
|
146
|
+
- [git.list_matching_refs](https://docs.github.com/rest/git/refs#list-matching-references)(owner, repo, ref): *List matching references*
|
|
147
|
+
- [git.get_ref](https://docs.github.com/rest/git/refs#get-a-reference)(owner, repo, ref): *Get a reference*
|
|
148
|
+
- [git.create_ref](https://docs.github.com/rest/git/refs#create-a-reference)(owner, repo, ref, sha): *Create a reference*
|
|
149
|
+
- [git.update_ref](https://docs.github.com/rest/git/refs#update-a-reference)(owner, repo, ref, sha, force): *Update a reference*
|
|
150
|
+
- [git.delete_ref](https://docs.github.com/rest/git/refs#delete-a-reference)(owner, repo, ref): *Delete a reference*
|
|
151
|
+
- [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*
|
|
152
|
+
- [git.get_tag](https://docs.github.com/rest/git/tags#get-a-tag)(owner, repo, tag_sha): *Get a tag*
|
|
153
|
+
- [git.create_tree](https://docs.github.com/rest/git/trees#create-a-tree)(owner, repo, tree, base_tree): *Create a tree*
|
|
154
|
+
- [git.get_tree](https://docs.github.com/rest/git/trees#get-a-tree)(owner, repo, tree_sha, recursive): *Get a tree*
|
|
155
|
+
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
Here’s how to learn about an endpoint you want to use, e.g.:
|
|
159
|
+
|
|
160
|
+
``` python
|
|
161
|
+
api.git.get_ref
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
<div class="prose" markdown="1">
|
|
165
|
+
|
|
166
|
+
Get a reference
|
|
167
|
+
|
|
168
|
+
Docs: https://docs.github.com/rest/git/refs#get-a-reference
|
|
169
|
+
|
|
170
|
+
Parameters:
|
|
171
|
+
- owner (str, required): The account owner of the repository. The name is not case sensitive.
|
|
172
|
+
- repo (str, required): The name of the repository without the `.git` extension. The name is not case sensitive.
|
|
173
|
+
- 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.
|
|
174
|
+
|
|
175
|
+
</div>
|
|
176
|
+
|
|
177
|
+
In Jupyter Notebook full tab completion, parameter lists, etc are provided for all endpoints. Endpoints are called as standard Python methods:
|
|
178
|
+
|
|
179
|
+
``` python
|
|
180
|
+
await api.git.get_ref(owner='fastai', repo='fastcore', ref='heads/master')
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
<div class="prose" markdown="1">
|
|
184
|
+
|
|
185
|
+
``` python
|
|
186
|
+
{ 'node_id': 'MDM6UmVmMjI1NDYwNTk5OnJlZnMvaGVhZHMvbWFzdGVy',
|
|
187
|
+
'object': { 'sha': 'c0608379fe60014534c8dffe2e381138e8160f53',
|
|
188
|
+
'type': 'commit',
|
|
189
|
+
'url': 'https://api.github.com/repos/AnswerDotAI/fastcore/git/commits/c0608379fe60014534c8dffe2e381138e8160f53'},
|
|
190
|
+
'ref': 'refs/heads/master',
|
|
191
|
+
'url': 'https://api.github.com/repos/AnswerDotAI/fastcore/git/refs/heads/master'}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
</div>
|
|
195
|
+
|
|
196
|
+
To use [`ghapi`](https://ghapi.fast.ai/cli.html#ghapi) to access 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), which is a secret code used to access your account. If you don’t have one, [click here](https://github.com/settings/tokens/new) to create one. You’ll be asked to enter a name – choose anything you like, for instance “*ghapi*”. You’ll also be asked to choose “scopes”; this limits what you’ll be able to do with the API using this token. If you’re not sure, click “*repo*” “*gist*”, “*notifications*”, and “*workflow*”. Then click “Generate Token” at the bottom of the screen, and copy the token (the long string of letters and numbers shown). You can easily do that by clicking the little clipboard icon next to the token.
|
|
197
|
+
|
|
198
|
+
Rather than pasting that token into every script, it’s easiest to save it as an environment variable. If you save it as `$GITHUB_TOKEN` then it will be most convenient, so add this to the end of your `.bashrc` or `.zshrc` file:
|
|
199
|
+
|
|
200
|
+
export GITHUB_TOKEN=xxx
|
|
201
|
+
|
|
202
|
+
…replacing the `xxx` with the token you just copied. (Don’t forget to `source` that file after you change it.), pass a \[GitHub token\].
|
|
203
|
+
|
|
204
|
+
As well as your `token`, you can also pass any parameters you want auto-inserted into relevant methods, such as `owner` and `repo`:
|
|
205
|
+
|
|
206
|
+
``` python
|
|
207
|
+
api = GhApi(owner='fastai', repo='fastcore', token=github_token)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
We can now repeat the previous method, but only need to pass `ref`:
|
|
211
|
+
|
|
212
|
+
``` python
|
|
213
|
+
await api.git.get_ref('heads/master')
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
<div class="prose" markdown="1">
|
|
217
|
+
|
|
218
|
+
``` python
|
|
219
|
+
{ 'node_id': 'MDM6UmVmMjI1NDYwNTk5OnJlZnMvaGVhZHMvbWFzdGVy',
|
|
220
|
+
'object': { 'sha': 'c0608379fe60014534c8dffe2e381138e8160f53',
|
|
221
|
+
'type': 'commit',
|
|
222
|
+
'url': 'https://api.github.com/repos/AnswerDotAI/fastcore/git/commits/c0608379fe60014534c8dffe2e381138e8160f53'},
|
|
223
|
+
'ref': 'refs/heads/master',
|
|
224
|
+
'url': 'https://api.github.com/repos/AnswerDotAI/fastcore/git/refs/heads/master'}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
</div>
|
|
228
|
+
|
|
229
|
+
Now that we’ve provided our token, we can use authenticated endpoints such as creating an issue:
|
|
230
|
+
|
|
231
|
+
``` python
|
|
232
|
+
issue = await api.issues.create("Remember to check out GhApi!")
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Since we’ve now checked out GhApi, let’s close this issue. 😎
|
|
236
|
+
|
|
237
|
+
``` python
|
|
238
|
+
await api.issues.update(issue.number, state='closed')
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## How to use - command line
|
|
242
|
+
|
|
243
|
+
You can use [`GhApi`](https://ghapi.fast.ai/core.html#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`](https://ghapi.fast.ai/cli.html#ghapi) – see the full CLI docs page for details on all the programs available.
|
|
244
|
+
|
|
245
|
+
We strongly recommend enabling tab completion for [`ghapi`](https://ghapi.fast.ai/cli.html#ghapi), which you can do by placing the following command at the end of your `~/.bashrc` or `~/.zshrc` file:
|
|
246
|
+
|
|
247
|
+
``` bash
|
|
248
|
+
eval "$(completion-ghapi --install)"
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
To get started with the [`ghapi`](https://ghapi.fast.ai/cli.html#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).
|
|
252
|
+
|
|
253
|
+
To use [`ghapi`](https://ghapi.fast.ai/cli.html#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.
|
|
254
|
+
|
|
255
|
+
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:
|
|
256
|
+
|
|
257
|
+
``` bash
|
|
258
|
+
ghapi git.get_ref fastai ghapi-test --ref heads/master
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
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:
|
|
262
|
+
|
|
263
|
+
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
|
|
264
|
+
|
|
265
|
+
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.
|
|
266
|
+
|
|
267
|
+
``` bash
|
|
268
|
+
ghapi git.get_ref --help
|
|
269
|
+
>>> git.get_ref(owner, repo, ref)
|
|
270
|
+
>>> https://docs.github.com/rest/reference/git#get-a-reference
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
In addition to `--help` and the GitHub operation parameters, you can also pass the following:
|
|
274
|
+
|
|
275
|
+
- `--headers`: A list of extra headers to pass, JSON-encoded
|
|
276
|
+
- `--token`: A GitHub authentation token
|
|
277
|
+
- `--debug`: Print requests before sending them
|
ghapi-2.0.1/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# ghapi
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
|
|
5
|
+
|
|
6
|
+
> **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`](https://docs.python.org/3/library/asyncio-runner.html#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`.
|
|
7
|
+
|
|
8
|
+
[`ghapi`](https://ghapi.fast.ai/cli.html#ghapi) provides 100% always-updated coverage of the entire [GitHub API](https://docs.github.com/rest). Because we automatically convert the [OpenAPI spec](https://docs.github.com/rest/overview/openapi-description) to a Pythonic API, [`ghapi`](https://ghapi.fast.ai/cli.html#ghapi) is always up to date with the latest changes to GitHub APIs. Furthermore, because this is all built dynamically from a compact pre-parsed copy of the spec, the package stays small and is always up to date.
|
|
9
|
+
|
|
10
|
+
Using [`ghapi`](https://ghapi.fast.ai/cli.html#ghapi), you can automate nearly anything that you can do through the GitHub web interface or through the `git` client, such as:
|
|
11
|
+
|
|
12
|
+
- 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)
|
|
13
|
+
- 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
|
|
14
|
+
- Configure and run GitHub [Actions](https://github.com/features/actions) and [webhooks](https://docs.github.com/developers/webhooks-and-events/about-webhooks)
|
|
15
|
+
- 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)
|
|
16
|
+
- Manage your [deployments](https://docs.github.com/rest/guides/delivering-deployments)
|
|
17
|
+
- …and much, much more.
|
|
18
|
+
|
|
19
|
+
There are two ways to use [`ghapi`](https://ghapi.fast.ai/cli.html#ghapi): either through Python, or from the command line. An overview of each is provided below.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
To install, run `pip install ghapi`.
|
|
24
|
+
|
|
25
|
+
## How to use - Python
|
|
26
|
+
|
|
27
|
+
Throughout this documentation, you will see code inputs and outputs shown in this format:
|
|
28
|
+
|
|
29
|
+
``` python
|
|
30
|
+
1+1
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
2
|
|
34
|
+
|
|
35
|
+
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.
|
|
36
|
+
|
|
37
|
+
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/nbs/index.ipynb). To open any page as an interactive notebook in Google Colab, click the *Colab* badge at the top of the page.
|
|
38
|
+
|
|
39
|
+
To access the GitHub API, first create a [`GhApi`](https://ghapi.fast.ai/core.html#ghapi) object. Note that as of v2, [`ghapi`](https://ghapi.fast.ai/cli.html#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`](https://docs.python.org/3/library/asyncio-runner.html#asyncio.run).
|
|
40
|
+
|
|
41
|
+
``` python
|
|
42
|
+
from ghapi.all import GhApi
|
|
43
|
+
api = GhApi()
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
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:
|
|
47
|
+
|
|
48
|
+
``` python
|
|
49
|
+
api
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
<div class="prose" markdown="1">
|
|
53
|
+
|
|
54
|
+
- [actions](https://docs.github.com/rest/reference/actions)
|
|
55
|
+
- [activity](https://docs.github.com/rest/reference/activity)
|
|
56
|
+
- [agent_tasks](https://docs.github.com/rest/reference/agent-tasks)
|
|
57
|
+
- [agents](https://docs.github.com/rest/reference/agents)
|
|
58
|
+
- [api_insights](https://docs.github.com/rest/reference/api-insights)
|
|
59
|
+
- [apps](https://docs.github.com/rest/reference/apps)
|
|
60
|
+
- [billing](https://docs.github.com/rest/reference/billing)
|
|
61
|
+
- [campaigns](https://docs.github.com/rest/reference/campaigns)
|
|
62
|
+
- [checks](https://docs.github.com/rest/reference/checks)
|
|
63
|
+
- [classroom](https://docs.github.com/rest/reference/classroom)
|
|
64
|
+
- [code_quality](https://docs.github.com/rest/reference/code-quality)
|
|
65
|
+
- [code_scanning](https://docs.github.com/rest/reference/code-scanning)
|
|
66
|
+
- [code_security](https://docs.github.com/rest/reference/code-security)
|
|
67
|
+
- [codes_of_conduct](https://docs.github.com/rest/reference/codes-of-conduct)
|
|
68
|
+
- [codespaces](https://docs.github.com/rest/reference/codespaces)
|
|
69
|
+
- [copilot](https://docs.github.com/rest/reference/copilot)
|
|
70
|
+
- [copilot_spaces](https://docs.github.com/rest/reference/copilot-spaces)
|
|
71
|
+
- [credentials](https://docs.github.com/rest/reference/credentials)
|
|
72
|
+
- [dependabot](https://docs.github.com/rest/reference/dependabot)
|
|
73
|
+
- [dependency_graph](https://docs.github.com/rest/reference/dependency-graph)
|
|
74
|
+
- [emojis](https://docs.github.com/rest/reference/emojis)
|
|
75
|
+
- [enterprise_team_memberships](https://docs.github.com/rest/reference/enterprise-team-memberships)
|
|
76
|
+
- [enterprise_team_organizations](https://docs.github.com/rest/reference/enterprise-team-organizations)
|
|
77
|
+
- [enterprise_teams](https://docs.github.com/rest/reference/enterprise-teams)
|
|
78
|
+
- [gists](https://docs.github.com/rest/reference/gists)
|
|
79
|
+
- [git](https://docs.github.com/rest/reference/git)
|
|
80
|
+
- [gitignore](https://docs.github.com/rest/reference/gitignore)
|
|
81
|
+
- [hosted_compute](https://docs.github.com/rest/reference/hosted-compute)
|
|
82
|
+
- [interactions](https://docs.github.com/rest/reference/interactions)
|
|
83
|
+
- [issues](https://docs.github.com/rest/reference/issues)
|
|
84
|
+
- [licenses](https://docs.github.com/rest/reference/licenses)
|
|
85
|
+
- [markdown](https://docs.github.com/rest/reference/markdown)
|
|
86
|
+
- [meta](https://docs.github.com/rest/reference/meta)
|
|
87
|
+
- [migrations](https://docs.github.com/rest/reference/migrations)
|
|
88
|
+
- [oidc](https://docs.github.com/rest/reference/oidc)
|
|
89
|
+
- [orgs](https://docs.github.com/rest/reference/orgs)
|
|
90
|
+
- [packages](https://docs.github.com/rest/reference/packages)
|
|
91
|
+
- [private_registries](https://docs.github.com/rest/reference/private-registries)
|
|
92
|
+
- [projects](https://docs.github.com/rest/reference/projects)
|
|
93
|
+
- [pulls](https://docs.github.com/rest/reference/pulls)
|
|
94
|
+
- [rate_limit](https://docs.github.com/rest/reference/rate-limit)
|
|
95
|
+
- [reactions](https://docs.github.com/rest/reference/reactions)
|
|
96
|
+
- [repos](https://docs.github.com/rest/reference/repos)
|
|
97
|
+
- [search](https://docs.github.com/rest/reference/search)
|
|
98
|
+
- [secret_scanning](https://docs.github.com/rest/reference/secret-scanning)
|
|
99
|
+
- [security_advisories](https://docs.github.com/rest/reference/security-advisories)
|
|
100
|
+
- [teams](https://docs.github.com/rest/reference/teams)
|
|
101
|
+
- [users](https://docs.github.com/rest/reference/users)
|
|
102
|
+
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
Then we can explore the endpoints provided by the API in each group, e.g. for the `git` group:
|
|
106
|
+
|
|
107
|
+
``` python
|
|
108
|
+
api.git
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
<div class="prose" markdown="1">
|
|
112
|
+
|
|
113
|
+
- [git.create_blob](https://docs.github.com/rest/git/blobs#create-a-blob)(owner, repo, content, encoding): *Create a blob*
|
|
114
|
+
- [git.get_blob](https://docs.github.com/rest/git/blobs#get-a-blob)(owner, repo, file_sha): *Get a blob*
|
|
115
|
+
- [git.create_commit](https://docs.github.com/rest/git/commits#create-a-commit)(owner, repo, message, tree, parents, author, committer, signature): *Create a commit*
|
|
116
|
+
- [git.get_commit](https://docs.github.com/rest/git/commits#get-a-commit-object)(owner, repo, commit_sha): *Get a commit object*
|
|
117
|
+
- [git.list_matching_refs](https://docs.github.com/rest/git/refs#list-matching-references)(owner, repo, ref): *List matching references*
|
|
118
|
+
- [git.get_ref](https://docs.github.com/rest/git/refs#get-a-reference)(owner, repo, ref): *Get a reference*
|
|
119
|
+
- [git.create_ref](https://docs.github.com/rest/git/refs#create-a-reference)(owner, repo, ref, sha): *Create a reference*
|
|
120
|
+
- [git.update_ref](https://docs.github.com/rest/git/refs#update-a-reference)(owner, repo, ref, sha, force): *Update a reference*
|
|
121
|
+
- [git.delete_ref](https://docs.github.com/rest/git/refs#delete-a-reference)(owner, repo, ref): *Delete a reference*
|
|
122
|
+
- [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*
|
|
123
|
+
- [git.get_tag](https://docs.github.com/rest/git/tags#get-a-tag)(owner, repo, tag_sha): *Get a tag*
|
|
124
|
+
- [git.create_tree](https://docs.github.com/rest/git/trees#create-a-tree)(owner, repo, tree, base_tree): *Create a tree*
|
|
125
|
+
- [git.get_tree](https://docs.github.com/rest/git/trees#get-a-tree)(owner, repo, tree_sha, recursive): *Get a tree*
|
|
126
|
+
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
Here’s how to learn about an endpoint you want to use, e.g.:
|
|
130
|
+
|
|
131
|
+
``` python
|
|
132
|
+
api.git.get_ref
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
<div class="prose" markdown="1">
|
|
136
|
+
|
|
137
|
+
Get a reference
|
|
138
|
+
|
|
139
|
+
Docs: https://docs.github.com/rest/git/refs#get-a-reference
|
|
140
|
+
|
|
141
|
+
Parameters:
|
|
142
|
+
- owner (str, required): The account owner of the repository. The name is not case sensitive.
|
|
143
|
+
- repo (str, required): The name of the repository without the `.git` extension. The name is not case sensitive.
|
|
144
|
+
- 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.
|
|
145
|
+
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
In Jupyter Notebook full tab completion, parameter lists, etc are provided for all endpoints. Endpoints are called as standard Python methods:
|
|
149
|
+
|
|
150
|
+
``` python
|
|
151
|
+
await api.git.get_ref(owner='fastai', repo='fastcore', ref='heads/master')
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
<div class="prose" markdown="1">
|
|
155
|
+
|
|
156
|
+
``` python
|
|
157
|
+
{ 'node_id': 'MDM6UmVmMjI1NDYwNTk5OnJlZnMvaGVhZHMvbWFzdGVy',
|
|
158
|
+
'object': { 'sha': 'c0608379fe60014534c8dffe2e381138e8160f53',
|
|
159
|
+
'type': 'commit',
|
|
160
|
+
'url': 'https://api.github.com/repos/AnswerDotAI/fastcore/git/commits/c0608379fe60014534c8dffe2e381138e8160f53'},
|
|
161
|
+
'ref': 'refs/heads/master',
|
|
162
|
+
'url': 'https://api.github.com/repos/AnswerDotAI/fastcore/git/refs/heads/master'}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
</div>
|
|
166
|
+
|
|
167
|
+
To use [`ghapi`](https://ghapi.fast.ai/cli.html#ghapi) to access 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), which is a secret code used to access your account. If you don’t have one, [click here](https://github.com/settings/tokens/new) to create one. You’ll be asked to enter a name – choose anything you like, for instance “*ghapi*”. You’ll also be asked to choose “scopes”; this limits what you’ll be able to do with the API using this token. If you’re not sure, click “*repo*” “*gist*”, “*notifications*”, and “*workflow*”. Then click “Generate Token” at the bottom of the screen, and copy the token (the long string of letters and numbers shown). You can easily do that by clicking the little clipboard icon next to the token.
|
|
168
|
+
|
|
169
|
+
Rather than pasting that token into every script, it’s easiest to save it as an environment variable. If you save it as `$GITHUB_TOKEN` then it will be most convenient, so add this to the end of your `.bashrc` or `.zshrc` file:
|
|
170
|
+
|
|
171
|
+
export GITHUB_TOKEN=xxx
|
|
172
|
+
|
|
173
|
+
…replacing the `xxx` with the token you just copied. (Don’t forget to `source` that file after you change it.), pass a \[GitHub token\].
|
|
174
|
+
|
|
175
|
+
As well as your `token`, you can also pass any parameters you want auto-inserted into relevant methods, such as `owner` and `repo`:
|
|
176
|
+
|
|
177
|
+
``` python
|
|
178
|
+
api = GhApi(owner='fastai', repo='fastcore', token=github_token)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
We can now repeat the previous method, but only need to pass `ref`:
|
|
182
|
+
|
|
183
|
+
``` python
|
|
184
|
+
await api.git.get_ref('heads/master')
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
<div class="prose" markdown="1">
|
|
188
|
+
|
|
189
|
+
``` python
|
|
190
|
+
{ 'node_id': 'MDM6UmVmMjI1NDYwNTk5OnJlZnMvaGVhZHMvbWFzdGVy',
|
|
191
|
+
'object': { 'sha': 'c0608379fe60014534c8dffe2e381138e8160f53',
|
|
192
|
+
'type': 'commit',
|
|
193
|
+
'url': 'https://api.github.com/repos/AnswerDotAI/fastcore/git/commits/c0608379fe60014534c8dffe2e381138e8160f53'},
|
|
194
|
+
'ref': 'refs/heads/master',
|
|
195
|
+
'url': 'https://api.github.com/repos/AnswerDotAI/fastcore/git/refs/heads/master'}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
</div>
|
|
199
|
+
|
|
200
|
+
Now that we’ve provided our token, we can use authenticated endpoints such as creating an issue:
|
|
201
|
+
|
|
202
|
+
``` python
|
|
203
|
+
issue = await api.issues.create("Remember to check out GhApi!")
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Since we’ve now checked out GhApi, let’s close this issue. 😎
|
|
207
|
+
|
|
208
|
+
``` python
|
|
209
|
+
await api.issues.update(issue.number, state='closed')
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## How to use - command line
|
|
213
|
+
|
|
214
|
+
You can use [`GhApi`](https://ghapi.fast.ai/core.html#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`](https://ghapi.fast.ai/cli.html#ghapi) – see the full CLI docs page for details on all the programs available.
|
|
215
|
+
|
|
216
|
+
We strongly recommend enabling tab completion for [`ghapi`](https://ghapi.fast.ai/cli.html#ghapi), which you can do by placing the following command at the end of your `~/.bashrc` or `~/.zshrc` file:
|
|
217
|
+
|
|
218
|
+
``` bash
|
|
219
|
+
eval "$(completion-ghapi --install)"
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
To get started with the [`ghapi`](https://ghapi.fast.ai/cli.html#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).
|
|
223
|
+
|
|
224
|
+
To use [`ghapi`](https://ghapi.fast.ai/cli.html#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.
|
|
225
|
+
|
|
226
|
+
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:
|
|
227
|
+
|
|
228
|
+
``` bash
|
|
229
|
+
ghapi git.get_ref fastai ghapi-test --ref heads/master
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
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:
|
|
233
|
+
|
|
234
|
+
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
|
|
235
|
+
|
|
236
|
+
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.
|
|
237
|
+
|
|
238
|
+
``` bash
|
|
239
|
+
ghapi git.get_ref --help
|
|
240
|
+
>>> git.get_ref(owner, repo, ref)
|
|
241
|
+
>>> https://docs.github.com/rest/reference/git#get-a-reference
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
In addition to `--help` and the GitHub operation parameters, you can also pass the following:
|
|
245
|
+
|
|
246
|
+
- `--headers`: A list of extra headers to pass, JSON-encoded
|
|
247
|
+
- `--token`: A GitHub authentation token
|
|
248
|
+
- `--debug`: Print requests before sending them
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.0.1"
|