Python wrapper for the GitHub API(http://developer.github.com/v3)
—
Complete user profile management, social features, and account operations for the authenticated user and public user information retrieval across GitHub's social and collaboration features.
Access user profiles and account information with comprehensive details and social connections.
def user(self, username):
"""
Retrieve a User object for a specific username.
Parameters:
- username (str, required): GitHub username
Returns:
User object with profile information or None if not found
"""
def user_with_id(self, number):
"""
Get user information using their unique GitHub ID.
Parameters:
- number (int, required): User's unique GitHub ID
Returns:
User object or None if not found
"""
def me(self):
"""
Retrieve information for the authenticated user.
Returns:
AuthenticatedUser object with enhanced permissions and details
"""
def all_users(self, number=-1, etag=None, per_page=None, since=None):
"""
Iterate over every user in the order they signed up.
Parameters:
- number (int): Number to return (-1 for all)
- since (int, optional): ID of last user seen for pagination
- etag (str, optional): ETag from previous request
- per_page (int, optional): Results per page
Returns:
Generator of ShortUser objects
"""# Get specific user
user = gh.user('octocat')
print(f"User: {user.login}")
print(f"Name: {user.name}")
print(f"Company: {user.company}")
print(f"Location: {user.location}")
print(f"Public repos: {user.public_repos}")
print(f"Followers: {user.followers}")
# Get user by ID
user = gh.user_with_id(583231)
# Get authenticated user details
me = gh.me()
print(f"Authenticated as: {me.login}")
print(f"Email: {me.email}")
print(f"Private repos: {me.total_private_repos}")
# Browse all users
for user in gh.all_users(number=100):
print(f"{user.login} (ID: {user.id})")Update and manage the authenticated user's profile information and account settings.
def update_me(self, name=None, email=None, blog=None, company=None, location=None, hireable=False, bio=None):
"""
Update the authenticated user's profile.
Parameters:
- name (str, optional): Display name (not login name)
- email (str, optional): Public email address
- blog (str, optional): Blog/website URL
- company (str, optional): Company name
- location (str, optional): Location string
- hireable (bool): Available for hire status
- bio (str, optional): Biography in GitHub Flavored Markdown
Returns:
bool: True if successful, False otherwise
"""# Update profile information
success = gh.update_me(
name='John Smith',
email='john@example.com',
blog='https://johnsmith.dev',
company='Acme Corp',
location='San Francisco, CA',
hireable=True,
bio='Full-stack developer passionate about open source. Python & JavaScript enthusiast.'
)
if success:
print("Profile updated successfully")Manage social connections through GitHub's following system for community engagement.
def follow(self, username):
"""
Make the authenticated user follow another user.
Parameters:
- username (str, required): User to follow
Returns:
bool: True if successful, False otherwise
"""
def unfollow(self, username):
"""
Make the authenticated user stop following another user.
Parameters:
- username (str, required): User to unfollow
Returns:
bool: True if successful, False otherwise
"""
def is_following(self, username):
"""
Check if the authenticated user is following another user.
Parameters:
- username (str, required): User to check
Returns:
bool: True if following, False otherwise
"""
def followers(self, number=-1, etag=None):
"""
Iterate over followers of the authenticated user.
Parameters:
- number (int): Number to return (-1 for all)
- etag (str, optional): ETag from previous request
Returns:
Generator of ShortUser objects
"""
def following(self, number=-1, etag=None):
"""
Iterate over users the authenticated user is following.
Parameters:
- number (int): Number to return (-1 for all)
- etag (str, optional): ETag from previous request
Returns:
Generator of ShortUser objects
"""
def followers_of(self, username, number=-1, etag=None):
"""
Iterate over followers of a specific user.
Parameters:
- username (str, required): Target user's username
- number (int): Number to return (-1 for all)
- etag (str, optional): ETag from previous request
Returns:
Generator of ShortUser objects
"""
def followed_by(self, username, number=-1, etag=None):
"""
Iterate over users being followed by a specific user.
Parameters:
- username (str, required): Target user's username
- number (int): Number to return (-1 for all)
- etag (str, optional): ETag from previous request
Returns:
Generator of ShortUser objects
"""# Follow a user
success = gh.follow('octocat')
if success:
print("Now following octocat")
# Check following status
if gh.is_following('octocat'):
print("You are following octocat")
# List your followers
print("Your followers:")
for user in gh.followers():
print(f"- {user.login}")
# List who you're following
print("You are following:")
for user in gh.following():
print(f"- {user.login}")
# List another user's followers
print("octocat's followers:")
for user in gh.followers_of('octocat', number=10):
print(f"- {user.login}")
# Unfollow a user
gh.unfollow('octocat')Manage blocked users to control interactions and prevent harassment.
def block(self, username):
"""
Block a specific user.
Parameters:
- username (str, required): User to block
Returns:
bool: True if successful, False otherwise
"""
def unblock(self, username):
"""
Unblock a specific user.
Parameters:
- username (str, required): User to unblock
Returns:
bool: True if successful, False otherwise
"""
def is_blocking(self, username):
"""
Check if the authenticated user is blocking another user.
Parameters:
- username (str, required): User to check
Returns:
bool: True if blocking, False otherwise
"""
def blocked_users(self, number=-1, etag=None):
"""
Iterate over users blocked by the authenticated user.
Parameters:
- number (int): Number to return (-1 for all)
- etag (str, optional): ETag from previous request
Returns:
Generator of ShortUser objects
"""# Block a user
success = gh.block('spammer')
if success:
print("User blocked successfully")
# Check if blocking a user
if gh.is_blocking('spammer'):
print("User is currently blocked")
# List blocked users
for user in gh.blocked_users():
print(f"Blocked: {user.login}")
# Unblock a user
gh.unblock('spammer')Manage email addresses associated with the authenticated user's account.
def emails(self, number=-1, etag=None):
"""
Iterate over email addresses for the authenticated user.
Parameters:
- number (int): Number to return (-1 for all)
- etag (str, optional): ETag from previous request
Returns:
Generator of Email objects
"""
def add_email_addresses(self, addresses=[]):
"""
Add email addresses to the authenticated user's account.
Parameters:
- addresses (list): List of email address strings
Returns:
List of Email objects for added addresses
"""
def delete_email_addresses(self, addresses=[]):
"""
Remove email addresses from the authenticated user's account.
Parameters:
- addresses (list): List of email address strings to remove
Returns:
bool: True if successful, False otherwise
"""# List current email addresses
for email in gh.emails():
print(f"Email: {email.email}")
print(f"Primary: {email.primary}")
print(f"Verified: {email.verified}")
# Add new email addresses
new_emails = gh.add_email_addresses(['john@company.com', 'john.work@example.com'])
for email in new_emails:
print(f"Added: {email.email}")
# Remove email addresses
success = gh.delete_email_addresses(['old@example.com'])
if success:
print("Email addresses removed")Access team memberships across organizations for the authenticated user.
def user_teams(self, number=-1, etag=None):
"""
Get the authenticated user's teams across all organizations.
Parameters:
- number (int): Number to return (-1 for all)
- etag (str, optional): ETag from previous request
Returns:
Generator of ShortTeam objects
"""# List all teams the user belongs to
for team in gh.user_teams():
print(f"Team: {team.name}")
print(f"Organization: {team.organization.login}")
print(f"Permission: {team.permission}")class User:
"""Full user representation with public profile information"""
id: int
login: str
name: str
email: str
bio: str
company: str
location: str
blog: str
avatar_url: str
html_url: str
followers: int
following: int
public_repos: int
public_gists: int
created_at: datetime
updated_at: datetime
# ... additional user properties
class AuthenticatedUser(User):
"""Authenticated user with additional private information"""
private_gists: int
total_private_repos: int
owned_private_repos: int
disk_usage: int
collaborators: int
two_factor_authentication: bool
plan: Plan
# ... additional authenticated user properties and methods
class ShortUser:
"""Abbreviated user representation for list operations"""
id: int
login: str
avatar_url: str
# ... essential user properties
class Email:
"""User email address representation"""
email: str
primary: bool
verified: bool
visibility: str
# ... additional email properties
class Plan:
"""User's GitHub subscription plan"""
name: str
space: int
private_repos: int
collaborators: int
# ... additional plan properties# Find users by location or company
users = gh.search_users('location:seattle company:github')
for result in users:
user = result.user
print(f"{user.login} - {user.company} in {user.location}")# Analyze mutual connections
my_following = set(u.login for u in gh.following())
their_following = set(u.login for u in gh.followed_by('target_user'))
mutual = my_following.intersection(their_following)
print(f"Mutual connections: {len(mutual)}")# Update profile and verify changes
success = gh.update_me(bio='Updated biography')
if success:
updated_me = gh.me()
print(f"New bio: {updated_me.bio}")
# Manage email notifications
emails = list(gh.emails())
primary_email = next(e for e in emails if e.primary)
print(f"Primary email: {primary_email.email}")# Follow contributors to interesting projects
repo = gh.repository('facebook', 'react')
for contributor in repo.contributors()[:10]: # Top 10 contributors
if not gh.is_following(contributor.login):
gh.follow(contributor.login)
print(f"Following {contributor.login}")Install with Tessl CLI
npx tessl i tessl/pypi-github3--py