PyGithub
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+.
Warnings
- breaking In v2.0, the login_or_token, password, and jwt parameters on Github() were removed. Authentication must use Auth objects.
- breaking The import module name is 'github', not 'pygithub'. Using 'import pygithub' raises ModuleNotFoundError.
- gotcha PaginatedList 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.
- gotcha Github objects hold a requests Session. Failing to call g.close() or use a context manager leaks connections.
- gotcha GitHub API rate limit is 5000 requests/hour for authenticated users, 60/hour for unauthenticated. PyGithub does not auto-retry on 403 rate limit errors.
- deprecated GithubIntegration constructor parameters changed in v2.0. The old positional (integration_id, private_key) signature is removed.
Install
-
pip install PyGithub
Imports
- Github
from github import Github
- Auth
from github import Auth
- GithubIntegration
from github import GithubIntegration
Quickstart
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()