Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ If no DSN is configured, the client becomes a no-op and logs a warning.

| Integration | Example |
|---|---|
| `anthropic` | [anthropic_example.py](https://github.com/wild-edge/wildedge-python/blob/main/examples/anthropic_example.py) |
| `openai` | [openai_example.py](https://github.com/wild-edge/wildedge-python/blob/main/examples/openai_example.py) |

**Hub tracking**
Expand Down
2 changes: 2 additions & 0 deletions docs/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ The table below is generated from `scripts/compat_matrix.py`.

| Integration | Version set | Dependencies | Supported Python |
|---|---|---|---|
| `anthropic` | `min` | `anthropic==0.25.0` | 3.10, 3.11, 3.12, 3.13 |
| `anthropic` | `current` | `anthropic==0.92.0` | 3.10, 3.11, 3.12, 3.13 |
| `onnx` | `min` | `onnxruntime==1.18.1`, `numpy==1.26.4` | 3.10, 3.11, 3.12, 3.13, 3.14 |
| `onnx` | `min` (`py3.13` override) | `onnxruntime==1.20.1`, `numpy==2.1.3` | 3.13 |
| `onnx` | `current` | `onnxruntime==1.20.1`, `numpy==2.1.3` | 3.10, 3.11, 3.12, 3.13, 3.14 |
Expand Down
48 changes: 48 additions & 0 deletions examples/anthropic_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# /// script
# requires-python = ">=3.10"
# dependencies = ["wildedge-sdk", "anthropic"]
#
# [tool.uv.sources]
# wildedge-sdk = { path = "..", editable = true }
# ///
"""Anthropic integration example.

WildEdge patches anthropic.Anthropic (and AsyncAnthropic) at instrumentation
time, so inference tracking happens automatically for every messages.create call.

Run with: uv run anthropic_example.py
Requires: ANTHROPIC_API_KEY environment variable. Set WILDEDGE_DSN to send events.
"""

import anthropic

import wildedge

client = wildedge.init(
app_version="1.0.0", # uses WILDEDGE_DSN if set; otherwise no-op
integrations="anthropic",
)

anthropic_client = anthropic.Anthropic() # set ANTHROPIC_API_KEY or pass api_key=

prompts = [
"Explain transformer attention in one sentence.",
"What is the capital of Japan?",
"Write a haiku about edge AI.",
]

for prompt in prompts:
stream = anthropic_client.messages.create(
model="claude-haiku-4-5",
max_tokens=256,
messages=[{"role": "user", "content": prompt}],
stream=True,
)
print(f"Q: {prompt}\nA: ", end="", flush=True)
for event in stream:
if event.type == "content_block_delta" and event.delta.type == "text_delta":
print(event.delta.text, end="", flush=True)
print("\n")

client.flush()
print("Done. Events flushed to WildEdge.")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "wildedge-sdk"
version = "0.1.2"
version = "0.1.3"
description = "On-device ML inference monitoring for Python"
readme = "README.md"
requires-python = ">=3.10"
Expand Down
5 changes: 5 additions & 0 deletions scripts/compat_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import sys

MATRIX = {
"anthropic": {
"min": ["anthropic==0.25.0"],
"current": ["anthropic==0.92.0"],
},
"onnx": {
"min": ["onnxruntime==1.18.1", "numpy==1.26.4"],
"current": ["onnxruntime==1.20.1", "numpy==2.1.3"],
Expand Down Expand Up @@ -56,6 +60,7 @@
}

SUPPORTED_PYTHON = {
"anthropic": ["3.10", "3.11", "3.12", "3.13"],
"onnx": ["3.10", "3.11", "3.12", "3.13", "3.14"],
"torch": ["3.10", "3.11", "3.12", "3.13", "3.14"],
"timm": ["3.10", "3.11", "3.12", "3.13", "3.14"],
Expand Down
9 changes: 9 additions & 0 deletions tests/compat/test_anthropic_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from __future__ import annotations

import pytest


def test_anthropic_import_and_instrument(compat_client):
anthropic = pytest.importorskip("anthropic")
assert getattr(anthropic, "__version__", None)
compat_client.instrument("anthropic")
Loading
Loading