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 PyGithubVerified import paths — ran on the pinned version, not inferred.
Minimal example: authenticate with a personal access token and list repository info and issues.
Replace Github(login_or_token='TOKEN') with Github(auth=Auth.Token('TOKEN')).Use 'from github import Github' not 'import pygithub'.
Use totalCount before iterating, slice results, or check g.get_rate_limit() to monitor usage.
Use 'with Github(auth=auth) as g:' or explicitly call g.close() when done.
Check g.get_rate_limit().core.remaining and implement retry logic or use retry_after from the RateLimitExceededException.
Use GithubIntegration(auth=Auth.AppAuth(app_id, private_key)) instead of positional arguments.
Ensure that the authentication token passed to Auth.Token() is a valid, non-empty string.
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.
Ensure the library is installed with `pip install PyGithub` and then import the main class correctly using `from github import Github`.
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)`.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.
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()`.