Registry / http-networking / PyGithub

PyGithub

JSON →
library2.10.0pypypi✓ verified 25d ago

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.

pip install PyGithub
INSTALL
IMPORT
SIG · PYGITHUB
P
PyGithub
http-networkingpythonv2.10.0
Install
4.0s avg
Import
583ms
Disk
45MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.10.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.602s · 46.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.0s · import 0.564s · 47MB
45MB installed
● package 45MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Github, Auth
from github import Github, Auth
import PyGithub
Package installs as PyGithub but imports as github. import PyGithub raises ModuleNotFoundError.

Minimal authenticated GitHub API call using PyGithub 2.x auth pattern.

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()
Debug
Known issues
breakingGithub(login_or_token='token') is the old 1.x pattern. In 2.x use Auth.Token() and pass via auth= argument.
fix
auth = Auth.Token('ghp_...'); g = Github(auth=auth)
affects: < 2.0
breakingCommit.files used to return list[File], now returns PaginatedList[File]. len(commit.files) raises TypeError.
fix
Use commit.files.totalCount or iterate instead of len()
affects: < 2.4
breakingrepo.compare().commits used to return list[Commit], now returns PaginatedList[Commit]. len() raises TypeError.
fix
Use .totalCount property instead of len()
affects: < 2.2
breakingdatetime objects returned by the API are now timezone-aware (UTC). Comparing with naive datetime instances breaks.
fix
Add tzinfo=timezone.utc to any datetime instances used in comparisons
affects: < 2.0
gotchapip install name is PyGithub (capital P, G) but the import is 'from github import Github'. The casing mismatch trips up agents constantly.
fix
pip install PyGithub && from github import Github
affects: all
gotchag.close() must be called after use to close the underlying connection pool. Omitting causes ResourceWarning in tests.
fix
Use as context manager: with Github(auth=auth) as g: ...
affects: all
gotchaPullRequest.create_review_comment argument renamed from position= to line=. Keyword callers break silently.
fix
Replace position=N with line=N
affects: < 1.57
gotchaThis is a community SDK, not an official GitHub product. GitHub has no official Python SDK. Agents often assume otherwise.
fix
For official REST access use requests + Authorization header directly, or use PyGithub.
affects: all
breakingThe provided GitHub token is invalid, expired, or lacks the necessary permissions (e.g., 'public_repo' for public repos, 'repo' for private). This results in a BadCredentialsException.
fix
Ensure the GitHub token is correct, not expired, and has the required scopes for the API calls being made. Check GitHub token settings or regenerate a new token with appropriate permissions.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'github'
The PyGithub package is not installed or is installed in a different Python environment.
fix
Ensure PyGithub is installed in your current environment using: pip install PyGithub
ImportError: cannot import name 'Auth' from 'github'
The 'Auth' module is not available in the installed version of PyGithub.
fix
Use the older authentication method: from github import Github; g = Github('access_token')
ImportError: cannot import name 'GitHub' from 'github'
The class name is case-sensitive; 'GitHub' should be 'Github'.
fix
Correct the import statement to: from github import Github
AttributeError: 'Repository' object has no attribute 'get_contents'
The 'get_contents' method is not available in the 'Repository' class.
fix
Use the 'get_dir_contents' method instead: contents = repo.get_dir_contents('path')
TypeError: 'NoneType' object is not iterable
A method returned None, possibly due to an invalid repository or user.
fix
Ensure the repository or user exists and is accessible: repo = g.get_repo('owner/repo')
Upgrade
Version history
2.10.0latest on PyPI · released Aug 20, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
62 hits · last 30 days
node
52
OpenAI (training)
1
Resources
PyGithub — pip install PyGithub · libregistry