Library / SDK
octokit/octokit.rb avatar
octokit/octokit.rb

octokit.rb: The Ruby Gem for the GitHub API with Flat Methods, Pagination, and GitHub App Auth

Ruby toolkit for the GitHub API

3,951 stars1,168 forksRubyMIT

At a glance

What is it?
octokit.rb is the official Ruby toolkit for the GitHub REST API, providing a flat client API that follows Ruby conventions and requires no knowledge of REST to use. It handles authentication through OAuth tokens, GitHub Apps, and basic credentials, supports automatic pagination, and works with GitHub Enterprise.
Who is it for?
octokit.rb is the natural choice for any Ruby application that needs to interact with the GitHub API. It handles the authentication, pagination, error mapping, and HTTP response parsing that every caller would otherwise need to write.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 8 days ago.
What is it written in?
Mainly Ruby, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 29, 2026, and from our analysis. They are not legal advice.

Editorial analysis

What octokit.rb Provides and Who It Is For

The GitHub API is a REST API that accepts and returns JSON over HTTPS. Using it directly from Ruby means constructing requests, setting headers, handling rate limits, parsing responses, following pagination links, and raising exceptions on error codes. octokit.rb handles all of that.

The README states its philosophy clearly: API wrappers should reflect the idioms of the language in which they were written. The gem wraps the GitHub API in a flat client where API methods are available as Ruby methods with positional arguments for required inputs and an options hash for optional parameters, headers, or other options. The README gives this example:

ruby
client = Octokit::Client.new

# Fetch a README with Accept header for HTML format
client.readme 'al3x/sovereign', :accept => 'application/vnd.github.html'

The result is that a Ruby developer can call GitHub API endpoints without learning the URL structure or constructing HTTP requests by hand. The client method names correspond to GitHub API operations, and the response is a Resource object that supports dot notation and hash-style access.

The primary users are Ruby and Rails applications that integrate with GitHub: tools that list repositories, manage issues, trigger Actions workflows, process webhook payloads, or administer GitHub Enterprise instances.

Installation and Basic Usage

Installing octokit.rb follows standard Ruby gem conventions:

ruby
gem install octokit

Or in a Gemfile:

ruby
gem "octokit"

Access the library in Ruby:

ruby
require 'octokit'

Creating an authenticated client and fetching the current user:

ruby
# Provide authentication credentials
client = Octokit::Client.new(:access_token => 'personal_access_token')

# Fetch the current user
client.user

The response from most methods is a Resource object. Dot notation and bracket notation both work:

ruby
user = client.user 'jbarnette'
puts user.name
# => "John Barnette"
puts user[:company]
# => "GitHub"

URL fields in responses are separated into a .rels collection for hypermedia navigation. The README notes that this is intentional: it keeps the resource object clean while making related resource URLs accessible.

For methods that take additional query parameters on GET requests, the options hash accepts a query key:

ruby
client.repos({}, query: {type: 'owner', sort: 'asc'})

Authentication: OAuth Tokens, GitHub Apps, and More

octokit.rb supports multiple authentication methods, each documented in the README.

OAuth access tokens are the preferred method for authenticating on behalf of users. They provide revocable access and scoped permissions:

ruby
client = Octokit::Client.new(:access_token => 'personal_access_token')

Basic authentication with username and password (using a personal access token as the password) is supported but the README recommends OAuth tokens instead:

ruby
client = Octokit::Client.new(:login => 'defunkt', :password => 'personal_access_token')

GitHub App authentication is supported through a separate mechanism. Apps authenticate using a JWT signed with a private key, then exchange it for an installation access token. This authentication model is used by GitHub Apps that need to act on behalf of installations rather than individual users.

Application-level authentication (using a client ID and secret) is available for unauthenticated calls that need a higher rate limit than anonymous requests receive.

Configuration can be set globally on the Octokit module rather than on individual client instances, and environment variables (OCTOKIT_ACCESS_TOKEN and others) are supported for twelve-factor-style configuration.

Pagination and Error Handling

Many GitHub API endpoints return paginated results. octokit.rb provides two ways to handle this.

Manual pagination uses the rel links in the HTTP response. The last_response object on the client exposes the HTTP headers, where rel links for the next and last pages are available. Callers can iterate manually using these links.

Auto-pagination is built in. Setting auto_paginate on the client or module causes list methods to fetch all pages and return a combined array. The trade-off is that auto-pagination loads all results into memory at once, which can be significant for large repositories or organisations. The README recommends using it selectively rather than enabling it globally.

Error handling maps HTTP error codes to typed Ruby exceptions. The README documents the mapping: a 400 response raises Octokit::BadRequest, a 403 with a rate-limit message raises Octokit::TooManyRequests. All exceptions inherit from Octokit::Error and expose response_status, response_headers, and response_body. Validation errors from the API expose an errors array with detailed information from the API response.

