Skip to content

[OPIK-4961] [P SDK] [M2] Python SDK: Add project_name parameter to dataset, prompt, and experiment methods#5684

Open
yaricom wants to merge 16 commits intomainfrom
yaricom/OPIK-4961-add-project_name
Open

[OPIK-4961] [P SDK] [M2] Python SDK: Add project_name parameter to dataset, prompt, and experiment methods#5684
yaricom wants to merge 16 commits intomainfrom
yaricom/OPIK-4961-add-project_name

Conversation

@yaricom
Copy link
Contributor

@yaricom yaricom commented Mar 16, 2026

Details

Add project_name parameter to dataset, prompt, and experiment methods in the Python SDK, so that users can work with project-scoped entities.

Change checklist

  • User facing
  • Documentation update

Issues

  • Resolves #
  • OPIK-4961

AI-WATERMARK

AI-WATERMARK: [yes|no]

  • If yes:
    • Tools:
    • Model(s):
    • Scope:
    • Human verification:

Testing

Fixed existing tests

Documentation

Updated docstrings where appropriate

…tests

- Introduced the `project_name` field in the `Dataset` class to associate datasets with specific projects.
- Updated dataset initialization in tests and CLI to include the new `project_name` parameter when creating datasets.
- Added a corresponding `project_name` property with getter functionality in the `Dataset` class.
@yaricom yaricom requested a review from a team as a code owner March 16, 2026 18:02
@github-actions github-actions bot added python Pull requests that update Python code tests Including test files, or tests related like configuration. Python SDK labels Mar 16, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Python SDK Unit Tests Results (Python 3.11)

2 308 tests   2 294 ✅  56s ⏱️
    1 suites      0 💤
    1 files       14 ❌

For more details on these failures, see this check.

Results for commit 2f954f0.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Python SDK Unit Tests Results (Python 3.14)

2 308 tests   2 294 ✅  38s ⏱️
    1 suites      0 💤
    1 files       14 ❌

For more details on these failures, see this check.

Results for commit 2f954f0.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Python SDK Unit Tests Results (Python 3.13)

2 308 tests   2 294 ✅  51s ⏱️
    1 suites      0 💤
    1 files       14 ❌

For more details on these failures, see this check.

Results for commit 2f954f0.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Python SDK Unit Tests Results (Python 3.10)

2 308 tests   2 294 ✅  58s ⏱️
    1 suites      0 💤
    1 files       14 ❌

For more details on these failures, see this check.

Results for commit 2f954f0.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Python SDK Unit Tests Results (Python 3.12)

2 308 tests   2 294 ✅  53s ⏱️
    1 suites      0 💤
    1 files       14 ❌

For more details on these failures, see this check.

Results for commit 2f954f0.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Python SDK E2E Tests Results (Python 3.11)

238 tests   - 8   236 ✅  - 8   10m 31s ⏱️ + 2m 22s
  1 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 2f954f0. ± Comparison against base commit 8e24a51.

This pull request removes 13 and adds 5 tests. Note that renamed tests count towards both.
tests.e2e.test_agent_config ‑ test_agent_config__env_pin__does_not_update_backend__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__env_pin__second_instantiation_uses_backend_value__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__get_blueprint_by_env_tag__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__mask_creation_and_application__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__mask_id_pin__does_not_update_backend__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__multiple_blueprints_each_produce_new_id__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__multiple_mask_updates__each_produce_distinct_mask_id__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__programmatic_create_and_get__happyflow
tests.e2e.test_agent_config ‑ test_agent_config_decorator__all_primitive_and_collection_types__happyflow
tests.e2e.test_agent_config ‑ test_agent_config_decorator__annotated_descriptions__sent_to_backend
…
tests.e2e.test_agent_config ‑ test_mask_overrides_config__happyflow
tests.e2e.test_agent_config ‑ test_multi_class_and_field_removal_dedup__happyflow
tests.e2e.test_agent_config ‑ test_prompt_field_and_trace_metadata__happyflow
tests.e2e.test_agent_config ‑ test_publish_version_and_retrieve__happyflow
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d0780-0ec3-7f4d-9336-962eabbfb8aa]

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Python SDK E2E Tests Results (Python 3.12)

238 tests   - 8   236 ✅  - 8   9m 20s ⏱️ + 1m 23s
  1 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 2f954f0. ± Comparison against base commit 8e24a51.

