PyGithub Programming Model
Jump to navigation
Jump to search
Internal
Authentication
Various authentication mechanism are invoked by appropriately configuring the main Github
class.
Authentication with Personal Access Token (PAT)
github_pat = os.environ.get('GITHUB_PAT')
if not github_pat:
raise ValueError("'GITHUB_PAT' not found in environment")
github = Github(base_url='https://github.com/api/v3', login_or_token=github_pat)
Authentication with Username and Password
github = Github(base_url='https://github.com/api/v3', login_or_token='someusername', password='somepassword')
Note that the invocation does not fail if the username or the password is invalid. Subsequent calls are made as unauthenticated user.
Authentication with JWT
Configuring Retry
status_forcelist = [403, 500, 502, 504] # retry 403s, 5XX from GitHub
retry = Retry(total=10, backoff_factor=0.2, raise_on_status=True, status_forcelist=status_forcelist)
github = Github(base_url='...', retry=retry, ...)