Getting Started
Install the SDK and read a file from a repo in under 2 minutes.
Quickstart
Section titled “Quickstart”pip install githostedfrom githosted import Client
client = Client(token="gw_your_workspace_token")repo = client.repo("my-project")
files = repo.ls("src/")print(files)# [FileEntry(name='main.py', type='file'), FileEntry(name='lib', type='directory')]
file = repo.read("src/main.py")print(file.content)# "print('hello')"Installation
Section titled “Installation”pip install githostedThe only runtime dependency is httpx. Python 3.10+ is required.
Authentication
Section titled “Authentication”The SDK needs a workspace token (gw_) or repo token (gr_). Pass it directly or set the GITHOSTED_TOKEN environment variable:
export GITHOSTED_TOKEN=gw_your_workspace_token# Explicit tokenclient = Client(token="gw_xxx")
# Auto-reads GITHOSTED_TOKEN from envclient = Client()See Authentication for the full credential resolution order.
Reading and Writing
Section titled “Reading and Writing”repo = client.repo("my-project")
# Read a filefile = repo.read("README.md")print(file.content) # file contents as stringprint(file.head_sha) # branch tip SHA — use for optimistic concurrency
# Write a filerepo.write("README.md", "# Updated readme", "Update readme")
# Atomic multi-file commitwith repo.transaction("Add feature") as tx: tx.write("src/feature.py", feature_code) tx.write("tests/test_feature.py", test_code)Using Repo IDs
Section titled “Using Repo IDs”Repos have stable IDs (rp_ prefix) that don’t change on rename. You can reference repos by slug or ID:
# By slugrepo = client.repo("my-project")
# By stable ID — preferred for persistencerepo = client.repo(id="rp_8f3k2m1q9t6w4z7c5n2h")