MCPcopy Index your code
hub / github.com/XAMPPRocky/octocrab

github.com/XAMPPRocky/octocrab @v0.53.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.53.1 ↗ · + Follow
2,418 symbols 5,922 edges 363 files 860 documented · 36% updated 16d agov0.53.1 · 2026-06-10★ 1,41298 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Octocrab: A modern, extensible GitHub API client.

Rust crates.io Help Wanted Documentation Crates.io

Octocrab is a third party GitHub API client, allowing you to easily build your own GitHub integrations or bots in Rust. Octocrab comes with two primary sets of APIs for communicating with GitHub, a high level strongly typed semantic API, and a lower level HTTP API for extending behaviour.

Adding Octocrab

Run this command in your terminal to add the latest version of Octocrab.

cargo add octocrab

Semantic API

The semantic API provides strong typing around GitHub's API, a set of [models] that maps to GitHub's types, and [auth] functions that are useful for GitHub apps. Currently, the following modules are available as of version 0.44.

  • [actions] GitHub Actions
  • [activity] GitHub Activity
  • [apps] GitHub Apps
  • [checks] GitHub Checks
  • [codes_of_conduct] GitHub Codes of Conduct
  • [code_scannings] Code Scanning
  • [commits] GitHub Commits
  • [current] Information about the current user
  • [events] GitHub Events
  • [gists] Gists
  • [gitignore] Gitignore templates
  • [graphql] GraphQL
  • [issues] Issues and related items, e.g. comments, labels, etc.
  • [licenses] License Metadata
  • [markdown] Rendering Markdown with GitHub
  • [orgs] GitHub Organisations
  • [projects] GitHub Projects
  • [pulls] Pull Requests
  • [ratelimit] Rate Limiting
  • [repos] Repositories
  • [search] Using GitHub's search
  • [teams] Teams
  • [users] Users

Getting a Pull Request

// Get pull request #5 from `XAMPPRocky/octocrab`.
let issue = octocrab::instance().pulls("XAMPPRocky", "octocrab").get(5).await?;

All methods with multiple optional parameters are built as Builder structs, allowing you to easily specify parameters.

Listing issues

let octocrab = octocrab::instance();
// Returns the first page of all issues.
let mut page = octocrab
    .issues("XAMPPRocky", "octocrab")
    .list()
    // Optional Parameters
    .creator("XAMPPRocky")
    .state(params::State::All)
    .per_page(50)
    .send()
    .await?;

// Go through every page of issues. Warning: There's no rate limiting so
// be careful.
loop {
    for issue in &page {
        println!("{}", issue.title);
    }
    page = match octocrab
        .get_page::<models::issues::Issue>(&page.next)
        .await?
    {
        Some(next_page) => next_page,
        None => break,
    }
}

HTTP API

The typed API currently doesn't cover all of GitHub's API at this time, and even if it did GitHub is in active development and this library will likely always be somewhat behind GitHub at some points in time. However that shouldn't mean that in order to use those features, you have to fork or replace octocrab with your own solution.

Instead octocrab exposes a suite of HTTP methods allowing you to easily extend Octocrab's existing behaviour. Using these HTTP methods allows you to keep using the same authentication and configuration, while having control over the request and response. There is a method for each HTTP method, get, post, patch, put, delete, all of which accept a relative route and a optional body.

let user: octocrab::models::User = octocrab::instance()
    .get("/user", None::<&()>)
    .await?;

Each of the HTTP methods expects a body, formats the URL with the base URL, and errors if GitHub doesn't return a successful status, but this isn't always desired when working with GitHub's API, sometimes you need to check the response status or headers. As such there are companion methods _get, _post, etc. that perform no additional pre or post-processing to the request.

let octocrab = octocrab::instance();
let response = octocrab
    ._get("https://api.github.com/organizations")
    .await?;

// You can also use `Uri::builder().authority("<my custom base>").path_and_query("<my custom path>")` if you want to customize the base uri and path.
let response =  octocrab
    ._get(Uri::builder().path_and_query("/organizations").build().expect("valid uri"))
    .await?;

