Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsJul 15, 2026·3 min de lecture

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.

Prêt pour agents

Staging sûr pour cet actif

Cet actif est d'abord staged. Le prompt copié demande à l'agent d'inspecter les fichiers staged avant d'activer scripts, config MCP ou config globale.

Stage only · 29/100Policy : staging
Surface agent
Tout agent MCP/CLI
Type
CLI Tool
Installation
Single
Confiance
Confiance : Established
Point d'entrée
PyGithub Overview
Commande de staging sûr
npx -y tokrepo@latest install 8808dc46-808e-11f1-9bc6-00163e2b0d79 --target codex

Stage les fichiers d'abord; l'activation exige la revue du README et du plan staged.

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

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires