GitHub API (PyGithub)
Community-maintained Python library for GitHub REST API v3. Current version is 2.8.1 (Feb 2026). Note: package name on PyPI is 'PyGithub' (capital P and G) but imports as 'github' (lowercase). Not an official GitHub SDK.
Warnings
- breaking Github(login_or_token='token') is the old 1.x pattern. In 2.x use Auth.Token() and pass via auth= argument.
- breaking Commit.files used to return list[File], now returns PaginatedList[File]. len(commit.files) raises TypeError.
- breaking repo.compare().commits used to return list[Commit], now returns PaginatedList[Commit]. len() raises TypeError.
- breaking datetime objects returned by the API are now timezone-aware (UTC). Comparing with naive datetime instances breaks.
- gotcha pip install name is PyGithub (capital P, G) but the import is 'from github import Github'. The casing mismatch trips up agents constantly.
- gotcha g.close() must be called after use to close the underlying connection pool. Omitting causes ResourceWarning in tests.
- gotcha PullRequest.create_review_comment argument renamed from position= to line=. Keyword callers break silently.
- gotcha This is a community SDK, not an official GitHub product. GitHub has no official Python SDK. Agents often assume otherwise.
Install
-
pip install PyGithub
Imports
- Github, Auth
from github import Github, Auth
Quickstart
from github import Github, Auth
auth = Auth.Token("your_token")
g = Github(auth=auth)
repo = g.get_repo("owner/repo")
for issue in repo.get_issues(state='open'):
print(issue.title)
g.close()