You can use the those HTTP methods to easily create your own extensions to Octocrab's typed API. (Requires async_trait).

use octocrab::{Octocrab, Page, Result, models};

#[async_trait::async_trait]
trait OrganisationExt {
  async fn list_every_organisation(&self) -> Result<Page<models::Organization>>;
}

#[async_trait::async_trait]
impl OrganisationExt for Octocrab {
  async fn list_every_organisation(&self) -> Result<Page<models::Organization>> {
    self.get("/organizations", None::<&()>).await
  }
}

You can also easily access new properties that aren't available in the current models using serde.

#[derive(Deserialize)]
struct RepositoryWithVisibility {
    #[serde(flatten)]
    inner: octocrab::models::Repository,
    visibility: String,
}

let my_repo = octocrab::instance()
    .get::<RepositoryWithVisibility>("https://api.github.com/repos/XAMPPRocky/octocrab", None::<&()>)
    .await?;

Static API

Octocrab also provides a statically reference counted version of its API, allowing you to easily plug it into existing systems without worrying about having to integrate and pass around the client.

// Initialises the static instance with your configuration and returns an
// instance of the client.
octocrab::initialise(octocrab::Octocrab::builder());
// Gets a instance of `Octocrab` from the static API. If you call this
// without first calling `octocrab::initialise` a default client will be
// initialised and returned instead.
let octocrab = octocrab::instance();

GitHub Webhook Support

octocrab provides deserializable datatypes for the payloads received by a GitHub application responding to webhooks. This allows you to write a typesafe application using Rust with pattern-matching/enum-dispatch to respond to events.

Note: Webhook support in octocrab is still beta, not all known webhook events are strongly typed.

use http::request::Request;
use tracing::{warn, info};
use octocrab::models::webhook_events::*;

let request_from_github = Request::post("https://my-webhook-url.com").body(vec![0_u8]).unwrap();
// request_from_github is the HTTP request your webhook handler received
let (parts, body) = request_from_github.into_parts();
let header = parts.headers.get("X-GitHub-Event").unwrap().to_str().unwrap();

let event = WebhookEvent::try_from_header_and_body(header, &body).unwrap();
// Now you can match on event type and call any specific handling logic
match event.kind {
    WebhookEventType::Ping => info!("Received a ping"),
    WebhookEventType::PullRequest => info!("Received a pull request event"),
    // ...
    _ => warn!("Ignored event"),
};

Extension points exported contracts — how you extend this code

FromResponse (Interface)
(no doc) [3 implementers]
src/from_response.rs
CacheStorage (Interface)
[HttpCacheLayer] is agnostic to the storage implementation (e.g., in-memory, filesystem, etc.). This trait represents th [1 …
src/service/middleware/cache.rs
EndpointSelector (Interface)
(no doc) [2 implementers]
src/api/gists/list_gists.rs
CacheWriter (Interface)
Writes the response body to the cache. [1 implementers]
src/service/middleware/cache.rs
RateLimitMetrics (Interface)
Gather metrics about retry behavior when handling rate limit headers. [1 implementers]
src/service/middleware/retry.rs

Core symbols most depended-on inside this repo

clone
called by 135
src/lib.rs
build
called by 123
src/lib.rs
setup_error_handler
called by 97
tests/mock_error.rs
send
called by 94
src/lib.rs
base_uri
called by 86
src/lib.rs
repos
called by 77
src/lib.rs
map_github_error
called by 75
src/lib.rs
context
called by 66
src/api/markdown.rs

Shape

Method 1,032
Class 626
Function 585
Enum 170
Interface 5

Languages

Rust100%

Modules by API surface

src/lib.rs121 symbols
src/models.rs70 symbols
src/api/repos.rs55 symbols
src/api/issues.rs54 symbols
src/api/checks.rs40 symbols
src/api/repos/releases.rs35 symbols
src/api/actions.rs35 symbols
src/params.rs33 symbols
src/api/pulls.rs32 symbols
src/models/repos.rs31 symbols
src/models/pulls.rs30 symbols
src/api/gists.rs30 symbols

For agents

$ claude mcp add octocrab \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page