Easy to use Python SDK for the GitCode REST API, community-maintained.
Project description
GitCode-API
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 groups such as
client.repos,client.pulls, andclient.users. - Repository defaults via
owner=andrepo=on the client. - Sphinx docs plus a mirrored GitCode REST API reference in
docs/.
Installation
Install from PyPI:
pip install -U 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,
)
CLI
After installation, you can invoke the SDK directly from the command line:
gitcode-api repos get --api-key "$GITCODE_ACCESS_TOKEN" --owner SushiNinja --repo GitCode-API
python -m gitcode_api pulls list --api-key "$GITCODE_ACCESS_TOKEN" --owner SushiNinja --repo GitCode-API --state open
Commands mirror the synchronous resource methods on GitCode, using the pattern
gitcode-api <resource> <method> .... For methods that accept extra **params
or **payload, pass repeated --set key=value flags or --set-json '{"key": "value"}'.
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. close() also clears the LRU cache used by each resource group's method_signature(...) helper (see the Available Resources section).
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")
pull = client.pulls.create(
title="Add feature",
head="feature-branch",
base="main",
body="Implements the new flow.",
)
print(pull.number)
Get the authenticated user:
from gitcode_api import GitCode
client = GitCode()
user = client.users.me()
print(user.login)
Search repositories:
from gitcode_api import GitCode
client = GitCode()
repos = client.search.repositories(q="sdk language:python", per_page=10)
for repo in repos:
print(repo.full_name)
Available Resources
Both GitCode and AsyncGitCode expose:
reposandcontentsbranchesandcommitsissuesandpullslabels,milestones, andmembersreleases,tags, andwebhooksusers,orgs,search, andoauth
Every resource group inherits a cached methods property from the shared resource base: a tuple of public callable names in stable SDK order (underscore-segment sort key, not plain A–Z on the full identifier). Private names and the introspection helpers methods and method_signature are omitted. For example, client.pulls.methods helps with discovery or tooling without reading the full manual list. For one method’s parameters and return type, call client.pulls.method_signature("list_issues") (a cached string from inspect.signature, with gitcode_api._models. stripped from annotations).
Examples
Runnable examples live in examples/:
get_current_user.pyget_repository_overview.pylist_pull_requests.pyasync_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
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 gitcode_api-1.2.2.tar.gz.
File metadata
- Download URL: gitcode_api-1.2.2.tar.gz
- Upload date:
- Size: 64.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40550226a1dbf68a4d9e49e112e693f8cb7c67215bb247cde0271f1859893493
|
|
| MD5 |
61b3029028039ce441f969abd782b2d0
|
|
| BLAKE2b-256 |
b5cf488ca5e4e583186980618fdda3021daa749bebcac0fd4067017224debbf7
|
Provenance
The following attestation bundles were made for gitcode_api-1.2.2.tar.gz:
Publisher:
python-publish.yml on Trenza1ore/GitCode-API
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gitcode_api-1.2.2.tar.gz -
Subject digest:
40550226a1dbf68a4d9e49e112e693f8cb7c67215bb247cde0271f1859893493 - Sigstore transparency entry: 1415813236
- Sigstore integration time:
-
Permalink:
Trenza1ore/GitCode-API@4af6d141ee773a4443cdd36d673807d7c12993a0 -
Branch / Tag:
refs/tags/1.2.2 - Owner: https://github.com/Trenza1ore
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@4af6d141ee773a4443cdd36d673807d7c12993a0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file gitcode_api-1.2.2-py3-none-any.whl.
File metadata
- Download URL: gitcode_api-1.2.2-py3-none-any.whl
- Upload date:
- Size: 61.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
893a410308d4718fe50985aca430c9d368857fb931c9c71bded202c3d83999ad
|
|
| MD5 |
fd87975610e289608446616c3ef1eb5a
|
|
| BLAKE2b-256 |
6559857efc5451d74447c4e7fed343999655191ea7a0910e855961ee46f0d469
|
Provenance
The following attestation bundles were made for gitcode_api-1.2.2-py3-none-any.whl:
Publisher:
python-publish.yml on Trenza1ore/GitCode-API
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gitcode_api-1.2.2-py3-none-any.whl -
Subject digest:
893a410308d4718fe50985aca430c9d368857fb931c9c71bded202c3d83999ad - Sigstore transparency entry: 1415813339
- Sigstore integration time:
-
Permalink:
Trenza1ore/GitCode-API@4af6d141ee773a4443cdd36d673807d7c12993a0 -
Branch / Tag:
refs/tags/1.2.2 - Owner: https://github.com/Trenza1ore
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@4af6d141ee773a4443cdd36d673807d7c12993a0 -
Trigger Event:
release
-
Statement type: