The package ships with a command-line entry point named gitcode-api and also
supports module invocation via python -m gitcode_api.
The CLI mirrors the synchronous GitCode client surface:
gitcode-api <resource> <method> [options]
For example, client.repos.get() becomes gitcode-api repos get ... and
client.pulls.list() becomes gitcode-api pulls list ....
Running gitcode-api with no arguments prints a short banner (version line
and ASCII art when stdout is a TTY) followed by the same top-level help as
gitcode-api -h.
Install the package from PyPI:
pip install -U gitcode-apiOr install the local project in editable mode while developing:
pip install -e .Pass --api-key directly or set GITCODE_ACCESS_TOKEN in your environment.
Most leaf commands share --base-url, --timeout, --output-file,
--compact, and -e / --escape (see :ref:`cli-escaping`).
The CLI does not expose the Python client's decrypt or custom
http_client hooks. If you store an encrypted token or need a bespoke
httpx client, use :class:`~gitcode_api.GitCode` in code instead (see
:doc:`index` authentication examples).
export GITCODE_ACCESS_TOKEN="your-token"gitcode-api repos get --owner SushiNinja --repo GitCode-APIIf a command calls a repository-scoped method and no owner / repo is
available from the command line, the SDK raises GitCodeConfigurationError.
With the [mcp] extra installed (Python 3.10+), gitcode-api serve
starts the bundled FastMCP server (same tool as :doc:`llm_tools`).
--transport—stdio,http, orsse(defaultstdio).--show-banner—trueorfalseto show or hide the FastMCP startup banner; omit the flag to use FastMCP’s default.--owner/--repo— optional defaults for repository-scoped tool calls.
gitcode-api serve --api-key "$GITCODE_ACCESS_TOKEN"Use -h / --help at any level to inspect available resource groups, methods, and flags:
gitcode-api --help
gitcode-api repos --help
gitcode-api pulls create --helpResource help lists subcommand names in the same order as
resource.methods on the sync client. Each method's help opens with a
signature line matching resource.method_signature("<name>") in Python, then
the docstring summary—so the CLI stays aligned with runtime introspection on
:class:`~gitcode_api.GitCode`.
Print the installed package version:
gitcode-api --versionGet repository metadata:
gitcode-api repos get \
--api-key "$GITCODE_ACCESS_TOKEN" \
--owner SushiNinja \
--repo GitCode-APIList open pull requests:
gitcode-api pulls list \
--owner SushiNinja \
--repo GitCode-API \
--state open \
--per-page 20Search repositories:
gitcode-api search repositories \
--q sdkBuild an OAuth authorization URL:
gitcode-api oauth build-authorize-url \
--client-id client-id \
--redirect-uri https://example.com/callback \
--scope user_info \
--state opaque-stateSome SDK methods are not well documented, so the CLI cannot know
every supported flag ahead of time. For those methods, pass repeated
--set key=value pairs or a JSON object with --set-json.
gitcode-api pulls list \
--owner SushiNinja \
--repo GitCode-API \
--set only_count=true \
--set reviewer=octocatgitcode-api repos update \
--owner SushiNinja \
--repo GitCode-API \
--set-json '{"description": "Updated from CLI", "has_wiki": false}'If the JSON payload is easier to keep in a file, prefix the path with @:
gitcode-api repos update \
--owner SushiNinja \
--repo GitCode-API \
--set-json @payload.jsonMost commands print JSON to stdout. Use --compact for single-line JSON, or
--output-file to write the response to disk.
gitcode-api search repositories --q sdk --compactRaw-byte responses such as contents get-raw can also be written directly to
a file:
gitcode-api contents get-raw \
--owner SushiNinja \
--repo GitCode-API \
--path README.md \
--output-file README.downloaded.mdWhen using string arguments with escape sequences (such as a line break as
\n), your shell may leave the backslashes as literal characters instead of
turning them into the intended character. Pass -e / --escape with the
sequences you want un-escaped—for example -e '\n\t'. Those tokens are
substituted into other string arguments and into string elements of list
arguments. The escape flag itself, resource, method, api_key, and
base_url are not rewritten. If --escape is set but contains no valid
tokens, argument parsing fails.
gitcode-api pulls create ... --body 'Line1\nLine2' -e '\n'If you prefer not to rely on the installed console script, use the module entry point:
python -m gitcode_api users me --api-key "$GITCODE_ACCESS_TOKEN"