A python client for the GitHub API
Project description
GhApi
A delightful and complete interface to GitHub's amazing API
GhApi
provides 100% always-updated coverage of the entire GitHub API. Because we automatically convert the OpenAPI spec to a Pythonic API, GhApi
is always up to date with the latest changes to GitHub APIs. Furthermore, because this is all done dynamically, the entire package is only 35kB in size!
Using GhApi
, you can do anything that you can do through the GitHub web interface or through the git
client, such as:
- Open, list, comment on, or modify issues or pull requests
- Create, list, or modify git tags or GitHub releases, including uploading release assets
- Configure and run GitHub Actions and webhooks
- Set up GitHub users and organizations
- Manage your deployments
- ...and much, much more.
Install
Either pip install ghapi
or conda install -c fastai ghapi
.
How to use
Throughout this documentation, you will see code inputs and outputs shown in this format:
1+1
2
We recommend reading the documentation on the official site, 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. 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
object:
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:
api
- actions
- activity
- apps
- billing
- checks
- code_scanning
- codes_of_conduct
- emojis
- enterprise_admin
- gists
- git
- gitignore
- interactions
- issues
- licenses
- markdown
- meta
- migrations
- oauth_authorizations
- orgs
- projects
- pulls
- rate_limit
- reactions
- repos
- scim
- search
- teams
- users
Then we can explore the endpoints provided by the API in each group, e.g. for the git
group:
api.git
- git.create_blob(owner, repo, content, encoding): Create a blob
- git.get_blob(owner, repo, file_sha): Get a blob
- git.create_commit(owner, repo, message, tree, parents, author, committer, signature): Create a commit
- git.get_commit(owner, repo, commit_sha): Get a commit
- git.list_matching_refs(owner, repo, ref, per_page, page): List matching references
- git.get_ref(owner, repo, ref): Get a reference
- git.create_ref(owner, repo, ref, sha, key): Create a reference
- git.update_ref(owner, repo, ref, sha, force): Update a reference
- git.delete_ref(owner, repo, ref): Delete a reference
- git.create_tag(owner, repo, tag, message, object, type, tagger): Create a tag object
- git.get_tag(owner, repo, tag_sha): Get a tag
- git.create_tree(owner, repo, tree, base_tree): Create a tree
- git.get_tree(owner, repo, tree_sha, recursive): Get a tree
Here's how to learn about an endpoint you want to use, e.g.:
api.git.get_ref
git.get_ref(owner, repo, ref): Get a reference
In Jupyter Notebook full tab completion, parameter lists, etc are provided for all endpoints. Endpoints are called as standard Python methods:
api.git.get_ref(owner='fastai', repo='fastcore', ref='heads/master')
- ref: refs/heads/master
- node_id: MDM6UmVmMjI1NDYwNTk5OnJlZnMvaGVhZHMvbWFzdGVy
- url: https://api.github.com/repos/fastai/fastcore/git/refs/heads/master
- object:
- sha: 28721554e0eab1f2974237c502912f8ba42a44a0
- type: commit
- url: https://api.github.com/repos/fastai/fastcore/git/commits/28721554e0eab1f2974237c502912f8ba42a44a0
For access to authenticated endpoints, pass a GitHub token. You can also pass any parameters you want auto-inserted into relevant methods, such as owner
and repo
:
api = GhApi(owner='fastai', repo='fastcore', token=github_token)
We can now repeat the previous method, but only need to pass ref
:
api.git.get_ref('heads/master')
- ref: refs/heads/master
- node_id: MDM6UmVmMjI1NDYwNTk5OnJlZnMvaGVhZHMvbWFzdGVy
- url: https://api.github.com/repos/fastai/fastcore/git/refs/heads/master
- object:
- sha: 28721554e0eab1f2974237c502912f8ba42a44a0
- type: commit
- url: https://api.github.com/repos/fastai/fastcore/git/commits/28721554e0eab1f2974237c502912f8ba42a44a0
Now that we've provided our token, we can use authenticated endpoints such as creating an issue:
issue = api.issues.create("Remember to check out GhApi!")
Since we've now checked out GhApi, let's close this issue. 😎
api.issues.update(issue.number, state='closed')
Tab completion
You can enable tab completion for ghapi
by placing the following command at the end of your ~/.bashrc
or ~/.zshrc
file:
eval "$(completion-ghapi --install)"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ghapi-0.1.3.tar.gz
.
File metadata
- Download URL: ghapi-0.1.3.tar.gz
- Upload date:
- Size: 41.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0.post20200925 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38854d497f042ec5ac2910dc275288a093dbfd3b3f8084ec98366b7605e129da |
|
MD5 | fb0c6ba38d836ce3611fda185a84328a |
|
BLAKE2b-256 | f03e0153f7e6520c6721365d40e6a7b467d0e1dcf23d6692b16cca466ef25eb0 |
File details
Details for the file ghapi-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: ghapi-0.1.3-py3-none-any.whl
- Upload date:
- Size: 37.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0.post20200925 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c869f4b9c3cd0be26d342a605b1899ba0ba3112e283fd7e15b7cc616c5c3b061 |
|
MD5 | e1a6dd743db2a25b35374243306302e7 |
|
BLAKE2b-256 | da49087bceb3921e9d7eff1c07da13226b483b95e3e1d2891dcc767841f46e41 |