← 返回
未分类 Key

GitCode API Usage

Uses the gitcode-api Python SDK for GitCode REST automation, including installation, OpenAI-style client structure, sync/async usage, repository-scoped helpers, and bundled CLI helpers. Use when: (1) Writing Agent or Python script that requires access to GitCode, (2) Explaining or debugging GitCode SDK calls such as client.repos.get() or client.pulls.list(), (3) Needing quick repository, pull request, user, or search examples, (4) Running bundled scripts to validate the environment or make simpl
简单易用的GitCode API SKILL,提供 CLI 和轻量级 Python SDK 两种调用方式,用于与 GitCode 的 REST API 进行交互。支持加密访问令牌、异步调用以及完善的类型提示。Easy to use GitCode API SKILL, providing CLI and lightweight Python SDK for interacting with GitCode's REST API. Supports encrypted access token, async usage and proper typing. - Documentation: https://gitcode-api.readthedocs.io/ - PyPI Page: https://pypi.org/project/gitcode-api - GitHub Repo: https://github.com/Trenza1ore/GitCode-API - GitCode Repo: https://gitcode.com/SushiNinja/GitCode-API
Sushi
未分类 community v1.1.0 2 版本 99435 Key: 需要
★ 1
Stars
📥 156
下载
💾 1
安装
2
版本
#latest

概述

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-api may 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_TOKEN environment variable, preferably encrypted:
  • environment variable may be read by untrusted software as that is not unscoped.
  • a decrypt argument can be passed into GitCode clients' constructor to decrypt an encrypted api_key value or encrypted GITCODE_ACCESS_TOKEN at runtime.

Client shape

This SDK is structured similarly to OpenAI's Python clients:

  • Start from a top-level client object: GitCode(...) or AsyncGitCode(...).
  • Call resource groups off the client, such as client.repos, client.pulls, client.users, and client.search.
  • Invoke methods on those resource groups, such as client.repos.get() or await client.pulls.list().
  • Each resource group exposes methods (public callable names in stable SDK order via a segment-based sorting) and method_signature(name) (a cached inspect.signature string for one callable) for runtime introspection; see the "Resource introspection" section in references/api-reference.md.
  • Prefer with GitCode(...) as client: or async with AsyncGitCode(...) as client: so the SDK closes the underlying httpx client automatically, including a custom http_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.repos and client.contents
  • client.branches and client.commits
  • client.issues and client.pulls
  • client.labels, client.milestones, and client.members
  • client.releases, client.tags, and client.webhooks
  • client.users, client.orgs, client.search, and client.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.py verifies Python, package import, and token setup.
  • scripts/gitcode_api_cli.py is a legacy example CLI (deprecated; it warns on use). Prefer the package's experimental built-in CLI (gitcode-api or python -m gitcode_api); see https://gitcode-api.readthedocs.io/en/latest/sdk/cli.html. For production, keep tokens out of argv and use env vars or your own wrapper.

Additional resources

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)
    ...

版本历史

共 2 个版本

  • v1.1.0 - Added runtime resource introspection (`methods` and `method_signature(name)`) for all resource groups; details in `references/api-reference.md`. - Updated guidance on CLI usage: marked bundled CLI script as deprecated, with recommendation to use the package's built-in CLI and best practices for token handling. - Expanded documentation links, including direct links to hosted SDK quickstart and CLI documentation. - No code or file changes detected; updates apply to documentation and usage advice only. 当前
    2026-05-01 07:53 安全 安全
  • v1.0.1 Initial version
    2026-04-18 00:19 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-intelligence

self-improving agent

pskoett
捕获经验教训、错误及修正内容,以实现持续改进。适用于以下场景:(1)命令或操作意外失败;(2)用户纠正Claude(如“不,那不对……”“实际上……”);(3)用户请求的功能不存在;(4)外部API或工具出现故障;(5)Claude发现自身
★ 4,064 📥 801,449
ai-intelligence

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,363 📥 319,199
security-compliance

Skill Vetter

spclaudehome
AI智能体技能安全预审工具。安装ClawdHub、GitHub等来源技能前,检查风险信号、权限范围及可疑模式。
★ 1,219 📥 266,974