Skip to content

Repos

Repos are created programmatically and referenced by slug or stable ID.

from githosted import Client
client = Client()
# Create a repo
repo = client.create_repo("my-new-project")
print(repo.id) # "rp_8f3k2m1q9t6w4z7c5n2h"
# Write immediately — no setup needed
repo.write("README.md", "# My Project", "Initial commit")
repo = client.repo("my-project")
repo = client.repo(id="rp_8f3k2m1q9t6w4z7c5n2h")

Store IDs, not slugs. Repo IDs (rp_ prefix) are globally unique and stable even if the repo is renamed. Slugs are human-readable but can change.

Create a new repo in a workspace. Returns a Repo handle with a stable ID.

repo = client.create_repo("session-data")
# The repo is immediately ready for reads and writes
print(repo.id) # "rp_..."
print(repo.info.slug) # "session-data"

Get a handle to an existing repo. Does not make a network call — the handle is created locally.

# These are equivalent ways to get a repo handle
repo = client.repo("my-project")
repo = client.repo(id="rp_8f3k2m1q9t6w4z7c5n2h")
PropertyValue
Formatrp_ prefix + 20-char NanoID (0-9a-z)
UniqueGlobally unique across all workspaces
StableDoesn’t change if repo is renamed

client.list_repos(*, page_size, page_token)

Section titled “client.list_repos(*, page_size, page_token)”

List all repos in the workspace. Requires a workspace token (gw_).

result = client.list_repos()
for r in result.repos:
print(f"{r.id} {r.slug} ({r.default_branch})")
# Paginated
page = client.list_repos(page_size=10)
next_page = client.list_repos(page_token=page.next_page_token)
# When creating a project for a user
repo = client.create_repo(f"{user_id}-{project_name}")
db.users.update(user_id, repo_id=repo.id)
# Later — resume from stored ID
repo_id = db.users.get(user_id).repo_id
repo = client.repo(id=repo_id)