github3.py: GitHub API Wrapper

4.0.1 · active · verified Thu Apr 09

github3.py is a comprehensive Python wrapper for the GitHub API (v3), designed with a logical organization of methods to interact with the API. It is currently at version 4.0.1, requires Python 3.7+, and maintains an active, though irregular, release cadence with frequent updates and bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with github3.py using a Personal Access Token (PAT), which is the recommended approach to avoid rate limits and issues with Two-Factor Authentication. It then fetches and prints the authenticated user's repositories.

import os
from github3 import login

# It's highly recommended to use a Personal Access Token (PAT) for authentication,
# especially when 2FA is enabled, to avoid repeated prompts.
# Store your token in an environment variable, e.g., GITHUB_TOKEN.
TOKEN = os.environ.get('GITHUB_TOKEN', 'YOUR_GITHUB_TOKEN') # Replace with actual token or ensure env var is set

if TOKEN and TOKEN != 'YOUR_GITHUB_TOKEN':
    gh = login(token=TOKEN)
    if gh:
        print(f"Successfully authenticated as: {gh.me().login}")
        # Example: Get your repositories
        print("Your repositories:")
        for repo in gh.iter_repos(type='owner'):
            print(f"- {repo.name}")
    else:
        print("Authentication failed. Check your GITHUB_TOKEN.")
else:
    print("GITHUB_TOKEN environment variable not set or is placeholder. Please set it for proper authentication.")
    print("You can generate a PAT at: https://github.com/settings/tokens")

view raw JSON →