Accessing the raw HTTP response for headers like ETags is straightforward:

ruby
user     = client.user 'andrewpthorp'
response = client.last_response
etag     = response.headers[:etag]

This is the standard pattern for implementing conditional requests and client-side caching.

The README also documents support for making repeating requests, which is useful for polling or for operations that must wait for a resource to reach a certain state. The Hypermedia agent section explains how Resource objects carry link relations from the API response: calling .rels[:gists].href on a user resource returns the URL for that user's gists endpoint, allowing navigation through the API without hardcoding URLs. URI templates from the API are expanded automatically.

GitHub Enterprise and Limitations

octokit.rb supports GitHub Enterprise Server. The README documents three separate interaction patterns: the standard GitHub.com REST API endpoints (which work the same way against Enterprise), the GitHub Enterprise Admin API for server administration, and the GHES Manage API for instance management operations.

Connecting to an Enterprise instance requires setting the api_endpoint and web_endpoint to the Enterprise server's URLs. The README notes that SSL connection errors can occur when the Enterprise instance uses a self-signed certificate, and it covers how to configure the underlying Faraday HTTP client to handle this.

The gem wraps the GitHub REST API only. The GitHub GraphQL API is a separate interface with a different client library. For operations that return deeply nested relational data (such as fetching issues with their comments, labels, and assignees in a single request), GraphQL is more efficient because it avoids multiple round-trips. octokit.rb does not support GraphQL.

A specific scenario where octokit.rb is the wrong tool is any application that needs to query across repositories in bulk (for example, listing every open pull request across all repositories in a large organisation with thousands of repos). Auto-pagination collects results in memory, and the REST API requires a separate request per repository. The GraphQL API's ability to fetch multiple resources in a single query is a better fit for that access pattern.

The README lists a Supported Ruby Versions section and follows semantic versioning. Version 10.0.0 (released 2025-04-24) is the latest release. The upgrade guide in the README covers breaking changes between major versions, and the README's opening note calls out the need to review it before bumping to a new major version.

Maintenance and Licence

The last push to the repository was on 2026-09-21. The most recent release is v10.0.0, published on 2025-04-24. Earlier releases v9.2.0 (2024-10-16) and v9.1.0 (2024-06-11) are also available. The repository is not archived.

octokit.rb is the official Ruby client for the GitHub API, maintained in the octokit GitHub organisation. It is MIT-licensed. The repository includes CODE_OF_CONDUCT.md, CONTRIBUTING.md, and SECURITY.md documents. A .github/ directory is present for CI and automation configuration.

The README notes a recent branch rename: the 4-stable branch was renamed to main. Users with local clones made before this change may need to update their local repository configuration; the README links to a discussion thread with the specific steps.

The gem follows semantic versioning. The README explicitly advises checking the upgrade guide before bumping to a new major version, as breaking changes are expected across major releases. A RELEASE.md file is also present in the repository for maintainers documenting the release process. The octokit.gemspec file defines the supported Ruby version range, which users targeting specific Ruby installations should verify.

Editorial conclusion

octokit.rb is the natural choice for any Ruby application that needs to interact with the GitHub API. It handles the authentication, pagination, error mapping, and HTTP response parsing that every caller would otherwise need to write. The flat method API and dot-notation resource objects make it usable without reading the GitHub API reference for basic tasks. The main limitation is scope: it wraps the GitHub REST API, not the GraphQL API, so operations that return large connected data sets may be more efficient with a GraphQL client. Verify that version 10.0.0 (released 2025-04-24) does not introduce breaking changes relative to your current integration before upgrading; the README references a full upgrade guide for major version bumps.

Frequently asked questions

How do I authenticate with octokit.rb using a GitHub App?

GitHub App authentication in octokit.rb uses a JWT signed with the app's private key, which is exchanged for an installation access token. The README documents this under the GitHub App authentication section and provides the required client configuration.

Does octokit.rb support automatic pagination?

Yes. Setting auto_paginate to true on the client or Octokit module causes list methods to fetch all pages automatically and return a combined array. The trade-off is that all results are loaded into memory at once.

Does octokit.rb work with GitHub Enterprise Server?

Yes. Set api_endpoint and web_endpoint to your Enterprise instance URLs. The README also documents the GitHub Enterprise Admin API and GHES Manage API for server-administration operations specific to Enterprise deployments.

Official sources

  1. License: MIT
  2. octokit/octokit.rb on GitHub
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/octokit-octokit-rb.svg)](https://hysenlabs.com/projects/octokit-octokit-rb)