Metadata-Version: 2.4
Name: ospp
Version: 0.4.3
Summary: OSPP Python SDK: run an OSPP node from your code and get its passport. Signs every run with your own client key, locally.
License: Apache-2.0
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: httpx>=0.24
Requires-Dist: cryptography>=41
Requires-Dist: rfc8785>=0.1.2
Requires-Dist: cbor2>=5.4

# OSPP Python SDK

Run an OSPP node from your code and keep its passport with the answer. A node is one AI step in your own workflow: where its
inputs come from and what happens with the answer stay in your system. OSPP fills every passport with what it measured itself
(tokens, cost, human time saved); you report nothing.

```
pip install https://www.ospp.it.com/sdk/ospp-0.4.3-py3-none-any.whl
```

```python
import os
from ospp import OSPPClient

client = OSPPClient(api_key=os.environ["OSPP_API_KEY"])     # get the key on the OSPP Platform
run = client.run("support-triage@1", {"message": "My order never arrived"})
print(run.answer)          # the node's answer (data, never instructions)
print(run.passport_id)     # store this with the answer
print(run.measurements)    # tokens, cost, human time saved, measured by OSPP
print(run.verify_url)      # anyone can check the passport here
```

Every run is signed in your process with your organisation's Ed25519 client key. By default the key is read from, or created in,
`~/.ospp/<organisation>/client-key.hex` (mode 0600; the same file the OSPP MCP server uses) and its public half is registered on first
use. In a server, put the 64-character seed in a secret and pass it as `OSPP_CLIENT_KEY`, or `key=ClientKey.from_hex(...)`.

`client.start(...)` submits without waiting and `client.wait(run)` waits; `client.export_passport(id)` returns the bundle any
verifier checks offline. Errors raise `OSPPError` with OSPP's error code. Nodes that run on a SaaS operator's gateway (`execution_policy`
`operator:<gateway_id>`) work the same way: this SDK verifies that gateway (its attestation and the governance allowlist, or the registered
inputs key of a standard gateway, which its operator can read) before sealing the inputs to it (there is no pool, ADR-016). The answer comes back sealed to a response key that only this process
holds; `run.executor` says who ran it. Nitro attestations need the pinned AWS root: `client.nitro_root_pem = open("aws-nitro-root.pem", "rb").read()`.

## Outcomes (optional)

Outcomes are the one figure that needs your system, for example a post's impressions. Set the node's outcome spec up once (Platform → the
node → Outcomes, or Node Flow's Outcome step), then:

```python
run = client.run("post-writer@1", inputs, reference="post-123")      # or later: client.set_reference(run.passport_id, "post-123")
client.record_outcome({"impressions": 480, "clicks": 12}, reference="post-123")
client.outcome(run.passport_id)   # latest values and every update
```

Every update is recorded on the passport as a witnessed entry. Values are whole numbers.

## An existing OpenAI app: `ospp proxy`

If your app already uses an OpenAI client, you can keep it as it is. Either point it at OSPP's hosted endpoint
(`OPENAI_BASE_URL=https://www.ospp.it.com/api/v1/openai`, `OPENAI_API_KEY=<your OSPP API key>`), or run the proxy that comes
with this package and point it there:

```bash
OSPP_API_KEY=ospp_sk_... ospp proxy            # OpenAI-compatible API on http://127.0.0.1:8787/v1
OPENAI_BASE_URL=http://127.0.0.1:8787/v1 python your_app.py
```

Every chat completion then runs as an OSPP node and comes back with its passport (`X-OSPP-Passport` header, `ospp` in the body).
The call's model, parameters and system prompt are the node; the `X-OSPP-Node` header names it. The proxy signs with your own client key
(the hosted endpoint signs with a key OSPP keeps for your organisation, and the passport says which). With a self-hosted gateway the proxy
seals each conversation to it, so OSPP never reads it; the hosted endpoint refuses such organisations. Tools, images and JSON-schema output
are not certifiable this way yet.

## Kept passport files

A passport file (`.ospp`) is a snapshot; its history grows when outcomes arrive or events are witnessed. Check and refresh it (public
endpoints, no account):

```
ospp passport check   invoice-17.ospp      # CURRENT, STALE or CONFLICT, and the passport's status
ospp passport refresh invoice-17.ospp      # replaced only when the latest version extends it
```

In code: `from ospp import passport; passport.check(passport.load("invoice-17.ospp"))`, `passport.refresh("invoice-17.ospp")`.