This pull request removes 13 and adds 5 tests. Note that renamed tests count towards both.
tests.e2e.test_agent_config ‑ test_agent_config__env_pin__does_not_update_backend__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__env_pin__second_instantiation_uses_backend_value__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__get_blueprint_by_env_tag__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__mask_creation_and_application__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__mask_id_pin__does_not_update_backend__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__multiple_blueprints_each_produce_new_id__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__multiple_mask_updates__each_produce_distinct_mask_id__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__programmatic_create_and_get__happyflow
tests.e2e.test_agent_config ‑ test_agent_config_decorator__all_primitive_and_collection_types__happyflow
tests.e2e.test_agent_config ‑ test_agent_config_decorator__annotated_descriptions__sent_to_backend
…
tests.e2e.test_agent_config ‑ test_mask_overrides_config__happyflow
tests.e2e.test_agent_config ‑ test_multi_class_and_field_removal_dedup__happyflow
tests.e2e.test_agent_config ‑ test_prompt_field_and_trace_metadata__happyflow
tests.e2e.test_agent_config ‑ test_publish_version_and_retrieve__happyflow
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d077f-12a1-74e8-a576-2458805fac98]

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Python SDK E2E Tests Results (Python 3.13)

238 tests   - 8   236 ✅  - 8   9m 13s ⏱️ +52s
  1 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 2f954f0. ± Comparison against base commit 8e24a51.

This pull request removes 13 and adds 5 tests. Note that renamed tests count towards both.
tests.e2e.test_agent_config ‑ test_agent_config__env_pin__does_not_update_backend__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__env_pin__second_instantiation_uses_backend_value__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__get_blueprint_by_env_tag__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__mask_creation_and_application__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__mask_id_pin__does_not_update_backend__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__multiple_blueprints_each_produce_new_id__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__multiple_mask_updates__each_produce_distinct_mask_id__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__programmatic_create_and_get__happyflow
tests.e2e.test_agent_config ‑ test_agent_config_decorator__all_primitive_and_collection_types__happyflow
tests.e2e.test_agent_config ‑ test_agent_config_decorator__annotated_descriptions__sent_to_backend
…
tests.e2e.test_agent_config ‑ test_mask_overrides_config__happyflow
tests.e2e.test_agent_config ‑ test_multi_class_and_field_removal_dedup__happyflow
tests.e2e.test_agent_config ‑ test_prompt_field_and_trace_metadata__happyflow
tests.e2e.test_agent_config ‑ test_publish_version_and_retrieve__happyflow
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d077f-5724-7077-aa95-f8cdac33afec]

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Python SDK E2E Tests Results (Python 3.10)

238 tests   - 8   236 ✅  - 8   13m 16s ⏱️ + 4m 56s
  1 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 2f954f0. ± Comparison against base commit 8e24a51.

This pull request removes 13 and adds 5 tests. Note that renamed tests count towards both.
tests.e2e.test_agent_config ‑ test_agent_config__env_pin__does_not_update_backend__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__env_pin__second_instantiation_uses_backend_value__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__get_blueprint_by_env_tag__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__mask_creation_and_application__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__mask_id_pin__does_not_update_backend__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__multiple_blueprints_each_produce_new_id__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__multiple_mask_updates__each_produce_distinct_mask_id__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__programmatic_create_and_get__happyflow
tests.e2e.test_agent_config ‑ test_agent_config_decorator__all_primitive_and_collection_types__happyflow
tests.e2e.test_agent_config ‑ test_agent_config_decorator__annotated_descriptions__sent_to_backend
…
tests.e2e.test_agent_config ‑ test_mask_overrides_config__happyflow
tests.e2e.test_agent_config ‑ test_multi_class_and_field_removal_dedup__happyflow
tests.e2e.test_agent_config ‑ test_prompt_field_and_trace_metadata__happyflow
tests.e2e.test_agent_config ‑ test_publish_version_and_retrieve__happyflow
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d0780-77e2-7a80-bac5-f4e3e73a0489]

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Python SDK E2E Tests Results (Python 3.14)

238 tests   - 8   236 ✅  - 8   8m 42s ⏱️ +38s
  1 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 2f954f0. ± Comparison against base commit 8e24a51.

