Comprehensive Python client library providing full access to the GitHub REST API v3 for programmatic management of repositories, users, organizations, issues, pull requests, and other GitHub entities
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
User profile access, organization management, membership operations, and social features. Handles both public user information and authenticated user capabilities.
Access user profiles, repositories, and public information.
class Github:
def get_user(self, login: str = None) -> Union[AuthenticatedUser, NamedUser]:
"""
Get a user by login or the authenticated user.
Args:
login (str, optional): Username (if None, returns authenticated user)
Returns:
Union[AuthenticatedUser, NamedUser]: User object
"""
class NamedUser:
# User properties
@property
def login(self) -> str: ...
@property
def name(self) -> str: ...
@property
def email(self) -> str: ...
@property
def bio(self) -> str: ...
@property
def company(self) -> str: ...
@property
def location(self) -> str: ...
@property
def blog(self) -> str: ...
@property
def avatar_url(self) -> str: ...
@property
def public_repos(self) -> int: ...
@property
def public_gists(self) -> int: ...
@property
def followers(self) -> int: ...
@property
def following(self) -> int: ...
@property
def created_at(self) -> datetime: ...
@property
def updated_at(self) -> datetime: ...
@property
def type(self) -> str: ... # "User" or "Bot"
def get_repos(
self,
type: str = None,
sort: str = None,
direction: str = None
):
"""
Get user's repositories.
Args:
type (str, optional): Repository type ("all", "owner", "member")
sort (str, optional): Sort by ("created", "updated", "pushed", "full_name")
direction (str, optional): Sort direction ("asc", "desc")
Returns:
PaginatedList[Repository]: List of repositories
"""
def get_gists(self, since: datetime = None):
"""
Get user's gists.
Args:
since (datetime, optional): Only gists updated after this date
Returns:
PaginatedList[Gist]: List of gists
"""
def get_followers(self):
"""
Get user's followers.
Returns:
PaginatedList[NamedUser]: List of followers
"""
def get_following(self):
"""
Get users this user is following.
Returns:
PaginatedList[NamedUser]: List of followed users
"""
def get_starred(self, sort: str = None, direction: str = None):
"""
Get repositories starred by the user.
Args:
sort (str, optional): Sort by ("created", "updated")
direction (str, optional): Sort direction ("asc", "desc")
Returns:
PaginatedList[Repository]: List of starred repositories
"""
def get_subscriptions(self):
"""
Get repositories watched by the user.
Returns:
PaginatedList[Repository]: List of watched repositories
"""
def get_orgs(self):
"""
Get organizations the user belongs to.
Returns:
PaginatedList[Organization]: List of organizations
"""
def get_events(self):
"""
Get user's public events.
Returns:
PaginatedList[Event]: List of events
"""
def get_received_events(self):
"""
Get events received by the user.
Returns:
PaginatedList[Event]: List of received events
"""Extended functionality available to the authenticated user for account management and content creation.
class AuthenticatedUser(NamedUser):
@property
def total_private_repos(self) -> int: ...
@property
def owned_private_repos(self) -> int: ...
@property
def private_gists(self) -> int: ...
@property
def disk_usage(self) -> int: ...
@property
def collaborators(self) -> int: ...
@property
def plan(self) -> Plan: ...
def edit(
self,
name: str = None,
email: str = None,
blog: str = None,
company: str = None,
location: str = None,
hireable: bool = None,
bio: str = None
):
"""
Edit authenticated user's profile.
Args:
name (str, optional): Full name
email (str, optional): Email address
blog (str, optional): Blog URL
company (str, optional): Company name
location (str, optional): Location
hireable (bool, optional): Available for hire
bio (str, optional): Biography
"""
def create_repo(
self,
name: str,
description: str = None,
homepage: str = None,
private: bool = False,
has_issues: bool = True,
has_wiki: bool = True,
has_downloads: bool = True,
auto_init: bool = False,
gitignore_template: str = None,
license_template: str = None,
allow_squash_merge: bool = True,
allow_merge_commit: bool = True,
allow_rebase_merge: bool = True
):
"""
Create a new repository for the authenticated user.
Args:
name (str): Repository name
description (str, optional): Repository description
homepage (str, optional): Homepage URL
private (bool, optional): Create private repository
has_issues (bool, optional): Enable issues
has_wiki (bool, optional): Enable wiki
has_downloads (bool, optional): Enable downloads
auto_init (bool, optional): Initialize with README
gitignore_template (str, optional): .gitignore template name
license_template (str, optional): License template name
allow_squash_merge (bool, optional): Allow squash merging
allow_merge_commit (bool, optional): Allow merge commits
allow_rebase_merge (bool, optional): Allow rebase merging
Returns:
Repository: Created repository
"""
def create_gist(
self,
description: str,
files: dict,
public: bool = True
):
"""
Create a new gist.
Args:
description (str): Gist description
files (dict): Dictionary mapping filenames to InputFileContent objects
public (bool, optional): Create public gist
Returns:
Gist: Created gist
"""
def get_notifications(
self,
all: bool = False,
participating: bool = False,
since: datetime = None,
before: datetime = None
):
"""
Get notifications for the authenticated user.
Args:
all (bool, optional): Include read notifications
participating (bool, optional): Only participating notifications
since (datetime, optional): Only notifications updated after this date
before (datetime, optional): Only notifications updated before this date
Returns:
PaginatedList[Notification]: List of notifications
"""
def get_issues(
self,
filter: str = None,
state: str = None,
labels: list = None,
sort: str = None,
direction: str = None,
since: datetime = None
):
"""
Get issues assigned to the authenticated user across all repositories.
Args:
filter (str, optional): Filter by ("assigned", "created", "mentioned", "subscribed")
state (str, optional): Issue state ("open", "closed", "all")
labels (list, optional): List of label names
sort (str, optional): Sort by ("created", "updated", "comments")
direction (str, optional): Sort direction ("asc", "desc")
since (datetime, optional): Only issues updated after this date
Returns:
PaginatedList[Issue]: List of issues
"""
def create_key(self, title: str, key: str):
"""
Add an SSH key to the authenticated user's account.
Args:
title (str): Key title
key (str): SSH public key content
Returns:
UserKey: Created SSH key
"""
def get_keys(self):
"""
Get SSH keys for the authenticated user.
Returns:
PaginatedList[UserKey]: List of SSH keys
"""
def mark_notifications_as_read(self, last_read_at: datetime = None):
"""
Mark notifications as read.
Args:
last_read_at (datetime, optional): Mark notifications read up to this time
"""Access and manage GitHub organizations, membership, and team operations.
class Github:
def get_organization(self, login: str) -> Organization:
"""
Get an organization by login.
Args:
login (str): Organization login
Returns:
Organization: Organization object
"""
class Organization:
# Organization properties
@property
def login(self) -> str: ...
@property
def name(self) -> str: ...
@property
def email(self) -> str: ...
@property
def blog(self) -> str: ...
@property
def location(self) -> str: ...
@property
def description(self) -> str: ...
@property
def avatar_url(self) -> str: ...
@property
def public_repos(self) -> int: ...
@property
def public_gists(self) -> int: ...
@property
def followers(self) -> int: ...
@property
def following(self) -> int: ...
@property
def created_at(self) -> datetime: ...
@property
def updated_at(self) -> datetime: ...
@property
def type(self) -> str: ... # "Organization"
def edit(
self,
billing_email: str = None,
blog: str = None,
company: str = None,
description: str = None,
email: str = None,
location: str = None,
name: str = None
):
"""
Edit organization profile.
Args:
billing_email (str, optional): Billing email
blog (str, optional): Blog URL
company (str, optional): Company name
description (str, optional): Organization description
email (str, optional): Public email
location (str, optional): Location
name (str, optional): Organization name
"""
def get_repos(
self,
type: str = None,
sort: str = None,
direction: str = None
):
"""
Get organization repositories.
Args:
type (str, optional): Repository type ("all", "public", "private", "forks", "sources", "member")
sort (str, optional): Sort by ("created", "updated", "pushed", "full_name")
direction (str, optional): Sort direction ("asc", "desc")
Returns:
PaginatedList[Repository]: List of repositories
"""
def create_repo(
self,
name: str,
description: str = None,
homepage: str = None,
private: bool = False,
has_issues: bool = True,
has_wiki: bool = True,
has_downloads: bool = True,
team_id: int = None,
auto_init: bool = False,
gitignore_template: str = None,
license_template: str = None
):
"""
Create a repository in the organization.
Args:
name (str): Repository name
description (str, optional): Repository description
homepage (str, optional): Homepage URL
private (bool, optional): Create private repository
has_issues (bool, optional): Enable issues
has_wiki (bool, optional): Enable wiki
has_downloads (bool, optional): Enable downloads
team_id (int, optional): Team with admin access
auto_init (bool, optional): Initialize with README
gitignore_template (str, optional): .gitignore template
license_template (str, optional): License template
Returns:
Repository: Created repository
"""
def get_members(self, filter: str = None, role: str = None):
"""
Get organization members.
Args:
filter (str, optional): Filter by ("2fa_disabled", "all")
role (str, optional): Filter by role ("all", "admin", "member")
Returns:
PaginatedList[NamedUser]: List of members
"""
def get_public_members(self):
"""
Get public organization members.
Returns:
PaginatedList[NamedUser]: List of public members
"""
def has_in_members(self, member: NamedUser):
"""
Check if user is a member of the organization.
Args:
member (NamedUser): User to check
Returns:
bool: True if user is a member
"""
def has_in_public_members(self, member: NamedUser):
"""
Check if user is a public member of the organization.
Args:
member (NamedUser): User to check
Returns:
bool: True if user is a public member
"""
def add_to_public_members(self, member: NamedUser):
"""
Make organization membership public for a user.
Args:
member (NamedUser): User to make public member
"""
def remove_from_public_members(self, member: NamedUser):
"""
Remove user from public members (makes membership private).
Args:
member (NamedUser): User to remove from public members
"""
def remove_from_members(self, member: NamedUser):
"""
Remove user from organization.
Args:
member (NamedUser): User to remove
"""
def get_events(self):
"""
Get organization public events.
Returns:
PaginatedList[Event]: List of events
"""Manage organization teams, team membership, and team repository access.
class Organization:
def get_teams(self):
"""
Get organization teams.
Returns:
PaginatedList[Team]: List of teams
"""
def get_team(self, id: int):
"""
Get a team by ID.
Args:
id (int): Team ID
Returns:
Team: Team object
"""
def create_team(
self,
name: str,
repo_names: list = None,
permission: str = None,
privacy: str = None,
description: str = None,
parent_team_id: int = None
):
"""
Create a team in the organization.
Args:
name (str): Team name
repo_names (list, optional): Repository names to add to team
permission (str, optional): Permission level ("pull", "push", "admin")
privacy (str, optional): Team privacy ("secret", "closed")
description (str, optional): Team description
parent_team_id (int, optional): Parent team ID for nested teams
Returns:
Team: Created team
"""
class Team:
@property
def id(self) -> int: ...
@property
def name(self) -> str: ...
@property
def slug(self) -> str: ...
@property
def description(self) -> str: ...
@property
def privacy(self) -> str: ...
@property
def permission(self) -> str: ...
@property
def members_count(self) -> int: ...
@property
def repos_count(self) -> int: ...
def edit(
self,
name: str = None,
description: str = None,
privacy: str = None,
permission: str = None,
parent_team_id: int = None
):
"""
Edit team settings.
Args:
name (str, optional): Team name
description (str, optional): Team description
privacy (str, optional): Team privacy
permission (str, optional): Permission level
parent_team_id (int, optional): Parent team ID
"""
def delete(self):
"""Delete the team."""
def get_members(self, role: str = None):
"""
Get team members.
Args:
role (str, optional): Filter by role ("member", "maintainer", "all")
Returns:
PaginatedList[NamedUser]: List of members
"""
def has_in_members(self, member: NamedUser):
"""
Check if user is a team member.
Args:
member (NamedUser): User to check
Returns:
bool: True if user is a member
"""
def add_membership(self, member: NamedUser, role: str = None):
"""
Add user to team.
Args:
member (NamedUser): User to add
role (str, optional): Role ("member", "maintainer")
"""
def remove_membership(self, member: NamedUser):
"""
Remove user from team.
Args:
member (NamedUser): User to remove
"""
def get_repos(self):
"""
Get team repositories.
Returns:
PaginatedList[Repository]: List of repositories
"""
def add_to_repos(self, repo: Repository, permission: str = None):
"""
Add repository to team.
Args:
repo (Repository): Repository to add
permission (str, optional): Permission level
"""
def remove_from_repos(self, repo: Repository):
"""
Remove repository from team.
Args:
repo (Repository): Repository to remove
"""from github import Github, Auth
g = Github(auth=Auth.Token("your_token"))
# Get authenticated user
user = g.get_user()
print(f"Authenticated as: {user.login}")
print(f"Name: {user.name}")
print(f"Email: {user.email}")
print(f"Public repos: {user.public_repos}")
# Get another user
other_user = g.get_user("octocat")
print(f"User: {other_user.name}")
print(f"Bio: {other_user.bio}")
print(f"Location: {other_user.location}")
# Get user's repositories
for repo in other_user.get_repos():
print(f"Repository: {repo.full_name}")# Get organization
org = g.get_organization("myorg")
print(f"Organization: {org.name}")
print(f"Description: {org.description}")
print(f"Public repos: {org.public_repos}")
# List organization members
for member in org.get_members():
print(f"Member: {member.login}")
# Create repository in organization
repo = org.create_repo(
name="new-project",
description="A new project repository",
private=True,
has_issues=True
)
print(f"Created repo: {repo.full_name}")# Get organization teams
for team in org.get_teams():
print(f"Team: {team.name} ({team.members_count} members)")
# Create a new team
team = org.create_team(
name="Development Team",
description="Main development team",
privacy="closed",
permission="push"
)
# Add members to team
user_to_add = g.get_user("developer")
team.add_membership(user_to_add, role="member")
# Add repository to team
team.add_to_repos(repo, permission="push")Install with Tessl CLI
npx tessl i tessl/pypi-pygithub