SDKs overview

The GitHub API offers extensive capabilities for programmatically interacting with nearly all features of the GitHub platform, including repositories, users, issues, pull requests, and GitHub Actions workflows. To facilitate this interaction, GitHub provides official SDKs, primarily under the Octokit brand, alongside a vibrant ecosystem of community-contributed libraries. These SDKs and libraries abstract the underlying HTTP requests, handle authentication (such as OAuth 2.0 or GitHub Apps authentication), manage rate limits, and simplify data serialization and deserialization, allowing developers to focus on application logic rather than API mechanics.

Developers can choose an SDK based on their preferred programming language and the specific features of the GitHub API they intend to use. The official Octokit libraries are designed to provide a consistent interface across different languages, adhering closely to the structure and conventions of the GitHub REST API and, in some cases, offering support for the GraphQL API. Community libraries often extend this functionality, provide alternative approaches, or focus on specific use cases or language idioms.

For authentication, GitHub APIs support various methods, including Personal Access Tokens (PATs), OAuth 2.0, and GitHub Apps installations. SDKs typically include mechanisms to manage these authentication flows securely. For instance, OAuth 2.0 is an industry-standard protocol that allows users to grant third-party applications limited access to their resources without sharing their credentials, as detailed in the OAuth 2.0 Authorization Framework specification. Understanding the chosen authentication method is crucial for configuring any SDK correctly.

Official SDKs by language

GitHub's official SDKs are primarily maintained under the Octokit organization, providing robust and up-to-date clients for several popular programming languages. These libraries are designed to offer comprehensive coverage of the GitHub REST API and, in some instances, the GraphQL API. They are actively maintained by GitHub and the open-source community, ensuring compatibility with the latest API versions and features.

Language Package Name Install Command Maturity Notes
JavaScript/TypeScript @octokit/core (and related packages) npm install @octokit/core or yarn add @octokit/core Stable Modular design, supports REST and GraphQL, highly configurable. See Octokit.js documentation.
Ruby octokit.rb gem install octokit Stable Comprehensive Ruby client for the GitHub API.
Python PyGithub pip install PyGithub Stable A high-level wrapper for the GitHub API. While not officially branded Octokit, it is widely recognized and supported by the community for Python.
Go go-github go get github.com/google/go-github/v60@latest Stable Official Go client for the GitHub API, maintained by Google.
C#/.NET Octokit.net Install-Package Octokit (NuGet) Stable GitHub API client for .NET, supports authentication and API calls.

Installation

Installation methods vary by programming language and package manager. The following examples demonstrate common installation procedures for the official Octokit libraries.

JavaScript/TypeScript (Node.js)

For Node.js projects, use npm or yarn to install the core Octokit package and any additional plugins you might need.

# Using npm
npm install @octokit/core

# Using yarn
yarn add @octokit/core

Ruby

For Ruby applications, the octokit.rb gem is installed using Bundler or directly via the gem command.

# Using Bundler (add to Gemfile then bundle install)
gem 'octokit'

# Direct installation
gem install octokit

Python

The PyGithub library is installed using pip, Python's package installer.

pip install PyGithub

Go

Go modules are used to manage dependencies. The go-github library is installed using the go get command.

go get github.com/google/go-github/v60@latest

C#/.NET

For .NET projects, Octokit.net is installed via NuGet Package Manager.

# .NET CLI
dotnet add package Octokit

# NuGet Package Manager Console
Install-Package Octokit

Quickstart example

This quickstart demonstrates how to fetch a user's profile information using the GitHub API with the JavaScript Octokit library. Ensure you have Node.js installed and have obtained a GitHub Personal Access Token (PAT) for authentication. Replace YOUR_PAT with your actual token and octocat with the GitHub username you wish to query.

JavaScript (Node.js) Example: Fetching User Data

First, create a new project directory and initialize it:

mkdir github-quickstart
cd github-quickstart
npm init -y
npm install @octokit/core dotenv

Create a .env file in your project root with your PAT:

GITHUB_TOKEN=YOUR_PAT

Now, create an index.js file with the following content:

require('dotenv').config();
const { Octokit } = require('@octokit/core');

async function getUserProfile(username) {
  const octokit = new Octokit({
    auth: process.env.GITHUB_TOKEN,
  });

  try {
    const response = await octokit.request('GET /users/{username}', {
      username: username,
    });
    console.log(`User: ${response.data.login}`);
    console.log(`Name: ${response.data.name || 'N/A'}`);
    console.log(`Public Repos: ${response.data.public_repos}`);
    console.log(`Followers: ${response.data.followers}`);
    console.log(`Bio: ${response.data.bio || 'N/A'}`);
  } catch (error) {
    console.error(`Error fetching user profile for ${username}:`, error.message);
    if (error.status) {
      console.error(`Status: ${error.status}`);
    }
  }
}

getUserProfile('octocat'); // Replace 'octocat' with any GitHub username

Run the script:

node index.js

This script initializes an Octokit client with your PAT and then makes a GET request to the /users/{username} endpoint to retrieve profile details for the specified user. The dotenv package is used to load environment variables, keeping your token out of the source code.

Community libraries

Beyond the officially supported Octokit suite, the GitHub API benefits from a robust ecosystem of community-developed libraries. These libraries often cater to specific needs, offer different programming paradigms, or provide specialized functionalities that complement the official SDKs. While not officially endorsed or maintained by GitHub, many community libraries are widely used and well-regarded within their respective language communities.

Examples of popular community-driven libraries include:

  • Python: While PyGithub is often considered the de-facto Python client, other libraries like github3.py offer alternative interfaces, sometimes focusing on specific API versions or features.
  • PHP: The php-github-api library by KnpLabs is a popular and well-maintained client for PHP developers, providing an object-oriented interface to the GitHub API.
  • Java: Libraries such as github-api (by Kohsuke Kawaguchi) or org.eclipse.egit.github.core (part of EGit) offer Java developers ways to interact with GitHub services.
  • Rust: For Rust developers, octocrab is a popular choice, providing an idiomatic Rust interface to the GitHub API.
  • CLI Tools: Beyond programming libraries, many community-developed command-line interface tools enhance interaction with GitHub, such as gh-cli extensions or specialized scripts.

When selecting a community library, developers should consider factors such as active maintenance, community support, documentation quality, and compatibility with the latest GitHub API versions. Checking the library's GitHub repository for recent commits, open issues, and pull requests can provide insights into its ongoing health and reliability. The HTTP status codes returned by the GitHub API, such as 200 OK for success or 403 Forbidden for authentication issues, are important for any library to handle gracefully, regardless of whether it's official or community-maintained.