simple-github
A simple Python Github client that handles auth and provides easy access to the REST and GraphQL APIs.
Why use simple-github?
You might consider simple-github if..
- You don't want to write your own auth (especially app auth) but also don't want to be stuck with an object oriented wrapper.
- You want to use both the REST and GraphQL endpoints.
Features
- Authenticate with a personal access token, as a Github App or a Github App installation.
- Automatic refreshing of app tokens on expiry.
- Query both the REST and GraphQL endpoints.
- Shared
aiohttpsession across both endpoints.
Installation
Install with pip:
pip install simple-github
Example Usage
Authenticate with an access token
In the simplest case, you can provide an access token to use:
from simple_github import TokenClient
token = "<access token>"
async with TokenClient(token) as session:
resp = await session.get("/octocat")
resp.raise_for_status()
data = await resp.json()
await resp.close()
The return value is an aiohttp.ClientResponse object.
If calling synchronously, simply remove the async / await from the
examples:
from simple_github import TokenClient
token = "<access token>"
with TokenClient(token) as session:
resp = session.get("/octocat")
resp.raise_for_status()
data = resp.json()
In this case the return value is a requests.Response object.
Authenticate as a Github App installation
To authenticate as an app installation you'll need:
- The Github app id for your app.
- A private key associated with your app. This can be generated from your app's settings page.
- The organization or user where the app is installed.
- Optionally a list of repositories to limit access to.
from simple_github import AppClient
app_id = 123
privkey = "<private key>"
owner = "mozilla-releng"
async with AppClient(app_id, privkey, owner=owner) as session:
resp = await session.get("/octocat")
You can also specify repositories if you want to restrict access.
async with AppClient(app_id, privkey, owner=owner, repositories=["simple-github"]) as session:
resp = await session.get("/octocat")
The AppClient can be used in both sync and async contexts. If a running async
loop is found, an object with awaitable method will be returned, otherwise a
normal synchronous object with the same methods will be provided.
Authenticate as a Github App
You can also authenticate as the app itself. This is mainly only useful for
administering the app. To do this, simply omit the owner argument.
async with AppClient(app_id, privkey) as session:
resp = await session.get("/octocat")
Obtain an app token for use with git
Under the hood, the AppClient uses the AppAuth and AppInstallationAuth
objects to obtain a GitHub token. It can also be used to pull or push from a
repository.
The token can be obtained as follows for a given installation of the app.
app_auth = AppAuth(app_id, privkey)
inst_auth = AppInstallationAuth(app_auth, owner, repositories=["simple-github"])
return await inst_auth.get_token()
The get_token method doesn't natively support synchronous calls, but it can
easily be called from synchronous code with
return asyncio.run(inst_auth.get_token())
For convenience, the AppClient provides a get_token() methods hiding those details.
token = await AppClient(app_id, privkey, owner=owner, repositories=["simple-github"]).get_token()
The returned token (ghs_XXX) can be used directly to authenticate git+http
operations as the git user.
git remote set-url origin https://git:ghs_XXX@github.com/mozilla-releng/simple-github
No Authentication
Finally you can create a client without any authentication. This is mainly provided for cases where supplying an authentication method is optional, e.g to increase rate limits. This allows for simpler implementations.
from simple_github import PublicClient
async with PublicClient() as session:
resp = await session.get("/octocat")
Query the REST API
simple-github provides only a very basic wrapper around Github's REST API. You can
query it by passing in the path fragment to session.get or session.post.
For example, you can list pull requests with a GET request:
resp = await session.get("/repos/mozilla-releng/simple-github/pulls")
pulls = await resp.json()
await resp.close()
open_pulls = [p for p in pulls if p["state"] == "open"]
Or you can create a pull request with a POST request:
data = {
"title": "Add feature X",
"body": "This adds new feature X",
"head": "simple-github:featureX",
"base": "main",
}
await session.post("/repos/mozilla-releng/simple-github/pulls", data=data)
Query the GraphQL API
simple-github also supports the GraphQL API. In this example we get the contents of a file:
query = """
query getFileContents {
repository(owner: "mozilla-releng", name: "simple-github") {
object(expression: "HEAD:README.md") {
... on Blob {
text
}
}
}
}
"""
contents = await session.execute(query)
You can use GraphQL variables via the variables argument to session.execute.
Metadata
Release files for simple-github 3.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| simple_github-3.2.2.tar.gz | 187.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| simple_github-3.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 201.7 kB
Release files / simple_github-3.2.2.tar.gz
| Download URL | simple_github-3.2.2.tar.gz |
|---|---|
| Size | 187.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dd7124484a26fcaddb3efa416ac6efb203f55f0e76c6d0bbfb80ad07f45e7472
|
|
BLAKE2b-256 checksum How to use checksums |
18426648c4c44b3021ea575edb381c57e25370c664f662b8f7dfaa2ba828f137
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency logRelease files / simple_github-3.2.2-py3-none-any.whl
| Download URL | simple_github-3.2.2-py3-none-any.whl |
|---|---|
| Size | 14.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d00930bddcbdfdf01b57472fc9647b6c32fdd4496f5220296351d0ef16fba5d5
|
|
BLAKE2b-256 checksum How to use checksums |
0210e80278ac4fc991701552d1bf87facef89e46ce6595866390ed9c00e55604
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency log