Skip to main content

Easy to use Python SDK for the GitCode REST API, community-maintained.

Project description

GitCode-API

PyPI - Version GitHub Badge GitCode Badge PyPI Downloads

Docs 中文README English README

gitcode-api is a community-maintained Python SDK for the GitCode REST API. It provides easy-to-use synchronous and asynchronous clients, repository-scoped helpers, and lightweight response models so you can work with GitCode from Python without hand-writing raw HTTP requests.

Why This Project

  • Community project for developers who want a practical GitCode Python library.
  • Sync and async clients with a consistent API surface.
  • Resource namespaces such as client.repos, client.pulls, and client.users.
  • Repository defaults via owner= and repo= on the client.
  • Sphinx docs plus a mirrored GitCode REST API reference in docs/.

Installation

Install from PyPI:

pip install gitcode-api

Authentication

Pass api_key= directly, or set GITCODE_ACCESS_TOKEN in your environment:

export GITCODE_ACCESS_TOKEN="your-token"

If your token is stored in encrypted form, pass decrypt= to decode either an encrypted api_key= value or an encrypted GITCODE_ACCESS_TOKEN value before the client uses it.

from gitcode_api import GitCode
from trusted_library import decrypt_token

client = GitCode(
    api_key="encrypted-token",
    decrypt=decrypt_token,
)

Quick Start

Sync client

from gitcode_api import GitCode

client = GitCode(
    owner="SushiNinja",
    repo="GitCode-API",
)

repo = client.repos.get()
branches = client.branches.list(per_page=5)

print(repo.full_name)
for branch in branches:
    print(branch.name)

Async client

import asyncio
from gitcode_api import AsyncGitCode

async def main() -> None:
    client = AsyncGitCode(owner="SushiNinja", repo="GitCode-API")
    pulls = await client.pulls.list(state="open", per_page=20)
    print(len(pulls))

asyncio.run(main())

Context managers

GitCode and AsyncGitCode (and the lower-level SyncAPIClient / AsyncAPIClient) support with / async with. Leaving the block calls close() / await close() on the underlying client automatically, including a custom http_client= you passed in.

from gitcode_api import GitCode

with GitCode(owner="SushiNinja", repo="GitCode-API") as client:
    repo = client.repos.get()
    print(repo.full_name)
import asyncio
from gitcode_api import AsyncGitCode

async def main() -> None:
    async with AsyncGitCode(owner="SushiNinja", repo="GitCode-API") as client:
        pulls = await client.pulls.list(state="open", per_page=20)
        print(len(pulls))

asyncio.run(main())

Common Workflows

Create a pull request:

from gitcode_api import GitCode

client = GitCode(owner="SushiNinja", repo="GitCode-API")

try:
    pull = client.pulls.create(
        title="Add feature",
        head="feature-branch",
        base="main",
        body="Implements the new flow.",
    )
    print(pull.number)
finally:
    client.close()

Get the authenticated user:

from gitcode_api import GitCode

client = GitCode()

try:
    user = client.users.me()
    print(user.login)
finally:
    client.close()

Search repositories:

from gitcode_api import GitCode

client = GitCode()

try:
    repos = client.search.repositories(q="sdk language:python", per_page=10)
    for repo in repos:
        print(repo.full_name)
finally:
    client.close()

Available Resources

Both GitCode and AsyncGitCode expose:

  • repos and contents
  • branches and commits
  • issues and pulls
  • labels, milestones, and members
  • releases, tags, and webhooks
  • users, orgs, search, and oauth

Examples

Runnable examples live in examples/:

  • get_current_user.py
  • get_repository_overview.py
  • list_pull_requests.py
  • async_list_branches.py

Example scripts load shared configuration from examples/.env using python-dotenv.

uv run python examples/get_current_user.py
uv run python examples/get_repository_overview.py
uv run python examples/list_pull_requests.py
uv run python examples/async_list_branches.py

See examples/.env.example for the expected variables.

Documentation

  • Project docs entry: docs/index.rst
  • SDK docs: docs/sdk/index.rst
  • REST API mirror: docs/rest_api/index.rst

Build the docs locally with Sphinx:

uv run --group docs sphinx-build -b html docs docs/_build/html

Project Status

This is a community project and is still evolving. API coverage is already broad, but some endpoints and behaviors may continue to be refined as the SDK grows.

Contributing

Issues, bug reports, API coverage improvements, docs fixes, and pull requests are welcome. If you are using GitCode heavily and notice missing endpoints or awkward ergonomics, contributions are especially appreciated.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitcode_api-1.1.2.tar.gz (56.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gitcode_api-1.1.2-py3-none-any.whl (53.9 kB view details)

Uploaded Python 3

File details

Details for the file gitcode_api-1.1.2.tar.gz.

File metadata

  • Download URL: gitcode_api-1.1.2.tar.gz
  • Upload date:
  • Size: 56.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gitcode_api-1.1.2.tar.gz
Algorithm Hash digest
SHA256 96b205907293458296e90d1cc82a6879e6cfc2878c5939cbea02e0f04958fccc
MD5 b4e7cd05bf4c7673e6e1c1bcee18139c
BLAKE2b-256 5884963653bd3b38f30d6ea45ceedf4e55c46544aacf42848d8a09d2e5adda22

See more details on using hashes here.

Provenance

The following attestation bundles were made for gitcode_api-1.1.2.tar.gz:

Publisher: python-publish.yml on Trenza1ore/GitCode-API

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gitcode_api-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: gitcode_api-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 53.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gitcode_api-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ba96ac00ba49bbef01847d22236bc2e22d6a2e8c54599e668ecb248999e9f152
MD5 3eb14ce4b2b56c7e9678eb7f633c0ce2
BLAKE2b-256 c2b5fb6d0672c2c6a7391c960da5693a6d5e6ebfc999271b24a988ee81c70c03

See more details on using hashes here.

Provenance

The following attestation bundles were made for gitcode_api-1.1.2-py3-none-any.whl:

Publisher: python-publish.yml on Trenza1ore/GitCode-API

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page