Configs2026年7月15日·1 分钟阅读

PyGithub — Typed Python Client for the GitHub API

A Python library providing typed access to the GitHub REST API v3 for managing repositories, issues, pull requests, organizations, and users programmatically.

Agent 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 29/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
CLI Tool
安装
Single
信任
信任等级:Established
入口
PyGithub Overview
安全暂存命令
npx -y tokrepo@latest install 8808dc46-808e-11f1-9bc6-00163e2b0d79 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

Introduction

PyGithub is a Python library that provides typed interactions with the GitHub REST API v3. It maps GitHub resources (repositories, issues, pull requests, users, organizations) to Python objects with attributes and methods, making it easy to automate GitHub workflows, build integrations, and manage repositories from Python scripts.

What PyGithub Does

  • Maps GitHub API resources to Python objects with typed attributes and methods
  • Supports authentication via personal access tokens, OAuth tokens, and GitHub App installation tokens
  • Handles pagination transparently through lazy-loading paginated lists
  • Provides read and write access to repos, issues, PRs, branches, releases, actions, and more
  • Manages rate limiting with automatic wait or exception-based handling

Architecture Overview

PyGithub wraps the GitHub REST API v3 using the requests library for HTTP transport. Each GitHub resource (Repository, Issue, PullRequest, Organization) is represented as a Python class with properties that map to API response fields. Related resources are accessed via methods that return lazy-loaded objects or paginated lists. Authentication tokens are passed at the Github object level and attached to every request. The library caches ETags for conditional requests to reduce rate limit consumption.

Self-Hosting & Configuration

  • Requires Python 3.8 or newer
  • Install with pip install PyGithub
  • Generate a personal access token at github.com/settings/tokens
  • For GitHub Apps, use the GithubIntegration class with your app's private key
  • Set base_url for GitHub Enterprise Server instances

Key Features

  • Full coverage of GitHub REST API v3 endpoints
  • Typed Python objects with IDE autocompletion and type hints
  • Transparent pagination: iterate over all items without managing page tokens
  • Support for GitHub Apps authentication and installation token generation
  • Conditional requests using ETags to minimize API quota usage

Comparison with Similar Tools

  • Octokit.js — JavaScript equivalent; PyGithub serves the same role for Python developers
  • ghapi — FastAI's GitHub API wrapper with a more dynamic approach; PyGithub offers typed objects
  • github3.py — Alternative Python GitHub library with a similar design; PyGithub has broader adoption
  • gh CLI — GitHub's official command-line tool; PyGithub is for programmatic access in Python applications

FAQ

Q: How do I handle rate limits? A: PyGithub tracks remaining API calls. You can check g.get_rate_limit() or enable retry on the Github object to automatically wait when limits are hit.

Q: Does PyGithub support the GraphQL API? A: No, PyGithub only covers the REST API v3. For GraphQL, use libraries like gql or sgqlc.

Q: Can I use PyGithub with GitHub Enterprise? A: Yes. Pass base_url="https://your-ghe-instance/api/v3" when creating the Github object.

Q: What license does PyGithub use? A: LGPL-3.0 License.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产