Metadata-Version: 2.5
Name: teleport-tap-sdk
Version: 0.1.0
Summary: Teleport TAP API for Python: post physical work, route it, verify it, get Teleport PoPW receipts (Proof of Physical Work, anchored on Base), and check signed webhooks.
Project-URL: Homepage, https://teleport.eco/developers
Project-URL: Documentation, https://teleport.eco/developers
Project-URL: API reference, https://api.teleport.eco/api/v1/openapi.json
Project-URL: Provider Protocol, https://teleport.eco/protocol/providers
Author: Teleport Ecosystem, LLC
License-Expression: MIT
License-File: LICENSE
Keywords: mcp,physical work,popw,proof of physical work,tap,teleport,verification,webhooks
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: cryptography>=41
Description-Content-Type: text/markdown

# teleport-tap-sdk (Python)

The Python SDK for the [Teleport](https://teleport.eco) TAP API. Use it to post physical work, send it to the people who can do it, verify the evidence they send back, and get a **Teleport PoPW receipt**: a Proof of Physical Work record anchored on Base. It also checks the signed webhooks Teleport sends you.

- **Requirements:** Python 3.10+. The only dependency is `cryptography`, used for signature checks.
- **Generated from the spec:** every operation in the [OpenAPI spec](https://api.teleport.eco/api/v1/openapi.json) can be reached with `call()`, and every schema is a `TypedDict` in `teleport_tap.models`.
- **TypeScript:** the same SDK is on npm as [`teleport-tap-sdk`](https://www.npmjs.com/package/teleport-tap-sdk).

```sh
pip install teleport-tap-sdk
```

## Quickstart

```python
from teleport_tap import Teleport

teleport = Teleport()  # reads TELEPORT_API_KEY; or Teleport("tp_live_…")

posted = teleport.templates.create_task("shelf-restock", {
    "locationId": "loc_…",
    "spot": "Cooler 4",
    "routing": {"audience": "LOCATION_STAFF"},
})
task = teleport.tasks.get(posted["task"]["id"])
```

To try it without anyone being alerted or anything being anchored, use a **test key** (`tp_test_…`). Then move the task along yourself; the same webhooks fire as for live work:

```python
teleport.sandbox.simulate(task_id, {"action": "submit_evidence"})
teleport.sandbox.simulate(task_id, {"action": "accept"})
```

| Namespace | Methods |
|---|---|
| `tasks` | `create`, `get`, `find`, `events`, `submit_evidence`, `create_uploads`, `create_capture_link` |
| `routes` | `start`, `get`, `cancel`, `escalate` |
| `routing_policies` | `get`, `set` |
| `verifications` | `create`, `get`, `submit_evidence` |
| `templates` | `list`, `get`, `create_task` |
| `receipts` | `get_claim`, `get_proof`, `get_batch`, `verify` |
| `proof_network` | `encoding`, `assurance_policies`, `verification_policies` |
| `webhooks` | `create`, `list`, `get`, `delete`, `replay`, `verify` |
| `sandbox` | `simulate` |
| `account` | `me`, `register_agent` |

Anything else, by its operationId:

```python
teleport.call("getSite", path={"id": "site_…"})
```

Every failed call raises `TeleportError`, which carries `status`, `code`, `message`, `details` and `request_id`. Reads are retried on network errors, 429 and 5xx. Writes are retried only on 429, because a write that never answered may still have been processed.

## Webhooks

Teleport signs every outcome event with ES256: a detached JWS in the `Teleport-Signature` header. Verify the **raw** body before you act on it:

```python
from teleport_tap import WebhookVerificationError, verify_webhook

@app.post("/teleport")  # FastAPI; Flask and Django work the same way
async def teleport_webhook(request: Request):
    raw = await request.body()
    try:
        event = verify_webhook(raw, request.headers)
    except WebhookVerificationError:
        return Response(status_code=400)
    if event["type"] == "task.accepted":
        ...  # dedupe on event["eventId"]: delivery is at least once
    return {"ok": True}
```

- **Signing keys:** fetched from `https://api.teleport.eco/.well-known/teleport-outcome-keys.json` and cached for 10 minutes. When a key id isn't in the cache, the keys are fetched again, so key rotation works.
- **Age limit:** deliveries signed more than 5 minutes ago are refused. Change this with `tolerance_seconds`.
- **Route events:** you also get `route.offered`, `route.claimed`, `route.released`, `route.exhausted` and `route.cancelled`, with details in `event["route"]`.
- **Paused webhooks:** if deliveries fail for 3 days, Teleport pauses the subscription and emails your organization's owners. Catch up with `teleport.webhooks.replay(subscription_id, "2026-11-16T00:00:00Z")`.

## Verify a receipt without trusting Teleport

```python
from teleport_tap import verify_receipt

check = verify_receipt("claim_62d4wz7njqgazpa6")
check["verified"]      # True: the claim hash recomputes, and it's in the anchored batch
check["claimHash"]     # {"published", "recomputed", "matches"}
check["onChain"]       # the last check, on Base: PhysicalWorkRegistry.batchOf(batchId)
```

- **What it checks:** it fetches the claim's public proof (no key needed). Then, on your machine, it recomputes the claim hash from its 25 committed fields under the EIP-712 domain, and folds the Merkle inclusion proof up to the batch root.
- **Lower-level tools:** `teleport_tap.popw` has Keccak-256, JCS document hashes, the claim hash, Merkle proofs, and the TAP v0.3 draft.3 constructions. It's tested against the published test vectors.

## For providers (TAP Provider Protocol)

Supply platforms take Teleport jobs through the [TAP Provider Protocol](https://teleport.eco/protocol/providers). Apply at [teleport.eco/protocol/providers/apply](https://teleport.eco/protocol/providers/apply).

```python
from teleport_tap import TeleportProvider, verify_provider_event

provider = TeleportProvider()  # your provider key (tp_test_… in the sandbox)
offers = provider.list_offers()["offers"]
job = provider.accept(offers[0]["offerId"], {"performerRef": "worker-7731"})
provider.update_status(job["assignmentId"], {"status": "ON_SITE"})
provider.payouts()  # Stripe payouts: paid per job once the requester's payment succeeds
```

Every call carries `Teleport-Provider-Version`, and every write gets a fresh `Idempotency-Key`.

For push delivery, check each event with `verify_provider_event(raw_body, headers)`. It uses the provider keys and refuses outcome-webhook signatures. Dedupe on `eventId`, and ignore event types you don't know.

## License

MIT
