Python wrapper for the GitHub API(http://developer.github.com/v3)
npx @tessl/cli install tessl/pypi-github3--py@4.0.0A comprehensive, actively developed, and extraordinarily stable Python wrapper around the GitHub API (v3). This library provides complete access to GitHub's REST API functionality including repositories, issues, pull requests, organizations, users, gists, and webhooks through an intuitive object-oriented interface.
pip install github3.pyimport github3For authenticated access:
# Using login function
from github3 import login
gh = login('username', token='your_token')
# Or using GitHub class directly
from github3 import GitHub
gh = GitHub(token='your_token')For unauthenticated access:
from github3 import GitHub
gh = GitHub()import github3
# Unauthenticated access for public data
gh = github3.GitHub()
# Get a repository
repo = gh.repository('octocat', 'Hello-World')
print(f"Repository: {repo.full_name}")
print(f"Description: {repo.description}")
print(f"Stars: {repo.stargazers_count}")
# Get a user
user = gh.user('octocat')
print(f"User: {user.login}")
print(f"Name: {user.name}")
# Authenticated access for full functionality
gh = github3.login(token='your_personal_access_token')
# Create a repository
new_repo = gh.create_repository('my-new-repo', description='A test repository')
# Create an issue
issue = gh.create_issue('owner', 'repo', 'Issue title', 'Issue body')
# Star a repository
gh.star('owner', 'repo')The library is organized around these key components:
The object-oriented design allows for intuitive navigation between related entities (e.g., from a repository to its issues to individual comments) while providing both high-level convenience methods and low-level API access.
Core authentication functionality supporting multiple GitHub authentication methods including personal access tokens, OAuth, GitHub Apps, and enterprise instances.
def login(username=None, password=None, token=None, two_factor_callback=None): ...
def enterprise_login(username=None, password=None, token=None, url=None, two_factor_callback=None): ...
class GitHub:
def __init__(self, username="", password="", token="", session=None, api_version=""): ...
def login(self, username=None, password=None, token=None, two_factor_callback=None): ...
def login_as_app(self, private_key_pem, app_id, expire_in=600): ...
def login_as_app_installation(self, private_key_pem, app_id, installation_id, expire_in=30): ...Complete user profile management, social features, and account operations for the authenticated user and public user information retrieval.
def user(self, username): ...
def user_with_id(self, number): ...
def me(self): ...
def update_me(self, name=None, email=None, blog=None, company=None, location=None, hireable=False, bio=None): ...
def follow(self, username): ...
def unfollow(self, username): ...
def is_following(self, username): ...
def followers(self, number=-1, etag=None): ...
def following(self, number=-1, etag=None): ...
def followers_of(self, username, number=-1, etag=None): ...
def followed_by(self, username, number=-1, etag=None): ...Comprehensive repository management including creation, modification, collaboration, and content operations for both authenticated and public repositories.
def repository(self, owner, repository): ...
def repository_with_id(self, number): ...
def repositories(self, type=None, sort=None, direction=None, number=-1, etag=None): ...
def repositories_by(self, username, type=None, sort=None, direction=None, number=-1, etag=None): ...
def all_repositories(self, number=-1, since=None, etag=None, per_page=None): ...
def create_repository(self, name, description="", homepage="", private=False, has_issues=True, has_wiki=True, auto_init=False, gitignore_template="", has_projects=True): ...
def star(self, username, repo): ...
def unstar(self, username, repo): ...
def is_starred(self, username, repo): ...
def starred(self, sort=None, direction=None, number=-1, etag=None): ...
def starred_by(self, username, sort=None, direction=None, number=-1, etag=None): ...Complete issue and pull request lifecycle management including creation, modification, labeling, milestones, and collaboration features.
def issue(self, username, repository, number): ...
def issues(self, filter="", state="", labels="", sort="", direction="", since=None, number=-1, etag=None): ...
def issues_on(self, username, repository, milestone=None, state=None, assignee=None, mentioned=None, labels=None, sort=None, direction=None, since=None, number=-1, etag=None): ...
def user_issues(self, filter="", state="", labels="", sort="", direction="", since=None, per_page=None, number=-1, etag=None): ...
def create_issue(self, owner, repository, title, body=None, assignee=None, milestone=None, labels=[], assignees=None): ...
def pull_request(self, owner, repository, number): ...Organization administration, team management, membership handling, and organization-wide operations for enterprise GitHub usage.
def organization(self, username): ...
def organizations(self, number=-1, etag=None): ...
def organizations_with(self, username, number=-1, etag=None): ...
def all_organizations(self, number=-1, since=None, etag=None, per_page=None): ...
def membership_in(self, organization): ...
def activate_membership(self, organization): ...
def organization_memberships(self, state=None, number=-1, etag=None): ...
def organization_issues(self, name, filter="", state="", labels="", sort="", direction="", since=None, number=-1, etag=None): ...Note: Organization management capabilities are included in the User Management and Repository Operations documentation.
Complete gist management including creation, modification, commenting, and sharing of code snippets and small files.
def gist(self, id_num): ...
def gists(self, number=-1, etag=None): ...
def gists_by(self, username, number=-1, etag=None): ...
def public_gists(self, number=-1, etag=None, since=None): ...
def create_gist(self, description, files, public=True): ...Note: Gist operations follow similar patterns to repository operations documented above.
Powerful search capabilities across repositories, code, issues, users, and commits with advanced query syntax and filtering options.
def search_repositories(self, query, sort=None, order=None, per_page=None, text_match=False, number=-1, etag=None): ...
def search_code(self, query, sort=None, order=None, per_page=None, text_match=False, number=-1, etag=None): ...
def search_issues(self, query, sort=None, order=None, per_page=None, text_match=False, number=-1, etag=None): ...
def search_users(self, query, sort=None, order=None, per_page=None, text_match=False, number=-1, etag=None): ...
def search_commits(self, query, sort=None, order=None, per_page=None, text_match=False, number=-1, etag=None): ...Note: Search functionality is accessible through the main GitHub client with comprehensive querying capabilities.
GitHub Apps authentication, installation management, and programmatic access for building integrations and automation tools.
def app(self, app_slug): ...
def authenticated_app(self): ...
def app_installations(self, number=-1): ...
def app_installation(self, installation_id): ...
def app_installation_for_organization(self, organization): ...
def app_installation_for_repository(self, owner, repository): ...
def app_installation_for_user(self, user): ...
def app_installation_repos(self, number=-1, etag=None): ...Note: GitHub Apps authentication is covered in the Authentication documentation above.
Complete SSH and GPG key lifecycle management for secure authentication and commit signing configuration.
def keys(self, number=-1, etag=None): ...
def key(self, id_num): ...
def create_key(self, title, key, read_only=False): ...
def gpg_keys(self, number=-1, etag=None): ...
def gpg_key(self, id_num): ...
def create_gpg_key(self, armored_public_key): ...Note: SSH and GPG key management is covered in the User Management documentation above.
GitHub platform utilities including rate limiting, API metadata, templates, licenses, and various GitHub-specific features.
def rate_limit(self): ...
def meta(self): ...
def emojis(self): ...
def gitignore_templates(self): ...
def gitignore_template(self, language): ...
def licenses(self, number=-1, etag=None): ...
def license(self, name): ...
def markdown(self, text, mode="", context="", raw=False): ...
def octocat(self, say=None): ...
def zen(self): ...
def feeds(self): ...
def pubsubhubbub(self, mode, topic, callback, secret=""): ...Note: Utility functions provide direct access to GitHub's platform features and metadata.
class GitHub:
"""Main GitHub API client for github.com"""
def __init__(self, username="", password="", token="", session=None, api_version=""): ...
class GitHubEnterprise:
"""GitHub API client for Enterprise instances"""
def __init__(self, url, username="", password="", token="", verify=True, session=None): ...
def create_user(self, login, email): ...
def admin_stats(self, option): ...
class GitHubError(Exception):
"""Base exception class for GitHub API errors"""
pass
# Core entity types
class User:
"""GitHub user representation"""
login: str
name: str
email: str
id: int
avatar_url: str
html_url: str
type: str
site_admin: bool
class Repository:
"""GitHub repository representation"""
name: str
full_name: str
description: str
id: int
private: bool
html_url: str
clone_url: str
stargazers_count: int
forks_count: int
language: str
default_branch: str
class Issue:
"""GitHub issue representation"""
number: int
title: str
body: str
state: str
id: int
html_url: str
user: User
assignee: User
labels: list
milestone: object
class PullRequest:
"""GitHub pull request representation"""
number: int
title: str
body: str
state: str
id: int
html_url: str
user: User
base: object
head: object
merged: bool
class Gist:
"""GitHub gist representation"""
id: str
description: str
public: bool
html_url: str
files: dict
user: User
class Organization:
"""GitHub organization representation"""
login: str
name: str
id: int
description: str
html_url: str
avatar_url: str
public_repos: int
# Short object types (used in listings)
class ShortUser:
"""Abbreviated user representation"""
login: str
id: int
avatar_url: str
html_url: str
class ShortRepository:
"""Abbreviated repository representation"""
name: str
full_name: str
id: int
private: bool
html_url: str
class ShortIssue:
"""Abbreviated issue representation"""
number: int
title: str
state: str
id: int
html_url: str
# Utility types
class Email:
"""User email address representation"""
email: str
primary: bool
verified: bool
visibility: str