This pull request removes 13 and adds 5 tests. Note that renamed tests count towards both.
tests.e2e.test_agent_config ‑ test_agent_config__env_pin__does_not_update_backend__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__env_pin__second_instantiation_uses_backend_value__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__get_blueprint_by_env_tag__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__mask_creation_and_application__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__mask_id_pin__does_not_update_backend__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__multiple_blueprints_each_produce_new_id__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__multiple_mask_updates__each_produce_distinct_mask_id__happyflow
tests.e2e.test_agent_config ‑ test_agent_config__programmatic_create_and_get__happyflow
tests.e2e.test_agent_config ‑ test_agent_config_decorator__all_primitive_and_collection_types__happyflow
tests.e2e.test_agent_config ‑ test_agent_config_decorator__annotated_descriptions__sent_to_backend
…
tests.e2e.test_agent_config ‑ test_mask_overrides_config__happyflow
tests.e2e.test_agent_config ‑ test_multi_class_and_field_removal_dedup__happyflow
tests.e2e.test_agent_config ‑ test_prompt_field_and_trace_metadata__happyflow
tests.e2e.test_agent_config ‑ test_publish_version_and_retrieve__happyflow
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d077f-372c-7afa-9b28-eb1c1fe28bf1]

♻️ This comment has been updated with latest results.

andrescrz
andrescrz previously approved these changes Mar 17, 2026
Copy link
Member

@andrescrz andrescrz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, feel free to get another extra review from @alexkuzmik

I guess this still needs Fern to be generated with the latest API changes, hence tests are currently failing.

yaricom added 5 commits March 17, 2026 15:00
…related tests

- Introduced the `project_name` parameter throughout SDK methods for dataset, experiment, evaluation suite, and prompt operations.
- Updated retrieval, creation, and search functions to handle `project_name` correctly.
- Added missing TODO comments to integrate `project_name` with the backend when applicable.
- Synchronized test cases to validate new `project_name` behavior.
@yaricom yaricom requested a review from a team as a code owner March 18, 2026 17:48
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Mar 18, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

🌿 Preview your docs: https://opik-preview-3f5178dd-6e60-46c6-84d9-4dcfe18bf230.docs.buildwithfern.com/docs/opik

No broken links found


📌 Results for commit 8f9c4d4

Comment on lines +218 to 224
def get_dataset_id(
rest_client: OpikApi, dataset_name: str, project_name: Optional[str]
) -> str:
try:
dataset_id = rest_client.datasets.get_dataset_by_identifier(
dataset_name=dataset_name
dataset_name=dataset_name, project_name=project_name
).id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_dataset_id forwards project_name even when None, serialized as null and violating the API schema — should we omit project_name when None and only pass it if present?
rest_client.datasets.get_dataset_by_identifier(id, project_name=project_name) => rest_client.datasets.get_dataset_by_identifier(id, **({'project_name': project_name} if project_name is not None else {}))

Finding type: Type Inconsistency | Severity: 🔴 High


Want Baz to fix this for you? Activate Fixer

Other fix methods

Fix in Cursor

Prompt for AI Agents:

In sdks/python/src/opik/api_objects/dataset/rest_operations.py around lines 218 to 224,
the get_dataset_id function currently calls
rest_client.datasets.get_dataset_by_identifier with project_name even when project_name
is None, causing a null to be sent and the server to reject the request. Change the call
so project_name is only included when it is not None — e.g., build kwargs =
{'dataset_name': dataset_name} and add 'project_name': project_name only if project_name
is not None, or call get_dataset_by_identifier(dataset_name=dataset_name) when
project_name is None. Ensure behavior is unchanged for non-None project_name.

…t methods

- Adjusted method parameter order to make `project_name` optional and consistent with SDK conventions.
- Added `project_name` resolution logic for improved dataset ID retrieval.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

TS SDK E2E Tests - Node 22

0 tests   - 238   0 ✅  - 236   0s ⏱️ - 14m 50s
0 suites  -  25   0 💤  -   2 
0 files    -   1   0 ❌ ±  0 

Results for commit 2f954f0. ± Comparison against base commit 8e24a51.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

TS SDK E2E Tests - Node 20

0 tests   - 238   0 ✅  - 236   0s ⏱️ - 15m 42s
0 suites  -  25   0 💤  -   2 
0 files    -   1   0 ❌ ±  0 

Results for commit 2f954f0. ± Comparison against base commit 8e24a51.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

TS SDK E2E Tests - Node 18

0 tests   - 238   0 ✅  - 236   0s ⏱️ - 14m 38s
0 suites  -  25   0 💤  -   2 
0 files    -   1   0 ❌ ±  0 

Results for commit 2f954f0. ± Comparison against base commit 8e24a51.

♻️ This comment has been updated with latest results.

yaricom added 4 commits March 19, 2026 17:51
…t streaming methods

- Updated `delete_dataset` to accept an optional `project_name` parameter, with default resolution logic.
- Extended dataset streaming and related classes to handle `project_name`.
- Added unit tests to validate `project_name` behavior in `delete_dataset`.
… and search methods

