Skip to main content

gfa-sdk — Python SDK for gfa (Git for Agents)

Opinionated Python client for gfa. Picks the right endpoint for the access pattern, caches what is safe to cache, and emits hints when a strategy change would help. Designed for AI agents reading, mutating, and forking gfa-hosted repos.

Install

pip install gfa-sdk

Python >= 3.10 required.

Quickstart

import os
import gfa

client = gfa.Client(
    endpoint=os.environ["GFA_ENDPOINT"],
    token=os.environ["GFA_JWT"],
)

# Profile a repo (cheap, cached for the session)
profile = client.profile_repo("myrepo")
print(f"{profile.file_count_at_head} files, {profile.storage_bytes} bytes")

# Read one file
src = client.read_file("myrepo", "src/main.go")

# Read many files — SDK picks /file vs /files/batch vs partial-clone
files = client.read_files("myrepo", ["a.go", "b.go", "c.go"])

# Create a commit
sha = client.create_commit(
    "myrepo",
    branch="main",
    message="agent: refactor",
    files=[gfa.FileChange(path="a.go", content=b"// rewritten\n")],
)

# Workspace for isolated changes
with client.create_workspace("myrepo", base_ref="main", ttl_hours=2) as ws:
    ws.create_commit(branch="main", message="WIP", files=[...])
    ws.merge()

Smart routing

client.read_files(repo, paths) auto-routes by len(paths):

Count Surface
1 GET /file
2–200 POST /files/batch
> 200 (default) SuggestPartialCloneError — opt into auto_clone=True for automatic partial clone

Threshold tuning:

from gfa import Client, ClientConfig
client = Client(
    endpoint,
    token,
    config=ClientConfig(batch_read_threshold=500),
)

Hints

The SDK emits structured hints when access patterns suggest a strategy change. The default handler writes to stderr; override with a logging hook:

def my_handler(hint):
    logger.info("gfa hint", extra={"code": hint.code, "repo": hint.repo})

client = gfa.Client(endpoint, token, hint_handler=my_handler)

Silence entirely:

client = gfa.Client(endpoint, token, hint_handler=lambda _: None)

Auth

Either a pre-minted JWT string, or a TokenProvider that mints per-call:

provider = gfa.FileKeyTokenProvider("/path/to/preview-jwt-priv.pem", ttl_hours=1)
client = gfa.Client(endpoint, provider)

FileKeyTokenProvider mints ES256 JWTs with sub=<repo>, iat=now, exp=now + ttl_hours. Mirrors the Go tools/mint-token binary.

Diagnostics

client.read_file("myrepo", "x.go")
client.read_files("myrepo", ["a.go", "b.go"])
print(client.stats)
# ClientStats(request_count=2, cache_hit_rate=0.0, ...)

Partial clone

with client.partial_clone("myrepo", filter="blob:none", depth=1) as repo:
    content = repo.read("src/foo.go")

Requires git binary on PATH.

Troubleshooting

Symptom Likely cause
UnauthorizedError Token missing, malformed, or expired
ForbiddenError JWT sub does not match the repo being accessed
SuggestPartialCloneError Asked for too many files; pass auto_clone=True or use partial_clone
GitBinaryMissingError partial_clone needs git on PATH
ConflictError on merge Workspace and source diverged — inspect via conflict_surface()

License

MIT.

Metadata

Release files for gfa-sdk 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gfa-sdk 0.3.0
File Size Uploaded Provenance Actions
gfa_sdk-0.3.0.tar.gz 43.1 kB Without provenance Details for gfa_sdk-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gfa-sdk 0.3.0
File Interpreter ABI Platform Actions
gfa_sdk-0.3.0-py3-none-any.whl Python 3 none any Details for gfa_sdk-0.3.0-py3-none-any.whl

Total release size: 76.5 kB

Release files / gfa_sdk-0.3.0.tar.gz

Download URL gfa_sdk-0.3.0.tar.gz
Size 43.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0a4b4ef17fd3e800a36ba4f68487d00c648ee5dcc1a3668decd51abb3375c3ba
BLAKE2b-256 checksum
How to use checksums
04ecaa6353169bef595e9dee2a228fe2319dace15040e27998bf4c167c4e6134
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / gfa_sdk-0.3.0-py3-none-any.whl

Download URL gfa_sdk-0.3.0-py3-none-any.whl
Size 33.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68f02d8372636436a9e61d0e0168adb35b66a2878e6b386cb1c356eb464e5f7a
BLAKE2b-256 checksum
How to use checksums
9409828806c9f66eb095beaf18ce583e32f8325dfb7ccc1085c797c5ba65b3cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for gfa-sdk 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page