CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pygithub

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

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

repository-management.mddocs/

Repository Management

Comprehensive repository operations including content management, branch operations, collaboration features, webhooks, and repository settings. Supports both repository-level and Git-level operations.

Capabilities

Repository Access and Information

Get repository objects and access repository metadata, statistics, and properties.

class Github:
    def get_repo(self, full_name_or_id: Union[str, int]) -> Repository:
        """
        Get a repository by full name or ID.
        
        Args:
            full_name_or_id (Union[str, int]): Repository full name (owner/repo) or ID
            
        Returns:
            Repository: Repository object
        """

class Repository:
    # Repository properties
    @property
    def name(self) -> str: ...
    @property
    def full_name(self) -> str: ...
    @property
    def description(self) -> str: ...
    @property
    def language(self) -> str: ...
    @property
    def private(self) -> bool: ...
    @property
    def fork(self) -> bool: ...
    @property
    def forks_count(self) -> int: ...
    @property
    def stargazers_count(self) -> int: ...
    @property
    def watchers_count(self) -> int: ...
    @property
    def size(self) -> int: ...
    @property
    def default_branch(self) -> str: ...
    @property
    def topics(self) -> list: ...

Content Management

Read, create, update, and delete repository files and directories.

class Repository:
    def get_contents(self, path: str, ref: str = None):
        """
        Get contents of a file or directory.
        
        Args:
            path (str): Path to file or directory
            ref (str, optional): Branch, tag, or commit SHA
            
        Returns:
            Union[ContentFile, list[ContentFile]]: File content or directory listing
        """
    
    def get_readme(self):
        """
        Get repository README file.
        
        Returns:
            ContentFile: README file content
        """
    
    def create_file(
        self,
        path: str,
        message: str,
        content: str,
        branch: str = None,
        committer: InputGitAuthor = None,
        author: InputGitAuthor = None
    ):
        """
        Create a new file in the repository.
        
        Args:
            path (str): Path where file should be created
            message (str): Commit message
            content (str): File content
            branch (str, optional): Branch name (defaults to default branch)
            committer (InputGitAuthor, optional): Committer information
            author (InputGitAuthor, optional): Author information
            
        Returns:
            dict: Created file information with commit details
        """
    
    def update_file(
        self,
        path: str,
        message: str,
        content: str,
        sha: str,
        branch: str = None,
        committer: InputGitAuthor = None,
        author: InputGitAuthor = None
    ):
        """
        Update an existing file in the repository.
        
        Args:
            path (str): Path to file to update
            message (str): Commit message
            content (str): New file content
            sha (str): Current file SHA
            branch (str, optional): Branch name
            committer (InputGitAuthor, optional): Committer information
            author (InputGitAuthor, optional): Author information
            
        Returns:
            dict: Updated file information with commit details
        """
    
    def delete_file(
        self,
        path: str,
        message: str,
        sha: str,
        branch: str = None,
        committer: InputGitAuthor = None,
        author: InputGitAuthor = None
    ):
        """
        Delete a file from the repository.
        
        Args:
            path (str): Path to file to delete
            message (str): Commit message
            sha (str): Current file SHA
            branch (str, optional): Branch name
            committer (InputGitAuthor, optional): Committer information
            author (InputGitAuthor, optional): Author information
            
        Returns:
            dict: Deletion commit details
        """

Branch and Reference Management

Manage branches, tags, and Git references.

class Repository:
    def get_branches(self):
        """
        Get all branches in the repository.
        
        Returns:
            PaginatedList[Branch]: List of branches
        """
    
    def get_branch(self, branch: str):
        """
        Get a specific branch.
        
        Args:
            branch (str): Branch name
            
        Returns:
            Branch: Branch object
        """
    
    def get_git_refs(self, subspace: str = None):
        """
        Get Git references.
        
        Args:
            subspace (str, optional): Reference subspace (e.g., "heads", "tags")
            
        Returns:
            PaginatedList[GitRef]: List of Git references
        """
    
    def get_git_ref(self, ref: str):
        """
        Get a specific Git reference.
        
        Args:
            ref (str): Reference name (e.g., "heads/main", "tags/v1.0")
            
        Returns:
            GitRef: Git reference object
        """
    
    def create_git_ref(self, ref: str, sha: str):
        """
        Create a Git reference.
        
        Args:
            ref (str): Reference name
            sha (str): SHA of the object to point to
            
        Returns:
            GitRef: Created Git reference
        """
    
    def get_tags(self):
        """
        Get repository tags.
        
        Returns:
            PaginatedList[Tag]: List of tags
        """

