githubpy: Simple GitHub REST API Client

2.0.0 · abandoned · verified Thu Apr 16

githubpy is a straightforward Python3 client designed to interact with the GitHub REST API. Its current version is 2.0.0, released in May 2023. Despite the recent PyPI release, the underlying GitHub repository shows no active development since 2017, indicating it is likely unmaintained.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the GitHub client with a personal access token and retrieves information about the authenticated user and their repositories. Authentication is crucial for most API interactions to avoid severe rate limits.

import os
from githubpy.github import Github

# It's recommended to use an environment variable for your token
github_token = os.environ.get('GITHUB_TOKEN', 'YOUR_GITHUB_TOKEN')

if not github_token or github_token == 'YOUR_GITHUB_TOKEN':
    print("WARNING: GITHUB_TOKEN environment variable not set or placeholder used. This may lead to rate limiting or authentication errors.")

try:
    g = Github(github_token)
    
    # Get authenticated user information
    user_response = g.get('/user')
    user_response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
    user_data = user_response.json()
    print(f"Authenticated as: {user_data.get('login')}")

    # List repositories for the authenticated user
    repos_response = g.get('/user/repos')
    repos_response.raise_for_status()
    repos_data = repos_response.json()
    print("\nUser Repositories:")
    for repo in repos_data[:3]: # Print first 3 repos for brevity
        print(f"- {repo.get('name')}")

except Exception as e:
    print(f"An error occurred: {e}")
    if hasattr(e, 'response') and e.response is not None:
        print(f"Response Status: {e.response.status_code}")
        print(f"Response Body: {e.response.text}")

view raw JSON →