GitHub SDK for Python
Project description
✨ The modern, all-batteries-included GitHub SDK for Python ✨
✨ Support both sync and async calls, fully typed ✨
✨ Always up to date, like octokit ✨
Installation
pip install githubkit
# or, use poetry
poetry add githubkit
# or, use pdm
pdm add githubkit
Usage
Initialization
Initialize a github client using PAT (Token):
from githubkit import GitHub, TokenAuthStrategy
github = GitHub("<your_token_here>")
# or, use TokenAuthStrategy
github = GitHub(TokenAuthStrategy("<your_token_here>"))
or using basic authentication:
from githubkit import GitHub, BasicAuthStrategy
github = GitHub(BasicAuthStrategy("<client_id_here>", "<client_secret_here>"))
Call Rest API
APIs are fully typed. Typing in the following examples is just for reference only.
Simple sync call:
from githubkit import Response
from githubkit.rest import FullRepository
resp: Response[FullRepository] = github.rest.repos.get(owner="owner", repo="repo")
repo: FullRepository = resp.parsed_data
Simple async call:
from githubkit import Response
from githubkit.rest import FullRepository
resp: Response[FullRepository] = await github.rest.repos.async_get(owner="owner", repo="repo")
repo: FullRepository = resp.parsed_data
Call API with context (reusing client):
from githubkit import Response
from githubkit.rest import FullRepository
# with GitHub("<your_token_here>") as github:
with github:
resp: Response[FullRepository] = github.rest.repos.get(owner="owner", repo="repo")
repo: FullRepository = resp.parsed_data
from githubkit import Response
from githubkit.rest import FullRepository
# async with GitHub("<your_token_here>") as github:
async with github:
resp: Response[FullRepository] = await github.rest.repos.async_get(owner="owner", repo="repo")
repo: FullRepository = resp.parsed_data
Warning
Making sync calls in async context or making async calls in sync context will raise an error.
Pagination
from githubkit.rest import Issue
for issue in github.paginate(
github.rest.issues.list_for_repo, owner="owner", repo="repo", state="open"
):
issue: Issue
print(issue.number)
from githubkit.rest import Issue
async for issue in github.paginate(
github.rest.issues.async_list_for_repo, owner="owner", repo="repo", state="open"
):
issue: Issue
print(issue.number)
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
GitHubKit-0.1.0.tar.gz
(161.3 kB
view hashes)
Built Distribution
GitHubKit-0.1.0-py3-none-any.whl
(183.2 kB
view hashes)
Close
Hashes for GitHubKit-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a632610b6f28dd358dec67e7e3a7a90174da9b4543a7d35c40dcdd488f44e08 |
|
MD5 | dd05a24e75167e7c12d534847ada26ad |
|
BLAKE2b-256 | 8b20537bbb39d6c565468d56ba2cfb99192b72a2cef7cea37dd909e1c0fbacab |