5a558eb09e
TypeScript SDK Compatibility V1.x E2E Tests / Select Node version matrix (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / TypeScript SDK Compatibility V1.x E2E Tests Node ${{matrix.node_version}} (push) Has been cancelled
TypeScript SDK E2E Tests / TypeScript SDK E2E Tests Node ${{matrix.node_version}} (push) Has been cancelled
Opik Optimizer - E2E Tests / build-opik (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / build-opik (push) Has been cancelled
Python SDK E2E Tests / Select Python version matrix (push) Has been cancelled
Python SDK E2E Tests / Python SDK E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Python SDK E2E Tests / build-opik (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / Select Python version matrix (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / Python SDK Compatibility V1.x E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / build-opik (push) Has been cancelled
TypeScript SDK E2E Tests / Select Node version matrix (push) Has been cancelled
TypeScript SDK E2E Tests / build-opik (push) Has been cancelled
Opik Optimizer - E2E Tests / Opik Optimizer E2E Tests Python ${{matrix.python_version}} (push) Has been cancelled
Opik Optimizer - E2E Tests / Opik Optimizer Integration Smoke Tests (push) Has been cancelled
🐙 Code Quality / detect (push) Has been cancelled
🐙 Code Quality / lint (${{ matrix.leg.name }}) (push) Has been cancelled
🐙 Code Quality / summary (push) Has been cancelled
TypeScript SDK Library Integration Tests / Check Secrets (push) Has been cancelled
TypeScript SDK Library Integration Tests / opik-vercel (Vercel AI SDK / eve) (push) Has been cancelled
SDK Library Integration Tests Runner / Check Secrets (push) Has been cancelled
SDK Library Integration Tests Runner / Missed OpenAI API Key Warning (push) Has been cancelled
SDK Library Integration Tests Runner / Build (push) Has been cancelled
SDK Library Integration Tests Runner / openai_tests (push) Has been cancelled
SDK Library Integration Tests Runner / langchain_tests (push) Has been cancelled
SDK Library Integration Tests Runner / langchain_legacy_tests (push) Has been cancelled
SDK Library Integration Tests Runner / llama_index_tests (push) Has been cancelled
SDK Library Integration Tests Runner / anthropic_tests (push) Has been cancelled
SDK Library Integration Tests Runner / mistral_tests (push) Has been cancelled
SDK Library Integration Tests Runner / groq_tests (push) Has been cancelled
SDK Library Integration Tests Runner / aisuite_tests (push) Has been cancelled
SDK Library Integration Tests Runner / haystack_tests (push) Has been cancelled
SDK Library Integration Tests Runner / dspy_tests (push) Has been cancelled
SDK Library Integration Tests Runner / crewai_v0_tests (push) Has been cancelled
SDK Library Integration Tests Runner / crewai_v1_tests (push) Has been cancelled
SDK Library Integration Tests Runner / genai_tests (push) Has been cancelled
SDK Library Integration Tests Runner / adk_tests (push) Has been cancelled
SDK Library Integration Tests Runner / adk_legacy_1_3_0_tests (push) Has been cancelled
SDK Library Integration Tests Runner / evaluation_metrics_tests (push) Has been cancelled
SDK Library Integration Tests Runner / bedrock_tests (push) Has been cancelled
SDK Library Integration Tests Runner / litellm_tests (push) Has been cancelled
SDK Library Integration Tests Runner / harbor_tests (push) Has been cancelled
SDK Library Integration Tests Runner / Slack Notification (push) Has been cancelled
Lint Opik Helm Chart / render-equality (push) Has been cancelled
Opik Optimizer - Unit Tests / Opik Optimizer Unit Tests Python ${{matrix.python_version}} (push) Has been cancelled
Python BE E2E Tests / Python BE E2E (push) Has been cancelled
Python Backend Tests / run-python-backend-tests (push) Has been cancelled
Python SDK Unit Tests / Python SDK Unit Tests ${{matrix.python_version}} (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
SDK E2E Libraries Integration Tests / Check Secrets (push) Has been cancelled
SDK E2E Libraries Integration Tests / Missed OpenAI API Key Warning (push) Has been cancelled
SDK E2E Libraries Integration Tests / build-opik (push) Has been cancelled
SDK E2E Libraries Integration Tests / E2E Lib Integration Python ${{matrix.python_version}} (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-gemini) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-langchain) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-openai) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-otel) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-vercel) (push) Has been cancelled
TypeScript SDK Build & Publish / build-and-publish (push) Has been cancelled
TypeScript SDK Unit Tests / Test on Node ${{ matrix.node-version }} (push) Has been cancelled
Backend Tests / discover-tests (push) Has been cancelled
Backend Tests / ${{ matrix.name }} (push) Has been cancelled
Build and Publish SDK / build-and-publish (push) Has been cancelled
Build Opik Docker Images / set-version (push) Has been cancelled
Build Opik Docker Images / build-backend (push) Has been cancelled
Build Opik Docker Images / build-sandbox-executor-python (push) Has been cancelled
Build Opik Docker Images / build-python-backend (push) Has been cancelled
Build Opik Docker Images / build-frontend (push) Has been cancelled
Build Opik Docker Images / create-git-tag (push) Has been cancelled
ClickHouse Migration Cluster Check / validate-clickhouse-migrations (push) Has been cancelled
Docs - Publish / run (push) Has been cancelled
E2E Tests - Post Merge (v2) / 🧪 E2E v2 Tests (${{ github.event.inputs.tier || 't1' }}) (push) Has been cancelled
E2E Tests - Post Merge (v2) / 📢 Slack Notification (push) Has been cancelled
Frontend Unit Tests / Test on Node 20 (push) Has been cancelled
Guardrails E2E Tests / Select Python version matrix (push) Has been cancelled
Guardrails E2E Tests / Guardrails E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Guardrails E2E Tests / 📢 Slack Notification (push) Has been cancelled
Guardrails Backend Unit Tests / Guardrails Backend Unit Tests (push) Has been cancelled
Guardrails Backend Unit Tests / 📢 Slack Notification (push) Has been cancelled
Lint Opik Helm Chart / lint-helm-chart (Helm v3.21.0) (push) Has been cancelled
Lint Opik Helm Chart / lint-helm-chart (Helm v4.2.0) (push) Has been cancelled
Lint Opik Helm Chart / unittest-helm-chart (push) Has been cancelled
132 lines
4.7 KiB
Plaintext
132 lines
4.7 KiB
Plaintext
---
|
|
headline: Python SDK | Opik Documentation
|
|
og:description: Learn how to contribute to the Opik Python SDK, enabling seamless
|
|
integration for developers in their Python applications.
|
|
og:site_name: Opik Documentation
|
|
og:title: Contributing to the Opik Python SDK
|
|
title: Python SDK
|
|
canonical-url: https://www.comet.com/docs/opik/contributing/guides/python-sdk
|
|
---
|
|
|
|
# Contributing to the Opik Python SDK
|
|
|
|
The Opik Python SDK is a key component of our platform, allowing developers to integrate Opik into their Python applications seamlessly. The SDK source code is located in the `sdks/python` directory of the main `comet-ml/opik` repository.
|
|
|
|
<Tip>
|
|
Before you start, please review our general [Contribution Overview](/v1/contributing/overview) and the [Contributor
|
|
License Agreement (CLA)](https://github.com/comet-ml/opik/blob/main/CLA.md).
|
|
</Tip>
|
|
|
|
## Getting Started
|
|
|
|
<Steps>
|
|
### 1. Set up Opik Locally
|
|
To develop and test Python SDK features, you'll need a local Opik instance running:
|
|
|
|
<Tabs>
|
|
<Tab title="Linux/Mac">
|
|
```bash
|
|
# From the root of the repository
|
|
./opik.sh --port-mapping
|
|
|
|
# Configure the Python SDK to point to the local Opik deployment
|
|
opik configure --use_local
|
|
```
|
|
</Tab>
|
|
<Tab title="Windows">
|
|
```powershell
|
|
# From the root of the repository
|
|
.\opik.ps1 --port-mapping
|
|
|
|
# Configure the Python SDK to point to the local Opik deployment
|
|
opik configure --use_local
|
|
```
|
|
</Tab>
|
|
</Tabs>
|
|
|
|
**Note:** The `--port-mapping` flag exposes all service ports (including MySQL on 3306, ClickHouse on 8123, Redis on 6379) which is useful for debugging. The Python SDK routes traffic through the API gateway (nginx) in the frontend service.
|
|
|
|
Your local Opik server will be accessible at `http://localhost:5173`.
|
|
|
|
<Tip title="Windows Users">
|
|
- Ensure the Python `Scripts` directory (e.g., `C:\Users\<name>\AppData\Local\Programs\Python<version>\Scripts\`) is in your system's PATH for the `opik` CLI command to work after installation. Restart your terminal after adding it.
|
|
- Using a Python virtual environment is highly recommended:
|
|
```powershell
|
|
# Create a virtual environment
|
|
py -m venv my-opik-env
|
|
|
|
# Activate it (example path)
|
|
cd my-opik-env\Scripts && .\activate.bat
|
|
|
|
# Install the SDK in editable mode (adjust path to sdks/python from your current location)
|
|
pip install -e ../../sdks/python
|
|
|
|
# Configure the SDK to use your local Opik instance
|
|
opik configure --use_local
|
|
```
|
|
</Tip>
|
|
|
|
### 2. Install SDK for Development
|
|
|
|
Navigate to the `sdks/python` directory (or use the path from your virtual environment setup) and install the SDK in editable mode:
|
|
|
|
```bash
|
|
pip install -e .
|
|
```
|
|
|
|
### 3. Review Coding Guidelines
|
|
|
|
Familiarize yourself with the [coding guidelines for our Python SDK](https://github.com/comet-ml/opik/blob/main/sdks/python/README.md). This will cover style, conventions, and other important aspects.
|
|
|
|
### 4. Implement Your Changes
|
|
|
|
Make your desired code changes, additions, or bug fixes within the `sdks/python` directory.
|
|
|
|
### 5. Test Your Changes
|
|
|
|
Testing is crucial. For most SDK contributions, you should run the unit and the end-to-end (e2e) tests:
|
|
|
|
```bash
|
|
cd sdks/python # Ensure you are in this directory
|
|
|
|
# Install test-specific requirements
|
|
pip install -r tests/test_requirements.txt
|
|
|
|
# Install unit test requirements
|
|
pip install -r tests/unit/test_requirements.txt
|
|
|
|
# Install pre-commit for linting checks (optional but good practice)
|
|
pip install pre-commit
|
|
|
|
# Run unit tests
|
|
python3 -m pytest -vv tests/unit/
|
|
|
|
# Run e2e tests
|
|
python3 -m pytest -vv tests/e2e/
|
|
```
|
|
|
|
If you're making changes to specific integrations (e.g., OpenAI, Anthropic):
|
|
|
|
1. Install the integration-specific requirements: `pip install -r tests/integrations/openai/requirements.txt` (example for OpenAI).
|
|
2. Configure any necessary API keys for the integration as environment variables or per your test setup.
|
|
3. Run the specific integration tests: `python3 -m pytest tests/integrations/openai/` (example for OpenAI).
|
|
|
|
### 6. Run Linters
|
|
|
|
Ensure your code adheres to our linting standards:
|
|
|
|
```bash
|
|
cd "$(git rev-parse --show-toplevel)"
|
|
make precommit
|
|
```
|
|
|
|
### 7. Update Documentation (If Applicable)
|
|
|
|
If your changes impact public-facing methods, parameters, or docstrings, please also update the documentation. Refer to the [Documentation Contribution Guide](/v1/contributing/guides/documentation) for how to update the Python SDK Reference Documentation (Sphinx).
|
|
|
|
### 8. Submit a Pull Request
|
|
|
|
Once all tests and checks pass, and any relevant documentation is updated, commit your changes and open a Pull Request against the `main` branch of the `comet-ml/opik` repository. Clearly describe your changes and link to any relevant issues.
|
|
|
|
</Steps>
|