- Updated prompt creation, retrieval, and history functions (`create_prompt`, `get_prompt`, `get_prompt_history`) to include `project_name` handling.
- Extended ChatPrompt methods with `project_name` support.
- Refactored relevant classes and tests to validate `project_name` resolution and propagation.
…relevant tests

- Added `project_name` parameter to chat prompt creation, retrieval, search, and history methods (`create_chat_prompt`, `get_chat_prompt`, `get_chat_prompt_history`, `search_prompts`).
- Updated chat prompt-related tests to validate `project_name` propagation.
- Fixed typos in code examples for `get_prompt_history` and `get_chat_prompt_history`.
yaricom added 2 commits March 19, 2026 19:59
…, and version view methods

- Updated dataset creation, filtering, and version view methods (`create_dataset`, `get_items`, `get_version_view`) to include `project_name` handling.
- Extended E2E tests to validate `project_name` propagation and expected behavior.
- Added assertions for `project_name` comparison in dataset verifications.
…xperiments, and verifiers

- Added `project_name` handling to evaluation suite creation, retrieval, and propagation methods.
- Updated experiments, verifiers, and rest operations to support `project_name`.
- Enhanced E2E tests to validate `project_name` propagation and assertions within evaluation scenarios.
Comment on lines +14 to +18
client: opik_client.Opik, experiment_name: str, project_name: Optional[str] = None
) -> experiment.Experiment:
experiments = client.get_experiments_by_name(name=experiment_name)
experiments = client.get_experiments_by_name(
name=experiment_name, project_name=project_name
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_experiments_data_by_name accepts project_name but doesn't forward it to rest_client.experiments.stream_experiments, should we forward project_name into the stream call or filter results in the experiment REST operations?

Finding type: Breaking Changes | Severity: 🔴 High


Want Baz to fix this for you? Activate Fixer

Other fix methods

Fix in Cursor

Prompt for AI Agents:

In sdks/python/src/opik/evaluation/rest_operations.py around lines 14-18,
get_experiment_with_unique_name now accepts project_name but the underlying experiment
lookup still ignores project scoping. Fix the root cause in the experiment REST
operations: open sdks/python/src/opik/api_objects/experiment/rest_operations.py and
modify the function that implements get_experiments_data_by_name (or the streaming
helper) to either forward the project_name into
rest_client.experiments.stream_experiments (add it as a query/parameter to the API call)
or, if the backend cannot accept it, filter the streamed/parsed experiment results by
project_name before returning. Also review
sdks/python/src/opik/api_objects/opik_client.py (opik_client.get_experiments_by_name) to
ensure it forwards project_name to the experiment REST function. Make sure unit tests
cover the case evaluate(..., project_name=...) so experiments from other projects are
not returned.

rest_client=self._rest_client, name=name, project_name=project_name
)

return experiment.Experiment(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

experiment.Experiment construction is duplicated across getters, including project_name, should we extract _build_experiment_from_public(public_experiment) and reuse it?

Finding type: Code Dedup and Conventions | Severity: 🟢 Low


Want Baz to fix this for you? Activate Fixer

Comment on lines 633 to +640
else:
experiment = rest_operations.get_experiment_with_unique_name(
client=client, experiment_name=experiment_name
client=client, experiment_name=experiment_name, project_name=project_name
)

dataset_ = client.get_dataset(name=experiment.dataset_name)
dataset_ = client.get_dataset(
name=experiment.dataset_name, project_name=project_name
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we default client.get_dataset's project_name to experiment.project_name when project_name isn't provided, e.g. client.get_dataset(..., project_name=project_name or experiment.project_name)?

Finding type: Use stable client APIs | Severity: 🔴 High


Want Baz to fix this for you? Activate Fixer

Other fix methods

Fix in Cursor

Prompt for AI Agents:

In sdks/python/src/opik/evaluation/evaluator.py around lines 633 to 640 inside the
evaluate_experiment function, the code calls
client.get_dataset(name=experiment.dataset_name, project_name=project_name) which can be
None when the caller provided experiment_id. Change this call to default to the
experiment's project when caller did not provide one: use
client.get_dataset(name=experiment.dataset_name, project_name=project_name or
experiment.project_name). Ensure the fallback only applies after experiment is resolved
(i.e., experiment variable is available).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation Python SDK python Pull requests that update Python code tests Including test files, or tests related like configuration. TypeScript SDK typescript *.ts *.tsx work-in-progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants