/install gitcode-api
GitCode API SDK
Use the published Python package:
pip install -U gitcode-api
Authentication defaults to the GITCODE_ACCESS_TOKEN environment variable, or pass api_key=... explicitly. If either value is encrypted, pass decrypt=... so the client can decode it before authenticating.
Confirm with user before installation or setup environment variable
Consult user for confirmation before installation:
- like all python packages, installing
gitcode-apimay introduce change to global environment. - when user ask for additional information, you may guide them to:
- the project's pypi page: https://pypi.org/project/gitcode-api/
- documentation: https://gitcode-api.readthedocs.io/
- source repository: https://github.com/Trenza1ore/GitCode-API
- ask user to provide the
GITCODE_ACCESS_TOKENenvironment variable, preferably encrypted:- environment variable may be read by untrusted software as that is not unscoped.
- a
decryptargument can be passed into GitCode clients' constructor to decrypt an encryptedapi_keyvalue or encryptedGITCODE_ACCESS_TOKENat runtime.
Client shape
This SDK is structured similarly to OpenAI's Python clients:
- Start from a top-level client object:
GitCode(...)orAsyncGitCode(...). - Call grouped resources off the client, such as
client.repos,client.pulls,client.users, andclient.search. - Invoke methods on those resource groups, such as
client.repos.get()orawait client.pulls.list(). - Prefer
with GitCode(...) as client:orasync with AsyncGitCode(...) as client:so the SDK closes the underlyinghttpxclient automatically, including a customhttp_client.
Unlike OpenAI's typed request/response shapes, this SDK focuses on GitCode REST resources and returns lightweight response objects with attribute access.
Quick start
Sync:
from gitcode_api import GitCode
with GitCode(
api_key="your-token",
owner="SushiNinja",
repo="GitCode-API",
) as client:
repo = client.repos.get()
pulls = client.pulls.list(state="open", per_page=5)
print(repo.full_name)
for pull in pulls:
print(pull.number, pull.title)
Async:
import asyncio
from gitcode_api import AsyncGitCode
async def main() -> None:
async with AsyncGitCode(
api_key="your-token",
owner="SushiNinja",
repo="GitCode-API",
) as client:
branches = await client.branches.list(per_page=5)
for branch in branches:
print(branch.name)
asyncio.run(main())
Encrypted token:
from gitcode_api import GitCode
from trusted_library import decryption_method
with GitCode(
api_key="encrypted-token",
owner="SushiNinja",
repo="GitCode-API",
decrypt=decryption_method,
) as client:
repo = client.repos.get()
pulls = client.pulls.list(state="open", per_page=5)
print(repo.full_name)
for pull in pulls:
print(pull.number, pull.title)
Repository-scoped defaults
If owner= and repo= are set on the client, repository resources can omit them per call. If not, pass owner= and repo= on repository-scoped methods.
Common resource groups
client.reposandclient.contentsclient.branchesandclient.commitsclient.issuesandclient.pullsclient.labels,client.milestones, andclient.membersclient.releases,client.tags, andclient.webhooksclient.users,client.orgs,client.search, andclient.oauth
Common tasks
- Repository info and file content:
client.repos.get(),client.contents.get(),client.contents.create(),client.contents.update() - Branches, commits, and diffs:
client.branches.list(),client.commits.list(),client.commits.compare() - Issues and pull requests:
client.issues.list(),client.issues.create(),client.pulls.list(),client.pulls.create(),client.pulls.merge() - Account and discovery:
client.users.me(),client.orgs.list_authenticated(),client.search.repositories() - OAuth:
client.oauth.build_authorize_url(),client.oauth.exchange_token()
For the broader method inventory, use references/api-reference.md
Response objects
Responses are lightweight objects, not plain dicts.
Typical usage:
pull = client.pulls.get(number=42)
print(pull.title)
print(pull.get("source_branch"))
payload = pull.to_dict()
Utility scripts
Bundled helpers:
scripts/check_env.pyverifies Python, package import, and token setup.scripts/gitcode_api_cli.pyprovides a small example CLI for common SDK calls, you are advised to write your own version with encrypted access token for security.
Additional resources
- API interfaces and resource method inventory: references/api-reference.md
- Usage habits and troubleshooting flow: references/workflow-patterns.md
FAQ
Q: In company network, access to GitCode failed with SSL errors mentioning "self-signed certificate".
A: Typically, a custom CA bundle needs to be set, user may pass in a custom httpx client with verify set to the certificate path, this is similar to REQUESTS_CA_BUNDLE environment variable for requests library.
from gitcode_api import GitCode
from httpx import Client
with GitCode(
owner="SushiNinja",
repo="GitCode-API",
http_client=Client(verify="path/to/my/certificate.crt"),
) as client:
repo = client.repos.get()
pulls = client.pulls.list(state="open", per_page=5)
...
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install gitcode-api - 安装完成后,直接呼叫该 Skill 的名称或使用
/gitcode-api触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
GitCode API Usage 是什么?
Provides Python SDK access to GitCode REST API with sync/async clients, repo helpers, and CLI scripts for managing repos, pulls, users, and searches. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 90 次。
如何安装 GitCode API Usage?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install gitcode-api」即可一键安装,无需额外配置。
GitCode API Usage 是免费的吗?
是的,GitCode API Usage 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
GitCode API Usage 支持哪些平台?
GitCode API Usage 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 GitCode API Usage?
由 Hugo(@trenza1ore)开发并维护,当前版本 v1.0.1。