Registry / http-networking / pygithub

pygithub

JSON →
library2.10.0pypypi✓ verified 26d ago

Python library to access the GitHub REST API v3. Provides typed Python objects for repositories, issues, pull requests, users, organizations, and more. Built on top of requests. Current version is 2.6.0 (2025). Supports Python 3.8+.

pip install PyGithub
INSTALL
IMPORT
SIG · PYGITHUB
P
pygithub
http-networkingpythonv2.10.0
Install
4.1s avg
Import
601ms
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.622s · 46.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.1s · import 0.580s · 47MB
45MB installed
● package 45MB
Code
Verified usage

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

Github
from github import Github
import pygithub
The package name on PyPI is PyGithub but the import module is 'github', not 'pygithub'.
Auth
from github import Auth
Github(login_or_token='my_token')
Since v2.0 the login_or_token parameter is removed. Use Auth.Token() objects instead.
GithubIntegration
from github import GithubIntegration
Used for GitHub App authentication. Requires the [integrations] extra.

Minimal example: authenticate with a personal access token and list repository info and issues.

import os from github import Github, Auth token = os.environ.get('GITHUB_TOKEN', '') auth = Auth.Token(token) g = Github(auth=auth) repo = g.get_repo('PyGithub/PyGithub') print(f'Repo: {repo.full_name}') print(f'Stars: {repo.stargazers_count}') # List open issues for issue in repo.get_issues(state='open')[:5]: print(f' #{issue.number}: {issue.title}') g.close()
Debug
Known issues
breakingIn v2.0, the login_or_token, password, and jwt parameters on Github() were removed. Authentication must use Auth objects.
fix
Replace Github(login_or_token='TOKEN') with Github(auth=Auth.Token('TOKEN')).
affects: >= 2.0.0
breakingThe import module name is 'github', not 'pygithub'. Using 'import pygithub' raises ModuleNotFoundError.
fix
Use 'from github import Github' not 'import pygithub'.
affects: all
gotchaPaginatedList objects are lazily loaded. Iterating over get_issues(), get_pulls(), etc. makes one API call per page (default 30 items). Large repos can exhaust rate limits quickly.
fix
Use totalCount before iterating, slice results, or check g.get_rate_limit() to monitor usage.
affects: all
gotchaGithub objects hold a requests Session. Failing to call g.close() or use a context manager leaks connections.
fix
Use 'with Github(auth=auth) as g:' or explicitly call g.close() when done.
affects: all
gotchaGitHub API rate limit is 5000 requests/hour for authenticated users, 60/hour for unauthenticated. PyGithub does not auto-retry on 403 rate limit errors.
fix
Check g.get_rate_limit().core.remaining and implement retry logic or use retry_after from the RateLimitExceededException.
affects: all
deprecatedGithubIntegration constructor parameters changed in v2.0. The old positional (integration_id, private_key) signature is removed.
fix
Use GithubIntegration(auth=Auth.AppAuth(app_id, private_key)) instead of positional arguments.
affects: >= 2.0.0
breakingThe token provided to Auth.Token() must be a non-empty string. An AssertionError: assert len(token) > 0 indicates an empty or invalid token was passed during authentication.
fix
Ensure that the authentication token passed to Auth.Token() is a valid, non-empty string.
affects: all
breakingAuth.Token() raises AssertionError if the token provided is an empty string. A valid, non-empty GitHub Personal Access Token is required.
fix
Ensure the token passed to Auth.Token() is a non-empty string. Verify the environment variable or configuration storing the token is correctly set and not empty.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'github'
The Python package is installed as `PyGithub` but developers often attempt to import it using `import github` or `from github import Github`, which refers to a module name that doesn't exist directly.
fix
Ensure the library is installed with `pip install PyGithub` and then import the main class correctly using `from github import Github`.
github.GithubException.GithubException: 401 {"message": "Bad credentials"}
This error occurs when the provided GitHub Personal Access Token (PAT) is invalid, expired, lacks the necessary permissions (scopes), or when an incorrect base URL is used for GitHub Enterprise.
fix
Verify that your PAT is correct, active, and has the required scopes. For GitHub Enterprise, ensure the `base_url` parameter is set correctly when initializing the `Github` object, typically to `https://{hostname}/api/v3`. For PATs, initialize with `from github import Auth; auth = Auth.Token('YOUR_PAT'); g = Github(auth=auth)`.
AttributeError: 'Issue' object has no attribute 'get_issue_comments'
This `AttributeError` typically arises when attempting to call a method or access an attribute that does not exist on a specific PyGithub object. Developers might guess method names (e.g., `get_issue_comments`) instead of consulting the actual API or using introspection.
fix
Consult the PyGithub documentation for the correct method names (e.g., `issue.get_comments()` instead of `issue.get_issue_comments()`). You can also use `dir(obj)` or `help(obj)` in a Python console to inspect available attributes and methods for an object.
ValueError: Invalid header value b'token <properly_formed_token>\n'
This error often happens when a Personal Access Token (PAT) is read from a file or an environment variable and includes extraneous whitespace characters, such as a newline character (`\n`), which makes the HTTP header invalid.
fix
Ensure that the token string has no leading or trailing whitespace by using the `.strip()` method: `token = token_file.read().strip()` or `token = os.environ.get('GITHUB_TOKEN').strip()`.
Upgrade
Version history
2.10.0latest on PyPI · released Aug 20, 2026
Audit
Dependencies
PyGithub[integrations]optionalRequired for GitHub App authentication via PyJWT and cryptography.
Agent activity
42 hits · last 30 days
node
38
OpenAI (training)
1
Resources
pygithub — pip install pygithub · libregistry