Python SDK for the Opper Task API
Project description
Opper Python SDK
Python client for the Opper API.
Install
pip install opperai
Quick Start
from opperai import Opper
opper = Opper() # uses OPPER_API_KEY env var
result = opper.call("summarize", input={"text": "Long article..."})
print(result.data)
# Stream a function
for chunk in opper.stream("summarize", input={"text": "Long article..."}):
if chunk.type == "content":
print(chunk.delta, end="")
if chunk.type == "complete":
print(chunk.data)
Schema Support
Pass Pydantic models, dataclasses, TypedDicts, or raw JSON Schema dicts for input_schema and output_schema — the SDK resolves them to JSON Schema automatically.
from pydantic import BaseModel
class Summary(BaseModel):
summary: str
entities: list[str]
result = opper.call(
"extract",
input={"text": "Marie Curie was a physicist in Paris."},
output_schema=Summary,
)
result.data.summary # str — typed!
result.data.entities # list[str]
Dataclasses, TypedDicts, and plain dicts also work. See 01a_using_schemas.py and 01b_using_other_schemas.py.
Observability
Use trace() as a decorator or context manager to group calls under a single trace span. Nesting works naturally.
@opper.trace("my-pipeline")
def run():
a = opper.call("step-1", input="hello")
b = opper.call("step-2", input=a.data)
# or as a context manager
with opper.trace("my-pipeline") as span:
opper.call("step-1", input="hello")
Examples
| # | Example | What it shows |
|---|---|---|
| 00 | First call | Simplest possible call |
| 01a | Pydantic schemas | Type-safe output with Pydantic |
| 01b | Other schemas | Dataclass, TypedDict, raw dict |
| 02 | Streaming | Stream deltas + complete event |
| 03a | Tools (call) | Tool definitions with call() |
| 03b | Tools (stream) | Tool call chunks in streaming |
| 04a | Generate image | Image generation |
| 04b | Describe image | Vision / image description |
| 04c | Edit image | Image editing |
| 05 | Audio | Text-to-speech + speech-to-text |
| 06 | Video | Video generation |
| 07 | Embeddings | Vector embeddings + similarity |
| 08 | Function mgmt | List, get, revisions, delete |
| 09 | Observability | Tracing with decorator + context manager |
| 09b | Manual tracing | Manual span creation |
| 09c | Traces | List, get, and inspect traces |
| 10 | Models | List available models |
| 12 | Knowledge base | Semantic search with knowledge bases |
| 13 | Web tools | Web search and URL fetch (beta) |
Run a single example:
export OPPER_API_KEY="your-key"
uv run python examples/getting-started/00_your_first_call.py
Run all examples:
uv run python examples/run_all.py
Configuration
| Parameter | Default | Env Var |
|---|---|---|
api_key |
— | OPPER_API_KEY |
base_url |
https://api.opper.ai |
OPPER_BASE_URL |
headers |
{} |
— |
Error Handling
from opperai import ApiError
try:
opper.call("my-fn", input="hello")
except ApiError as e:
print(e.status, e.body)
Async Support
All methods have _async variants:
result = await opper.call_async("summarize", input={"text": "..."})
async for chunk in opper.stream_async("summarize", input={"text": "..."}):
print(chunk.delta, end="")
Requirements
- Python 3.10+
- Optional:
pip install opperai[pydantic]for Pydantic schema support
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opperai-2.0.0b4.tar.gz.
File metadata
- Download URL: opperai-2.0.0b4.tar.gz
- Upload date:
- Size: 2.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aebc477cb498e7f77584d1a96b6b5c9addb598421d43d4d22ceaac02de97eb48
|
|
| MD5 |
e5245f5460bf420dc07f9d46717b46c2
|
|
| BLAKE2b-256 |
0c8f9d0535c6ab01a588b9936464037cd8277db11d1f2f4a9575d415aa6d0dad
|
Provenance
The following attestation bundles were made for opperai-2.0.0b4.tar.gz:
Publisher:
publish.yml on opper-ai/opper-sdks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opperai-2.0.0b4.tar.gz -
Subject digest:
aebc477cb498e7f77584d1a96b6b5c9addb598421d43d4d22ceaac02de97eb48 - Sigstore transparency entry: 1206205565
- Sigstore integration time:
-
Permalink:
opper-ai/opper-sdks@81367aad3ac173b51928143911efb5cfa69e5c80 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/opper-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@81367aad3ac173b51928143911efb5cfa69e5c80 -
Trigger Event:
push
-
Statement type:
File details
Details for the file opperai-2.0.0b4-py3-none-any.whl.
File metadata
- Download URL: opperai-2.0.0b4-py3-none-any.whl
- Upload date:
- Size: 27.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e98ddb255443139fd560f1556b75a6e2e0d757b3683f6198b32c2b3bece7c307
|
|
| MD5 |
a03206874b8053cf2798e551b7f64b5c
|
|
| BLAKE2b-256 |
f4bae9b75e0de18f4fec91cdd2196879238da9bec41b54423414d1b95e49ee20
|
Provenance
The following attestation bundles were made for opperai-2.0.0b4-py3-none-any.whl:
Publisher:
publish.yml on opper-ai/opper-sdks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opperai-2.0.0b4-py3-none-any.whl -
Subject digest:
e98ddb255443139fd560f1556b75a6e2e0d757b3683f6198b32c2b3bece7c307 - Sigstore transparency entry: 1206205572
- Sigstore integration time:
-
Permalink:
opper-ai/opper-sdks@81367aad3ac173b51928143911efb5cfa69e5c80 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/opper-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@81367aad3ac173b51928143911efb5cfa69e5c80 -
Trigger Event:
push
-
Statement type: