Metadata-Version: 2.5
Name: opencompute-playground
Version: 1.0.0
Summary: OpenCompute private monolith SDK — Exchange/Ledger OCX net-metering + Edge Pool + OpenAI-compat chat via LiteLLM
Project-URL: Homepage, https://github.com/smitpatel316/OpenCompute
Project-URL: Repository, https://github.com/smitpatel316/OpenCompute
Project-URL: Issues, https://github.com/smitpatel316/OpenCompute/issues
Author-email: OpenCompute <smitpatel316@gmail.com>
License: Proprietary
Keywords: auction,edge,gpu,litellm,openai,opencompute,vickrey,vllm
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Provides-Extra: dev
Requires-Dist: httpx; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Provides-Extra: httpx
Requires-Dist: httpx>=0.24; extra == 'httpx'
Description-Content-Type: text/markdown

# OpenCompute Python SDK

Minimal OpenAI-compat + Exchange/Ledger OCX SDK — file:// previewable, no build.

Per `docs/product.md` Consumer SDK + `frontend/readme.md` CLI first decision.

## Install (local dev, no PyPI)

```bash
# From repo root — editable install, no build
pip install -e sdk/python
# Or with httpx (optional, urllib fallback for Python 3.9 click match issue)
pip install -e "sdk/python[httpx]"
```

## Usage

```python
from opencompute import OpenCompute

# Exchange API 8001 healthy + Edge 8002 + LiteLLM 4000 + vLLM-mock 8000
client = OpenCompute(api_key="dev-key", base_url="http://localhost:8001", edge_url="http://localhost:8002", llm_url="http://localhost:4000")

# Pledges leaderboard 3 active 210 TFLOPs
pledges = client.pledges.list()
print(pledges["total_active_pledges"], pledges["total_tflops_est"])

# Tier-aware router v1 80/20 Edge+4090 + Vickrey second-price auction winner pays second
job = client.jobs.submit(tier=2, gpu_type="4090", edge_eligible=True, task_type="image.embed", count=1)
print(job["cost_cents"], job["spec"]["auction"])  # winner 29 second 120 settled 120 vickrey True 80/20 True

# Billing ceil min1c monotonic 60c/1M Llama 3.1 8B
settlement = client.billing.settle_usage(job_id=job["id"], model="llama-3.1-8b", prompt_tokens=100, completion_tokens=50)
print(settlement["cost_cents"])  # 1c min

# Topup Stripe real credit update idempotent dedup stripe_webhook_events
topup = client.billing.topup(1000)  # cents
print(topup["credit_balance_cents"])

# OpenAI-compat chat via LiteLLM gateway 4000 or Exchange proxy
chat = client.chat.completions.create(model="dev-tiny-opt-125m", messages=[{"role":"user","content":"hi"}])
print(chat["choices"][0]["message"]["content"])

# R2 presigned https://r2.opencompute.dev/artifacts/{job_id}/{filename}?expires=3600&sig=stub HMAC prod boto3
presigned = client.files.presign(job_id=job["id"], filename="model.bin")
print(presigned["presigned_url"])

# Job logs SSE bounded 60s/200 msgs + NATS opencompute.jobs.logs.{job_id}
logs = client.logs.list(job_id=job["id"], limit=100)
print(logs)
for line in client.logs.stream(job_id=job["id"], lines=3):
    print(line)

# Edge scorer charging+WiFi only 10% cap cellular deny parity Python/Go
score = client.edge.score(device_id="dev-mac-1", task_type="image.embed", ram_free=5000, battery=80, is_charging=True)
print(score["eligible"], score["score"])
```

## Architecture

- `src/opencompute/client.py` — `OpenCompute` main client, `PledgesClient`, `JobsClient`, `LedgerClient`, `BillingClient`, `ChatCompletionsClient`, `FilesClient`, `LogsClient`, `EdgeClient` — humble, no framework leaking, per Clean Architecture.
- Uses urllib stdlib fallback when httpx+click fails on Python 3.9 `match` syntax (same fix as `deployments/ocx_cli.py`).
- All endpoints live 11/11 healthy: `api-exchange:8001`, `api-edge:8002`, `litellm:4000`, `vllm-llama:8000`, `prometheus:9090`, `grafana:3001`, `nats:4222`, `temporal:7233`, `postgres:5432`.

## Tests

```bash
PYTHONPATH=sdk/python/src python -m pytest sdk/python/tests -v
```

- Unit: client init, jobs submit payload, auction winner 29 second 120 settled 120, billing ceil min1c, leaderboard 3 active 210 TFLOPs
- E2E: live 8001 /health /metrics dynamic ledger 12 pledges 3 avg second_price 120 + presign + SSE

## Gold

- Small commits <200 lines, <100 for domain core per AGENTS.md §0 non-negotiable.
- Ruff clean, 11/11 healthy live, 16/16 e2e PASS, make lint PASS.
- No secrets logged, bounded timeouts 5-10s per Release It!.