Collaboration and Permissions

Manage repository collaborators, permissions, and access control.

class Repository:
    def get_collaborators(self, affiliation: str = None):
        """
        Get repository collaborators.
        
        Args:
            affiliation (str, optional): Filter by affiliation ("outside", "direct", "all")
            
        Returns:
            PaginatedList[NamedUser]: List of collaborators
        """
    
    def add_to_collaborators(self, collaborator: str, permission: str = None):
        """
        Add a collaborator to the repository.
        
        Args:
            collaborator (str): Username of collaborator to add
            permission (str, optional): Permission level ("pull", "push", "admin")
        """
    
    def remove_from_collaborators(self, collaborator: str):
        """
        Remove a collaborator from the repository.
        
        Args:
            collaborator (str): Username of collaborator to remove
        """
    
    def get_permission(self, user: str):
        """
        Get user's permission level for the repository.
        
        Args:
            user (str): Username
            
        Returns:
            str: Permission level
        """

Webhook Management

Create and manage repository webhooks for event notifications.

class Repository:
    def get_hooks(self):
        """
        Get repository webhooks.
        
        Returns:
            PaginatedList[Hook]: List of webhooks
        """
    
    def get_hook(self, id: int):
        """
        Get a specific webhook.
        
        Args:
            id (int): Webhook ID
            
        Returns:
            Hook: Webhook object
        """
    
    def create_hook(
        self,
        name: str,
        config: dict,
        events: list = None,
        active: bool = True
    ):
        """
        Create a repository webhook.
        
        Args:
            name (str): Webhook name (usually "web")
            config (dict): Webhook configuration (url, content_type, etc.)
            events (list, optional): List of events to trigger webhook
            active (bool, optional): Whether webhook is active
            
        Returns:
            Hook: Created webhook
        """

class Hook:
    def edit(
        self,
        name: str = None,
        config: dict = None,
        events: list = None,
        active: bool = None
    ):
        """
        Edit webhook configuration.
        
        Args:
            name (str, optional): Webhook name
            config (dict, optional): Updated configuration
            events (list, optional): Updated events list
            active (bool, optional): Active status
        """
    
    def delete(self):
        """Delete the webhook."""
    
    def test(self):
        """
        Test the webhook.
        
        Returns:
            bool: Test result
        """
    
    def ping(self):
        """
        Ping the webhook.
        
        Returns:
            bool: Ping result
        """

Repository Statistics and Traffic

Access repository statistics, traffic data, and analytics.

class Repository:
    def get_stats_contributors(self):
        """
        Get contributor statistics.
        
        Returns:
            list[StatsContributor]: Contributor statistics
        """
    
    def get_stats_commit_activity(self):
        """
        Get weekly commit activity.
        
        Returns:
            list[StatsCommitActivity]: Weekly commit statistics
        """
    
    def get_stats_code_frequency(self):
        """
        Get code frequency statistics.
        
        Returns:
            list[StatsCodeFrequency]: Code frequency data
        """
    
    def get_stats_participation(self):
        """
        Get participation statistics.
        
        Returns:
            StatsParticipation: Participation data
        """
    
    def get_stats_punch_card(self):
        """
        Get punch card statistics.
        
        Returns:
            list[StatsPunchCard]: Punch card data
        """
    
    def get_clones_traffic(self, per: str = None):
        """
        Get repository clone traffic.
        
        Args:
            per (str, optional): Grouping ("day" or "week")
            
        Returns:
            Clones: Clone traffic data
        """
    
    def get_views_traffic(self, per: str = None):
        """
        Get repository view traffic.
        
        Args:
            per (str, optional): Grouping ("day" or "week")
            
        Returns:
            View: View traffic data
        """

Repository Settings and Management

Update repository settings, manage topics, and perform repository operations.

class Repository:
    def edit(
        self,
        name: str = None,
        description: str = None,
        homepage: str = None,
        private: bool = None,
        has_issues: bool = None,
        has_wiki: bool = None,
        has_downloads: bool = None,
        default_branch: str = None,
        allow_squash_merge: bool = None,
        allow_merge_commit: bool = None,
        allow_rebase_merge: bool = None,
        delete_branch_on_merge: bool = None
    ):
        """
        Edit repository settings.
        
        Args:
            name (str, optional): Repository name
            description (str, optional): Repository description
            homepage (str, optional): Homepage URL
            private (bool, optional): Repository visibility
            has_issues (bool, optional): Enable issues
            has_wiki (bool, optional): Enable wiki
            has_downloads (bool, optional): Enable downloads
            default_branch (str, optional): Default branch 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
            delete_branch_on_merge (bool, optional): Delete head branch after merge
        """
    
    def replace_topics(self, topics: list):
        """
        Replace repository topics.
        
        Args:
            topics (list): List of topic strings
        """
    
    def delete(self):
        """Delete the repository."""
    
    def create_fork(self, organization: str = None):
        """
        Fork the repository.
        
        Args:
            organization (str, optional): Organization to fork to
            
        Returns:
            Repository: Forked repository
        """

Content File Operations

class ContentFile:
    @property
    def name(self) -> str: ...
    @property
    def path(self) -> str: ...
    @property
    def sha(self) -> str: ...
    @property
    def size(self) -> int: ...
    @property
    def content(self) -> str: ...
    @property
    def decoded_content(self) -> bytes: ...
    @property
    def encoding(self) -> str: ...
    @property
    def type(self) -> str: ...  # "file" or "dir"
    
    def update(self, message: str, content: str, branch: str = None):
        """
        Update this file's content.
        
        Args:
            message (str): Commit message
            content (str): New content
            branch (str, optional): Branch name
        """
    
    def delete(self, message: str, branch: str = None):
        """
        Delete this file.
        
        Args:
            message (str): Commit message
            branch (str, optional): Branch name
        """

Usage Examples

Basic Repository Operations

from github import Github, Auth

g = Github(auth=Auth.Token("your_token"))

# Get repository
repo = g.get_repo("owner/repository")
print(f"Repository: {repo.full_name}")
print(f"Description: {repo.description}")
print(f"Language: {repo.language}")
print(f"Stars: {repo.stargazers_count}")

# Get repository contents
contents = repo.get_contents("")  # Root directory
for content in contents:
    print(f"- {content.name} ({content.type})")

# Get specific file
readme = repo.get_readme()
print(f"README content: {readme.decoded_content.decode('utf-8')}")

File Management

from github import Github, Auth, InputGitAuthor

g = Github(auth=Auth.Token("your_token"))
repo = g.get_repo("owner/repository")

# Create a new file
author = InputGitAuthor("Your Name", "your.email@example.com")
result = repo.create_file(
    path="new-file.txt",
    message="Add new file",
    content="Hello, World!",
    author=author
)
print(f"Created file with SHA: {result['commit'].sha}")

# Update the file
file_content = repo.get_contents("new-file.txt")
repo.update_file(
    path="new-file.txt",
    message="Update file content",
    content="Hello, Updated World!",
    sha=file_content.sha,
    author=author
)

Branch Management

# List all branches
for branch in repo.get_branches():
    print(f"Branch: {branch.name}")

# Get specific branch
main_branch = repo.get_branch("main")
print(f"Main branch commit: {main_branch.commit.sha}")

# Create new branch
repo.create_git_ref(
    ref="refs/heads/new-feature",
    sha=main_branch.commit.sha
)

Install with Tessl CLI

npx tessl i tessl/pypi-pygithub

docs

authentication.md

git-operations.md

index.md

issues-pull-requests.md

repository-management.md

search-discovery.md

user-organization-management.md

workflows-actions.md

tile.json