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
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)
Call GraphQL API
Simple sync call:
data: Dict[str, Any] = github.graphql(query, variables={"foo": "bar"})
Simple async call:
data: Dict[str, Any] = github.async_graphql(query, variables={"foo": "bar"})
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.3.0.tar.gz
(216.8 kB
view details)
Built Distribution
GitHubKit-0.3.0-py3-none-any.whl
(242.0 kB
view details)
File details
Details for the file GitHubKit-0.3.0.tar.gz
.
File metadata
- Download URL: GitHubKit-0.3.0.tar.gz
- Upload date:
- Size: 216.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.4 Linux/5.4.0-1074-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e188aa1a1fd3e609d6a734cf7459ed3b0cdc1e1c08fd5bdc1afe7366e862debf |
|
MD5 | b8e333dc9f943a535746c50ce1056a64 |
|
BLAKE2b-256 | 2545ae2e7f8ecc4b328fce4a26dfc3ebc245b5b8c52f736b63ff1c80a68288c2 |
File details
Details for the file GitHubKit-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: GitHubKit-0.3.0-py3-none-any.whl
- Upload date:
- Size: 242.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.4 Linux/5.4.0-1074-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14d8fa4bbf3958bb874094384a36aa85e2797a5a6734ece65c8d338798381c85 |
|
MD5 | 1472299b3adcb44dfb82ab58a2516da7 |
|
BLAKE2b-256 | 54d9aa10376359437176da641cdc2359db9d854d5f4a7d9457f78ab49b3703ef |