Production-grade GitHub AI SDK
Project description
github-agent-sdk
Production-grade modular GitHub AI SDK for Python.
This SDK gives you:
- async GitHub REST + GraphQL access
- high-level API modules (
repos,issues,pulls,search, etc.) - an orchestration layer for common agent workflows
- typed models for key GitHub resources
- testable, composable interfaces for automation scripts and AI agents
Install
pip install github-agent-sdk
Requirements
- Python
>=3.11 - GitHub token with required scopes for the APIs you call
Authentication
Set your token:
export GITHUB_TOKEN="ghp_your_token_here"
Quick Start
import asyncio
import os
from github_agent_sdk.agent import GitHubAgent
from github_agent_sdk.client import GitHub
async def main():
github = GitHub(token=os.environ["GITHUB_TOKEN"])
agent = GitHubAgent(github)
repos = await agent.search.repositories("ai agents python", limit=5)
print(repos["total_count"])
await github.close()
asyncio.run(main())
Package Exports
Top-level exports from github_agent_sdk:
GitHubGitHubAgentGistAPINotificationAPIMetaAPI
Core Client
GitHub
Main async HTTP client wrapper.
from github_agent_sdk.client import GitHub
github = GitHub(token="...")
data = await github.request("GET", "/user")
await github.close()
Constructor options:
token: GitHub token (required)timeout: request timeout in seconds (default60)base_url: GitHub API base URL (defaulthttps://api.github.com)user_agent: custom User-Agent header
Error Types
Handle SDK exceptions from github_agent_sdk.exceptions:
GitHubAuthenticationError(invalid/expired token)GitHubRateLimitError(rate limit exhausted)GitHubAPIError(other API errors)GitHubError(base class)
High-Level APIs via GitHubAgent
Instantiate once and use module-style APIs:
agent = GitHubAgent(github)
Available modules:
agent.repositoriesagent.branchesagent.contentsagent.pullsagent.issuesagent.searchagent.actionsagent.graphqlagent.organizationsagent.usersagent.gistsagent.notificationsagent.meta
API Reference
Repositories (agent.repositories)
get(owner, repo)create(name, *, private=True, description="", auto_init=True)
repo = await agent.repositories.get("octocat", "Hello-World")
new_repo = await agent.repositories.create("my-repo", private=True)
Branches (agent.branches)
get_sha(owner, repo, branch)create(owner, repo, *, branch, from_branch="main")
Contents (agent.contents)
get(owner, repo, path, branch="main")get_text(owner, repo, path, branch="main")create_or_update(owner, repo, *, path, content, message, branch)
text = await agent.contents.get_text("acme", "repo", "README.md")
await agent.contents.create_or_update(
"acme",
"repo",
path="README.md",
content=text + "\nUpdated\n",
message="docs: update readme",
branch="main",
)
Pull Requests (agent.pulls)
create(owner, repo, *, title, body, head, base="main")
Issues (agent.issues)
create(owner, repo, *, title, body, labels=None)list(*, filter="assigned", state="open", per_page=30, page=1)(global/issues)
Search (agent.search)
repositories(query, limit=10)code(query, limit=10)commits(query, limit=10)issues(query, limit=10)labels(query, repository_id, *, page=None, per_page=10)topics(query, limit=10)users(query, limit=10)
Actions (agent.actions)
trigger(owner, repo, *, workflow_id, ref="main", inputs=None)
GraphQL (agent.graphql)
query(query, variables=None)
Organizations (agent.organizations)
get(org)repositories(org, *, per_page=100)teams(org, *, per_page=100)
Users (agent.users)
me()get(username)emails()followers()following(*, per_page=30, page=1)is_following(target)->boolkeys()organizations()repositories(*, type="owner", page=1, per_page=30, sort="full_name")(current user repos)user_repositories(username, *, type="owner", page=1, per_page=30, sort="full_name")starred(*, page=1, per_page=30)has_starred(owner, repo)->bool
Gists (agent.gists)
list(*, per_page=30, page=1)get(gist_id)public(*, per_page=30, page=1)starred(*, per_page=30, page=1)
Notifications (agent.notifications)
list(*, all=False, participating=False, per_page=30, page=1)
Meta (agent.meta)
emojis()events(*, per_page=30, page=1)feeds()hub()rate_limit()
Built-in Workflow Helper
GitHubAgent.create_fix_pull_request(...)
End-to-end helper that:
- fetches repo default branch
- creates a new branch
- writes/updates file content
- opens a PR back to the default branch
pr = await agent.create_fix_pull_request(
owner="acme",
repo="service",
file_path="README.md",
content="new docs",
branch_name="fix/docs",
commit_message="docs: update readme",
pr_title="Fix docs",
pr_body="Updates README wording.",
)
Models
Typed models available in github_agent_sdk.models:
RepositoryPullRequestIssueWorkflow
MCP Server (All Tools Ready)
This package ships with an MCP server that exposes the SDK methods as ready-to-use tools for agentic projects.
Install MCP Support
pip install "github-agent-sdk[mcp]"
Required Environment Variables
export GITHUB_TOKEN="ghp_your_token_here"
Optional:
GITHUB_SDK_TIMEOUT(default60)GITHUB_BASE_URL(defaulthttps://api.github.com)GITHUB_SDK_USER_AGENT(defaultGitHubAgentSDK-MCP/1.0)
Run MCP Server
github-agent-sdk-mcp
Use in MCP Clients (Example)
Use github-agent-sdk-mcp as a stdio MCP server command in your client config.
{
"mcpServers": {
"githubAgentSdk": {
"command": "github-agent-sdk-mcp",
"env": {
"GITHUB_TOKEN": "ghp_your_token_here"
}
}
}
}
MCP Tool Naming
Tools are grouped by SDK module with predictable names:
repositories_*,branches_*,contents_*,pulls_*,issues_*search_*,actions_*,graphql_queryorganizations_*,users_*gists_*,notifications_*,meta_*create_fix_pull_request
Examples:
repositories_getcontents_create_or_updatesearch_repositoriesusers_has_starredmeta_rate_limit
Development
Install dev dependencies and run tests:
python3 -m pip install -e ".[dev]"
python3 -m pytest -q
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file github_agent_sdk-0.1.0.tar.gz.
File metadata
- Download URL: github_agent_sdk-0.1.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4a9607e465a8b9e5d561434ab8fea7529f3cc1c94e0f425b510326a9b21648b
|
|
| MD5 |
cbe753e74cb0ff803f3fc8fb199acdcd
|
|
| BLAKE2b-256 |
56f5f46cbe7129fafb234497a681f90bf3e74ea87d7a263d826c786bb876e138
|
File details
Details for the file github_agent_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: github_agent_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26d6aaa974188792b5e81db6ef3b54e1bbb2972c20bad1f7113aab2c79b117fb
|
|
| MD5 |
74fff38b016e8ea28719e6ee430e3d2d
|
|
| BLAKE2b-256 |
9fff6299de3f20886a8b7aa9712ce018f0884e5d5a680d205e77b99fc244f5e7
|