GitHubKit: GitHub SDK for Python
GitHubKit is a comprehensive, type-hinted SDK for interacting with the GitHub REST API and GraphQL API, and for parsing webhooks. It supports the latest GitHub API versions and provides a consistent interface for various GitHub features. The current version is 0.15.3, with frequent releases often driven by updates to GitHub's OpenAPI specification.
Warnings
- breaking In `v0.15.0`, the default GitHub REST API version was updated to `2026-03-10`. This might introduce breaking changes to existing code if your application relied on older API behaviors or response structures for endpoints that changed in the new API version. Review GitHub's API changelog for this version.
- gotcha It is highly recommended to reuse `GitHub` or `AppGitHub` client instances rather than creating a new one for each request. Creating multiple clients can lead to performance issues due to re-establishing connections and not utilizing connection pooling efficiently.
- gotcha When handling GitHub webhooks, failing to verify the `X-Hub-Signature-256` header (or `X-GitHub-Signature`) can lead to security vulnerabilities, allowing attackers to send forged payloads to your endpoint.
- gotcha GitHub API requests are subject to rate limiting. Not handling `githubkit.exception.RateLimitError` or checking `response.headers['x-ratelimit-remaining']` can lead to your application being temporarily blocked.
Install
-
pip install githubkit
Imports
- GitHub
from githubkit import GitHub
- AppGitHub
from githubkit import AppGitHub
- parse_webhook
from githubkit.webhooks import parse_webhook
- GitHubException
from githubkit.exception import GitHubException
Quickstart
import os
from githubkit import GitHub
github_token = os.environ.get('GITHUB_TOKEN', '')
if not github_token:
print("Error: GITHUB_TOKEN environment variable not set.")
else:
github = GitHub(github_token)
try:
# Get information about the authenticated user
user = github.rest.users.get_authenticated_user()
print(f"Hello, {user.data.login} (ID: {user.data.id})!")
# Example: list repositories for the authenticated user
repos = github.rest.repos.list_for_authenticated_user()
print(f"You have {len(repos.data)} repositories.")
except Exception as e:
print(f"An error occurred: {e}")