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.

Before you start, please review our general Contribution Overview and the Contributor License Agreement (CLA).

Getting Started

1

1. Set up Opik Locally

To develop and test Python SDK features, you’ll need a local Opik instance running. You can set this up by following the instructions in the Docker Compose README or by using the helper scripts provided in the root of the repository:

$# From the root of the repository
>./opik.sh
>
># Configure the Python SDK to point to the local Opik deployment
>opik configure --use_local

Your local Opik server will be accessible at http://localhost:5173.

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:
    1# Create a virtual environment
    2py -m venv my-opik-env
    3
    4# Activate it (example path)
    5cd my-opik-env\Scripts && .\activate.bat
    6
    7# Install the SDK in editable mode (adjust path to sdks/python from your current location)
    8pip install -e ../../sdks/python
    9
    10# Configure the SDK to use your local Opik instance
    11opik configure --use_local
2

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:

$pip install -e .
3

3. Review Coding Guidelines

Familiarize yourself with the coding guidelines for our Python SDK. This will cover style, conventions, and other important aspects.

4

4. Implement Your Changes

Make your desired code changes, additions, or bug fixes within the sdks/python directory.

5

5. Test Your Changes

Testing is crucial. For most SDK contributions, you should run the end-to-end (e2e) tests:

$cd sdks/python # Ensure you are in this directory
>
># Install test-specific requirements
>pip install -r tests/test_requirements.txt
>
># Install pre-commit for linting checks (optional but good practice)
>pip install pre-commit
>
># Run e2e tests
>pytest 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: pytest tests/integrations/openai (example for OpenAI).
6

6. Run Linters

Ensure your code adheres to our linting standards:

$cd sdks/python
>pre-commit run --all-files
7

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 for how to update the Python SDK Reference Documentation (Sphinx).

8

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.