Skip to main content

python-sdk

Python SDK patterns for Opik. Use when working in sdks/python, on SDK APIs, integrations, or message processing.

소스 정보

저장소
comet-ml/opik
최근 소스 활동
2026년 8월 6일 10:05
감지된 SKILL.md 언어
영어
스타
22,503
포크
1,846

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

파일 탐색기
5 개 파일

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
python-sdk
description
Python SDK patterns for Opik. Use when working in sdks/python, on SDK APIs, integrations, or message processing.
# Python SDK ## Three-Layer Architecture ``` Layer 1: Public API (opik.Opik, @opik.track) ↓ Layer 2: Message Processing (queue, batching, retry) ↓ Layer 3: REST Client (OpikApi, HTTP) ``` ## Critical Gotchas ### Flush Before Exit ```python # ✅ REQUIRED for async operations client = opik.Opik() # ... tracing operations ... client.flush() # Must call before exit! ``` ### Async vs Sync Operations **Async (via message queue)** - fire-and-forget: - `trace()`, `span()` - `log_traces_feedback_scores()` - `experiment.insert()` **Sync (blocking, returns data)**: - `create_dataset()`, `get_dataset()` - `create_prompt()`, `get_prompt()` - `search_traces()`, `search_spans()` ### Lazy Imports for Integrations ```python # ✅ GOOD - integration files assume dependency exists import anthropic # Only imported when user uses integration # ❌ BAD - importing at package level from opik.integrations import anthropic # Would fail if not installed ``` ## Integration Patterns ### Pattern Selection ``` Library has callbacks? → Pure Callback (LangChain, LlamaIndex) No callbacks? → Method Patching (OpenAI, Anthropic) Callbacks unreliable? → Hybrid (ADK) ``` ### Method Patching (OpenAI, Anthropic) ```python from opik.integrations.anthropic import track_anthropic client = anthropic.Anthropic() tracked_client = track_anthropic(client) # Wraps methods ``` ### Callback-Based (LangChain) ```python from opik.integrations.langchain import OpikTracer tracer = OpikTracer() chain.invoke(input, config={"callbacks": [tracer]}) ``` ### Decorator-Based ```python @opik.track def my_function(input: str) -> str: # Auto-creates span, captures input/output return process(input) ``` ## Dependency Policy - Avoid adding new dependencies - Use conditional imports for integrations - Keep version bounds flexible: `>=2.0.0,<3.0.0` ## Batching System Messages batch together for efficiency: - Flush triggers: time (1s), size (100), memory (50MB), manual - Reduces HTTP overhead significantly ## API Method Naming ```python # CRUD: create/get/list/update/delete client.create_experiment(name="exp") client.get_dataset(name="ds") # Search for complex queries client.search_spans(project_name="proj") client.search_traces(project_name="proj") # Batch for bulk operations client.batch_create_items(...) ``` ## Reference Files - [testing.md](testing.md) - fake_backend, verifiers, test naming - [error-handling.md](error-handling.md) - Exception hierarchy, MetricComputationError - [good-code.md](good-code.md) - Access control, imports, factories, DI
GitHub에서 보기