langwatch-scenario 0.4.0__py3-none-any.whl → 0.7.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {langwatch_scenario-0.4.0.dist-info → langwatch_scenario-0.7.1.dist-info}/METADATA +210 -86
- langwatch_scenario-0.7.1.dist-info/RECORD +237 -0
- scenario/__init__.py +12 -118
- scenario/_events/__init__.py +64 -0
- scenario/_events/event_bus.py +185 -0
- scenario/_events/event_reporter.py +83 -0
- scenario/_events/events.py +162 -0
- scenario/_events/messages.py +58 -0
- scenario/_events/utils.py +97 -0
- scenario/_generated/langwatch_api_client/README.md +139 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/__init__.py +13 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/__init__.py +1 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/__init__.py +1 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/delete_api_annotations_id.py +155 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/delete_api_prompts_by_id.py +218 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/delete_api_scenario_events.py +183 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/get_api_annotations.py +136 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/get_api_annotations_id.py +155 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/get_api_annotations_trace_id.py +160 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/get_api_dataset_by_slug_or_id.py +229 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/get_api_prompts.py +188 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/get_api_prompts_by_id.py +218 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/get_api_prompts_by_id_versions.py +218 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/get_api_trace_id.py +155 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/patch_api_annotations_id.py +178 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/post_api_annotations_trace_id.py +178 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/post_api_dataset_by_slug_entries.py +108 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/post_api_prompts.py +187 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/post_api_prompts_by_id_versions.py +241 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/post_api_scenario_events.py +229 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/post_api_trace_id_share.py +155 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/post_api_trace_id_unshare.py +155 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/put_api_prompts_by_id.py +241 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/traces/__init__.py +1 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/api/traces/post_api_trace_search.py +168 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/client.py +268 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/errors.py +16 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/__init__.py +455 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/annotation.py +131 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/dataset_post_entries.py +74 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/dataset_post_entries_entries_item.py +44 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/delete_api_annotations_id_response_200.py +68 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/delete_api_prompts_by_id_response_200.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/delete_api_prompts_by_id_response_400.py +61 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/delete_api_prompts_by_id_response_400_error.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/delete_api_prompts_by_id_response_401.py +61 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/delete_api_prompts_by_id_response_401_error.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/delete_api_prompts_by_id_response_404.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/delete_api_prompts_by_id_response_500.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/delete_api_scenario_events_response_200.py +81 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/delete_api_scenario_events_response_400.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/delete_api_scenario_events_response_401.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/delete_api_scenario_events_response_500.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/error.py +67 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/evaluation.py +164 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/evaluation_timestamps.py +68 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_dataset_by_slug_or_id_response_200.py +75 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_dataset_by_slug_or_id_response_200_data_item.py +109 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_dataset_by_slug_or_id_response_200_data_item_entry.py +44 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_dataset_by_slug_or_id_response_400.py +78 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_dataset_by_slug_or_id_response_401.py +78 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_dataset_by_slug_or_id_response_404.py +78 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_dataset_by_slug_or_id_response_422.py +67 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_dataset_by_slug_or_id_response_500.py +78 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_response_200.py +172 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_response_200_messages_item.py +69 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_response_200_messages_item_role.py +10 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_response_200_response_format_type_0.py +81 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_response_200_response_format_type_0_json_schema.py +77 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_response_200_response_format_type_0_json_schema_schema.py +44 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_response_200_response_format_type_0_type.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_response_400.py +61 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_response_400_error.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_response_401.py +61 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_response_401_error.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_response_404.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_response_500.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_200.py +155 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_200_config_data.py +204 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_200_config_data_demonstrations.py +101 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_200_config_data_demonstrations_columns_item.py +79 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_200_config_data_demonstrations_columns_item_type.py +18 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_200_config_data_demonstrations_rows_item.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_200_config_data_inputs_item.py +71 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_200_config_data_inputs_item_type.py +16 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_200_config_data_messages_item.py +71 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_200_config_data_messages_item_role.py +10 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_200_config_data_outputs_item.py +98 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_200_config_data_outputs_item_json_schema.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_200_config_data_outputs_item_type.py +11 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_200_config_data_prompting_technique.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_400.py +61 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_400_error.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_401.py +61 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_401_error.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_404.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_by_id_versions_response_500.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_response_200_item.py +172 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_response_200_item_messages_item.py +69 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_response_200_item_messages_item_role.py +10 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_response_200_item_response_format_type_0.py +81 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_response_200_item_response_format_type_0_json_schema.py +77 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_response_200_item_response_format_type_0_json_schema_schema.py +44 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_response_200_item_response_format_type_0_type.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_response_400.py +61 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_response_400_error.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_response_401.py +61 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_response_401_error.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_prompts_response_500.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200.py +249 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_error_type_0.py +79 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_evaluations_item.py +152 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_evaluations_item_error.py +79 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_evaluations_item_timestamps.py +68 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_input.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_metadata.py +68 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_metrics.py +95 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_output.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_spans_item.py +271 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_spans_item_error_type_0.py +79 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_spans_item_input.py +90 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_spans_item_input_value_item.py +69 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_spans_item_metrics.py +77 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_spans_item_output.py +89 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_spans_item_output_value_item.py +68 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_spans_item_params.py +68 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_spans_item_timestamps.py +95 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/get_api_trace_id_response_200_timestamps.py +77 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/input_.py +68 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/metadata.py +68 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/metrics.py +115 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/output.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/pagination.py +68 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/patch_api_annotations_id_body.py +77 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/patch_api_annotations_id_response_200.py +68 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_annotations_trace_id_body.py +77 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_body.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_body.py +147 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_body_config_data.py +207 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_body_config_data_demonstrations.py +106 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_body_config_data_demonstrations_columns_item.py +79 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_body_config_data_demonstrations_columns_item_type.py +18 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_body_config_data_demonstrations_rows_item.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_body_config_data_inputs_item.py +71 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_body_config_data_inputs_item_type.py +16 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_body_config_data_messages_item.py +71 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_body_config_data_messages_item_role.py +10 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_body_config_data_outputs_item.py +98 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_body_config_data_outputs_item_json_schema.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_body_config_data_outputs_item_type.py +11 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_body_config_data_prompting_technique.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_200.py +155 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_200_config_data.py +206 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_200_config_data_demonstrations.py +101 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_200_config_data_demonstrations_columns_item.py +79 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_200_config_data_demonstrations_columns_item_type.py +18 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_200_config_data_demonstrations_rows_item.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_200_config_data_inputs_item.py +71 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_200_config_data_inputs_item_type.py +16 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_200_config_data_messages_item.py +71 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_200_config_data_messages_item_role.py +10 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_200_config_data_outputs_item.py +98 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_200_config_data_outputs_item_json_schema.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_200_config_data_outputs_item_type.py +11 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_200_config_data_prompting_technique.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_400.py +61 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_400_error.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_401.py +61 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_401_error.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_404.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_by_id_versions_response_500.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_response_200.py +172 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_response_200_messages_item.py +69 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_response_200_messages_item_role.py +10 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_response_200_response_format_type_0.py +81 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_response_200_response_format_type_0_json_schema.py +77 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_response_200_response_format_type_0_json_schema_schema.py +44 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_response_200_response_format_type_0_type.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_response_400.py +61 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_response_400_error.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_response_401.py +61 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_response_401_error.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_prompts_response_500.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_body_type_0.py +127 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_body_type_0_metadata.py +68 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_body_type_1.py +164 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_body_type_1_results_type_0.py +98 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_body_type_1_results_type_0_verdict.py +10 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_body_type_1_status.py +13 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_body_type_2.py +245 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_body_type_2_messages_item_type_0.py +88 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_body_type_2_messages_item_type_1.py +88 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_body_type_2_messages_item_type_2.py +120 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_body_type_2_messages_item_type_2_tool_calls_item.py +87 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_body_type_2_messages_item_type_2_tool_calls_item_function.py +67 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_body_type_2_messages_item_type_3.py +88 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_body_type_2_messages_item_type_4.py +85 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_response_201.py +81 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_response_400.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_response_401.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_scenario_events_response_500.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_trace_id_share_response_200.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/post_api_trace_id_unshare_response_200.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/put_api_prompts_by_id_body.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/put_api_prompts_by_id_response_200.py +75 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/put_api_prompts_by_id_response_400.py +61 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/put_api_prompts_by_id_response_400_error.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/put_api_prompts_by_id_response_401.py +61 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/put_api_prompts_by_id_response_401_error.py +8 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/put_api_prompts_by_id_response_404.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/put_api_prompts_by_id_response_500.py +59 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/search_request.py +133 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/search_request_filters.py +51 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/search_response.py +93 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/timestamps.py +77 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/models/trace.py +225 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/py.typed +1 -0
- scenario/_generated/langwatch_api_client/lang_watch_api_client/types.py +46 -0
- scenario/_generated/langwatch_api_client/pyproject.toml +27 -0
- scenario/_utils/__init__.py +32 -0
- scenario/_utils/ids.py +58 -0
- scenario/_utils/message_conversion.py +103 -0
- scenario/{utils.py → _utils/utils.py} +21 -110
- scenario/agent_adapter.py +8 -4
- scenario/cache.py +4 -3
- scenario/config.py +7 -5
- scenario/judge_agent.py +13 -29
- scenario/pytest_plugin.py +6 -51
- scenario/scenario_executor.py +372 -215
- scenario/scenario_state.py +6 -6
- scenario/script.py +9 -9
- scenario/types.py +15 -8
- scenario/user_simulator_agent.py +4 -11
- langwatch_scenario-0.4.0.dist-info/RECORD +0 -18
- {langwatch_scenario-0.4.0.dist-info → langwatch_scenario-0.7.1.dist-info}/WHEEL +0 -0
- {langwatch_scenario-0.4.0.dist-info → langwatch_scenario-0.7.1.dist-info}/entry_points.txt +0 -0
- {langwatch_scenario-0.4.0.dist-info → langwatch_scenario-0.7.1.dist-info}/top_level.txt +0 -0
- /scenario/{error_messages.py → _error_messages.py} +0 -0
scenario/_generated/langwatch_api_client/lang_watch_api_client/api/default/put_api_prompts_by_id.py
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
from http import HTTPStatus
|
2
|
+
from typing import Any, Optional, Union
|
3
|
+
|
4
|
+
import httpx
|
5
|
+
|
6
|
+
from ... import errors
|
7
|
+
from ...client import AuthenticatedClient, Client
|
8
|
+
from ...models.put_api_prompts_by_id_body import PutApiPromptsByIdBody
|
9
|
+
from ...models.put_api_prompts_by_id_response_200 import PutApiPromptsByIdResponse200
|
10
|
+
from ...models.put_api_prompts_by_id_response_400 import PutApiPromptsByIdResponse400
|
11
|
+
from ...models.put_api_prompts_by_id_response_401 import PutApiPromptsByIdResponse401
|
12
|
+
from ...models.put_api_prompts_by_id_response_404 import PutApiPromptsByIdResponse404
|
13
|
+
from ...models.put_api_prompts_by_id_response_500 import PutApiPromptsByIdResponse500
|
14
|
+
from ...types import Response
|
15
|
+
|
16
|
+
|
17
|
+
def _get_kwargs(
|
18
|
+
id: str,
|
19
|
+
*,
|
20
|
+
body: PutApiPromptsByIdBody,
|
21
|
+
) -> dict[str, Any]:
|
22
|
+
headers: dict[str, Any] = {}
|
23
|
+
|
24
|
+
_kwargs: dict[str, Any] = {
|
25
|
+
"method": "put",
|
26
|
+
"url": f"/api/prompts/{id}",
|
27
|
+
}
|
28
|
+
|
29
|
+
_body = body.to_dict()
|
30
|
+
|
31
|
+
_kwargs["json"] = _body
|
32
|
+
headers["Content-Type"] = "application/json"
|
33
|
+
|
34
|
+
_kwargs["headers"] = headers
|
35
|
+
return _kwargs
|
36
|
+
|
37
|
+
|
38
|
+
def _parse_response(
|
39
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
40
|
+
) -> Optional[
|
41
|
+
Union[
|
42
|
+
PutApiPromptsByIdResponse200,
|
43
|
+
PutApiPromptsByIdResponse400,
|
44
|
+
PutApiPromptsByIdResponse401,
|
45
|
+
PutApiPromptsByIdResponse404,
|
46
|
+
PutApiPromptsByIdResponse500,
|
47
|
+
]
|
48
|
+
]:
|
49
|
+
if response.status_code == 200:
|
50
|
+
response_200 = PutApiPromptsByIdResponse200.from_dict(response.json())
|
51
|
+
|
52
|
+
return response_200
|
53
|
+
if response.status_code == 400:
|
54
|
+
response_400 = PutApiPromptsByIdResponse400.from_dict(response.json())
|
55
|
+
|
56
|
+
return response_400
|
57
|
+
if response.status_code == 401:
|
58
|
+
response_401 = PutApiPromptsByIdResponse401.from_dict(response.json())
|
59
|
+
|
60
|
+
return response_401
|
61
|
+
if response.status_code == 404:
|
62
|
+
response_404 = PutApiPromptsByIdResponse404.from_dict(response.json())
|
63
|
+
|
64
|
+
return response_404
|
65
|
+
if response.status_code == 500:
|
66
|
+
response_500 = PutApiPromptsByIdResponse500.from_dict(response.json())
|
67
|
+
|
68
|
+
return response_500
|
69
|
+
if client.raise_on_unexpected_status:
|
70
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
71
|
+
else:
|
72
|
+
return None
|
73
|
+
|
74
|
+
|
75
|
+
def _build_response(
|
76
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
77
|
+
) -> Response[
|
78
|
+
Union[
|
79
|
+
PutApiPromptsByIdResponse200,
|
80
|
+
PutApiPromptsByIdResponse400,
|
81
|
+
PutApiPromptsByIdResponse401,
|
82
|
+
PutApiPromptsByIdResponse404,
|
83
|
+
PutApiPromptsByIdResponse500,
|
84
|
+
]
|
85
|
+
]:
|
86
|
+
return Response(
|
87
|
+
status_code=HTTPStatus(response.status_code),
|
88
|
+
content=response.content,
|
89
|
+
headers=response.headers,
|
90
|
+
parsed=_parse_response(client=client, response=response),
|
91
|
+
)
|
92
|
+
|
93
|
+
|
94
|
+
def sync_detailed(
|
95
|
+
id: str,
|
96
|
+
*,
|
97
|
+
client: Union[AuthenticatedClient, Client],
|
98
|
+
body: PutApiPromptsByIdBody,
|
99
|
+
) -> Response[
|
100
|
+
Union[
|
101
|
+
PutApiPromptsByIdResponse200,
|
102
|
+
PutApiPromptsByIdResponse400,
|
103
|
+
PutApiPromptsByIdResponse401,
|
104
|
+
PutApiPromptsByIdResponse404,
|
105
|
+
PutApiPromptsByIdResponse500,
|
106
|
+
]
|
107
|
+
]:
|
108
|
+
"""Update a prompt
|
109
|
+
|
110
|
+
Args:
|
111
|
+
id (str):
|
112
|
+
body (PutApiPromptsByIdBody):
|
113
|
+
|
114
|
+
Raises:
|
115
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
116
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
117
|
+
|
118
|
+
Returns:
|
119
|
+
Response[Union[PutApiPromptsByIdResponse200, PutApiPromptsByIdResponse400, PutApiPromptsByIdResponse401, PutApiPromptsByIdResponse404, PutApiPromptsByIdResponse500]]
|
120
|
+
"""
|
121
|
+
|
122
|
+
kwargs = _get_kwargs(
|
123
|
+
id=id,
|
124
|
+
body=body,
|
125
|
+
)
|
126
|
+
|
127
|
+
response = client.get_httpx_client().request(
|
128
|
+
**kwargs,
|
129
|
+
)
|
130
|
+
|
131
|
+
return _build_response(client=client, response=response)
|
132
|
+
|
133
|
+
|
134
|
+
def sync(
|
135
|
+
id: str,
|
136
|
+
*,
|
137
|
+
client: Union[AuthenticatedClient, Client],
|
138
|
+
body: PutApiPromptsByIdBody,
|
139
|
+
) -> Optional[
|
140
|
+
Union[
|
141
|
+
PutApiPromptsByIdResponse200,
|
142
|
+
PutApiPromptsByIdResponse400,
|
143
|
+
PutApiPromptsByIdResponse401,
|
144
|
+
PutApiPromptsByIdResponse404,
|
145
|
+
PutApiPromptsByIdResponse500,
|
146
|
+
]
|
147
|
+
]:
|
148
|
+
"""Update a prompt
|
149
|
+
|
150
|
+
Args:
|
151
|
+
id (str):
|
152
|
+
body (PutApiPromptsByIdBody):
|
153
|
+
|
154
|
+
Raises:
|
155
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
156
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
157
|
+
|
158
|
+
Returns:
|
159
|
+
Union[PutApiPromptsByIdResponse200, PutApiPromptsByIdResponse400, PutApiPromptsByIdResponse401, PutApiPromptsByIdResponse404, PutApiPromptsByIdResponse500]
|
160
|
+
"""
|
161
|
+
|
162
|
+
return sync_detailed(
|
163
|
+
id=id,
|
164
|
+
client=client,
|
165
|
+
body=body,
|
166
|
+
).parsed
|
167
|
+
|
168
|
+
|
169
|
+
async def asyncio_detailed(
|
170
|
+
id: str,
|
171
|
+
*,
|
172
|
+
client: Union[AuthenticatedClient, Client],
|
173
|
+
body: PutApiPromptsByIdBody,
|
174
|
+
) -> Response[
|
175
|
+
Union[
|
176
|
+
PutApiPromptsByIdResponse200,
|
177
|
+
PutApiPromptsByIdResponse400,
|
178
|
+
PutApiPromptsByIdResponse401,
|
179
|
+
PutApiPromptsByIdResponse404,
|
180
|
+
PutApiPromptsByIdResponse500,
|
181
|
+
]
|
182
|
+
]:
|
183
|
+
"""Update a prompt
|
184
|
+
|
185
|
+
Args:
|
186
|
+
id (str):
|
187
|
+
body (PutApiPromptsByIdBody):
|
188
|
+
|
189
|
+
Raises:
|
190
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
191
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
192
|
+
|
193
|
+
Returns:
|
194
|
+
Response[Union[PutApiPromptsByIdResponse200, PutApiPromptsByIdResponse400, PutApiPromptsByIdResponse401, PutApiPromptsByIdResponse404, PutApiPromptsByIdResponse500]]
|
195
|
+
"""
|
196
|
+
|
197
|
+
kwargs = _get_kwargs(
|
198
|
+
id=id,
|
199
|
+
body=body,
|
200
|
+
)
|
201
|
+
|
202
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
203
|
+
|
204
|
+
return _build_response(client=client, response=response)
|
205
|
+
|
206
|
+
|
207
|
+
async def asyncio(
|
208
|
+
id: str,
|
209
|
+
*,
|
210
|
+
client: Union[AuthenticatedClient, Client],
|
211
|
+
body: PutApiPromptsByIdBody,
|
212
|
+
) -> Optional[
|
213
|
+
Union[
|
214
|
+
PutApiPromptsByIdResponse200,
|
215
|
+
PutApiPromptsByIdResponse400,
|
216
|
+
PutApiPromptsByIdResponse401,
|
217
|
+
PutApiPromptsByIdResponse404,
|
218
|
+
PutApiPromptsByIdResponse500,
|
219
|
+
]
|
220
|
+
]:
|
221
|
+
"""Update a prompt
|
222
|
+
|
223
|
+
Args:
|
224
|
+
id (str):
|
225
|
+
body (PutApiPromptsByIdBody):
|
226
|
+
|
227
|
+
Raises:
|
228
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
229
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
230
|
+
|
231
|
+
Returns:
|
232
|
+
Union[PutApiPromptsByIdResponse200, PutApiPromptsByIdResponse400, PutApiPromptsByIdResponse401, PutApiPromptsByIdResponse404, PutApiPromptsByIdResponse500]
|
233
|
+
"""
|
234
|
+
|
235
|
+
return (
|
236
|
+
await asyncio_detailed(
|
237
|
+
id=id,
|
238
|
+
client=client,
|
239
|
+
body=body,
|
240
|
+
)
|
241
|
+
).parsed
|
@@ -0,0 +1 @@
|
|
1
|
+
"""Contains endpoint functions for accessing the API"""
|
scenario/_generated/langwatch_api_client/lang_watch_api_client/api/traces/post_api_trace_search.py
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
from http import HTTPStatus
|
2
|
+
from typing import Any, Optional, Union
|
3
|
+
|
4
|
+
import httpx
|
5
|
+
|
6
|
+
from ... import errors
|
7
|
+
from ...client import AuthenticatedClient, Client
|
8
|
+
from ...models.search_request import SearchRequest
|
9
|
+
from ...models.search_response import SearchResponse
|
10
|
+
from ...types import Response
|
11
|
+
|
12
|
+
|
13
|
+
def _get_kwargs(
|
14
|
+
*,
|
15
|
+
body: SearchRequest,
|
16
|
+
) -> dict[str, Any]:
|
17
|
+
headers: dict[str, Any] = {}
|
18
|
+
|
19
|
+
_kwargs: dict[str, Any] = {
|
20
|
+
"method": "post",
|
21
|
+
"url": "/api/trace/search",
|
22
|
+
}
|
23
|
+
|
24
|
+
_body = body.to_dict()
|
25
|
+
|
26
|
+
_kwargs["json"] = _body
|
27
|
+
headers["Content-Type"] = "application/json"
|
28
|
+
|
29
|
+
_kwargs["headers"] = headers
|
30
|
+
return _kwargs
|
31
|
+
|
32
|
+
|
33
|
+
def _parse_response(
|
34
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
35
|
+
) -> Optional[SearchResponse]:
|
36
|
+
if response.status_code == 200:
|
37
|
+
response_200 = SearchResponse.from_dict(response.json())
|
38
|
+
|
39
|
+
return response_200
|
40
|
+
if client.raise_on_unexpected_status:
|
41
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
42
|
+
else:
|
43
|
+
return None
|
44
|
+
|
45
|
+
|
46
|
+
def _build_response(
|
47
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
48
|
+
) -> Response[SearchResponse]:
|
49
|
+
return Response(
|
50
|
+
status_code=HTTPStatus(response.status_code),
|
51
|
+
content=response.content,
|
52
|
+
headers=response.headers,
|
53
|
+
parsed=_parse_response(client=client, response=response),
|
54
|
+
)
|
55
|
+
|
56
|
+
|
57
|
+
def sync_detailed(
|
58
|
+
*,
|
59
|
+
client: Union[AuthenticatedClient, Client],
|
60
|
+
body: SearchRequest,
|
61
|
+
) -> Response[SearchResponse]:
|
62
|
+
"""Search traces
|
63
|
+
|
64
|
+
Search for traces based on given criteria
|
65
|
+
|
66
|
+
Args:
|
67
|
+
body (SearchRequest):
|
68
|
+
|
69
|
+
Raises:
|
70
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
71
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
72
|
+
|
73
|
+
Returns:
|
74
|
+
Response[SearchResponse]
|
75
|
+
"""
|
76
|
+
|
77
|
+
kwargs = _get_kwargs(
|
78
|
+
body=body,
|
79
|
+
)
|
80
|
+
|
81
|
+
response = client.get_httpx_client().request(
|
82
|
+
**kwargs,
|
83
|
+
)
|
84
|
+
|
85
|
+
return _build_response(client=client, response=response)
|
86
|
+
|
87
|
+
|
88
|
+
def sync(
|
89
|
+
*,
|
90
|
+
client: Union[AuthenticatedClient, Client],
|
91
|
+
body: SearchRequest,
|
92
|
+
) -> Optional[SearchResponse]:
|
93
|
+
"""Search traces
|
94
|
+
|
95
|
+
Search for traces based on given criteria
|
96
|
+
|
97
|
+
Args:
|
98
|
+
body (SearchRequest):
|
99
|
+
|
100
|
+
Raises:
|
101
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
102
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
103
|
+
|
104
|
+
Returns:
|
105
|
+
SearchResponse
|
106
|
+
"""
|
107
|
+
|
108
|
+
return sync_detailed(
|
109
|
+
client=client,
|
110
|
+
body=body,
|
111
|
+
).parsed
|
112
|
+
|
113
|
+
|
114
|
+
async def asyncio_detailed(
|
115
|
+
*,
|
116
|
+
client: Union[AuthenticatedClient, Client],
|
117
|
+
body: SearchRequest,
|
118
|
+
) -> Response[SearchResponse]:
|
119
|
+
"""Search traces
|
120
|
+
|
121
|
+
Search for traces based on given criteria
|
122
|
+
|
123
|
+
Args:
|
124
|
+
body (SearchRequest):
|
125
|
+
|
126
|
+
Raises:
|
127
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
128
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
129
|
+
|
130
|
+
Returns:
|
131
|
+
Response[SearchResponse]
|
132
|
+
"""
|
133
|
+
|
134
|
+
kwargs = _get_kwargs(
|
135
|
+
body=body,
|
136
|
+
)
|
137
|
+
|
138
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
139
|
+
|
140
|
+
return _build_response(client=client, response=response)
|
141
|
+
|
142
|
+
|
143
|
+
async def asyncio(
|
144
|
+
*,
|
145
|
+
client: Union[AuthenticatedClient, Client],
|
146
|
+
body: SearchRequest,
|
147
|
+
) -> Optional[SearchResponse]:
|
148
|
+
"""Search traces
|
149
|
+
|
150
|
+
Search for traces based on given criteria
|
151
|
+
|
152
|
+
Args:
|
153
|
+
body (SearchRequest):
|
154
|
+
|
155
|
+
Raises:
|
156
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
157
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
158
|
+
|
159
|
+
Returns:
|
160
|
+
SearchResponse
|
161
|
+
"""
|
162
|
+
|
163
|
+
return (
|
164
|
+
await asyncio_detailed(
|
165
|
+
client=client,
|
166
|
+
body=body,
|
167
|
+
)
|
168
|
+
).parsed
|
@@ -0,0 +1,268 @@
|
|
1
|
+
import ssl
|
2
|
+
from typing import Any, Optional, Union
|
3
|
+
|
4
|
+
import httpx
|
5
|
+
from attrs import define, evolve, field
|
6
|
+
|
7
|
+
|
8
|
+
@define
|
9
|
+
class Client:
|
10
|
+
"""A class for keeping track of data related to the API
|
11
|
+
|
12
|
+
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
|
13
|
+
|
14
|
+
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
|
15
|
+
|
16
|
+
``cookies``: A dictionary of cookies to be sent with every request
|
17
|
+
|
18
|
+
``headers``: A dictionary of headers to be sent with every request
|
19
|
+
|
20
|
+
``timeout``: The maximum amount of a time a request can take. API functions will raise
|
21
|
+
httpx.TimeoutException if this is exceeded.
|
22
|
+
|
23
|
+
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
|
24
|
+
but can be set to False for testing purposes.
|
25
|
+
|
26
|
+
``follow_redirects``: Whether or not to follow redirects. Default value is False.
|
27
|
+
|
28
|
+
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
|
29
|
+
|
30
|
+
|
31
|
+
Attributes:
|
32
|
+
raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
|
33
|
+
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
|
34
|
+
argument to the constructor.
|
35
|
+
"""
|
36
|
+
|
37
|
+
raise_on_unexpected_status: bool = field(default=False, kw_only=True)
|
38
|
+
_base_url: str = field(alias="base_url")
|
39
|
+
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
40
|
+
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
41
|
+
_timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout")
|
42
|
+
_verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl")
|
43
|
+
_follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
|
44
|
+
_httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
|
45
|
+
_client: Optional[httpx.Client] = field(default=None, init=False)
|
46
|
+
_async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
|
47
|
+
|
48
|
+
def with_headers(self, headers: dict[str, str]) -> "Client":
|
49
|
+
"""Get a new client matching this one with additional headers"""
|
50
|
+
if self._client is not None:
|
51
|
+
self._client.headers.update(headers)
|
52
|
+
if self._async_client is not None:
|
53
|
+
self._async_client.headers.update(headers)
|
54
|
+
return evolve(self, headers={**self._headers, **headers})
|
55
|
+
|
56
|
+
def with_cookies(self, cookies: dict[str, str]) -> "Client":
|
57
|
+
"""Get a new client matching this one with additional cookies"""
|
58
|
+
if self._client is not None:
|
59
|
+
self._client.cookies.update(cookies)
|
60
|
+
if self._async_client is not None:
|
61
|
+
self._async_client.cookies.update(cookies)
|
62
|
+
return evolve(self, cookies={**self._cookies, **cookies})
|
63
|
+
|
64
|
+
def with_timeout(self, timeout: httpx.Timeout) -> "Client":
|
65
|
+
"""Get a new client matching this one with a new timeout (in seconds)"""
|
66
|
+
if self._client is not None:
|
67
|
+
self._client.timeout = timeout
|
68
|
+
if self._async_client is not None:
|
69
|
+
self._async_client.timeout = timeout
|
70
|
+
return evolve(self, timeout=timeout)
|
71
|
+
|
72
|
+
def set_httpx_client(self, client: httpx.Client) -> "Client":
|
73
|
+
"""Manually set the underlying httpx.Client
|
74
|
+
|
75
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
76
|
+
"""
|
77
|
+
self._client = client
|
78
|
+
return self
|
79
|
+
|
80
|
+
def get_httpx_client(self) -> httpx.Client:
|
81
|
+
"""Get the underlying httpx.Client, constructing a new one if not previously set"""
|
82
|
+
if self._client is None:
|
83
|
+
self._client = httpx.Client(
|
84
|
+
base_url=self._base_url,
|
85
|
+
cookies=self._cookies,
|
86
|
+
headers=self._headers,
|
87
|
+
timeout=self._timeout,
|
88
|
+
verify=self._verify_ssl,
|
89
|
+
follow_redirects=self._follow_redirects,
|
90
|
+
**self._httpx_args,
|
91
|
+
)
|
92
|
+
return self._client
|
93
|
+
|
94
|
+
def __enter__(self) -> "Client":
|
95
|
+
"""Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
|
96
|
+
self.get_httpx_client().__enter__()
|
97
|
+
return self
|
98
|
+
|
99
|
+
def __exit__(self, *args: Any, **kwargs: Any) -> None:
|
100
|
+
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
|
101
|
+
self.get_httpx_client().__exit__(*args, **kwargs)
|
102
|
+
|
103
|
+
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client":
|
104
|
+
"""Manually the underlying httpx.AsyncClient
|
105
|
+
|
106
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
107
|
+
"""
|
108
|
+
self._async_client = async_client
|
109
|
+
return self
|
110
|
+
|
111
|
+
def get_async_httpx_client(self) -> httpx.AsyncClient:
|
112
|
+
"""Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
|
113
|
+
if self._async_client is None:
|
114
|
+
self._async_client = httpx.AsyncClient(
|
115
|
+
base_url=self._base_url,
|
116
|
+
cookies=self._cookies,
|
117
|
+
headers=self._headers,
|
118
|
+
timeout=self._timeout,
|
119
|
+
verify=self._verify_ssl,
|
120
|
+
follow_redirects=self._follow_redirects,
|
121
|
+
**self._httpx_args,
|
122
|
+
)
|
123
|
+
return self._async_client
|
124
|
+
|
125
|
+
async def __aenter__(self) -> "Client":
|
126
|
+
"""Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
|
127
|
+
await self.get_async_httpx_client().__aenter__()
|
128
|
+
return self
|
129
|
+
|
130
|
+
async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
|
131
|
+
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
|
132
|
+
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
|
133
|
+
|
134
|
+
|
135
|
+
@define
|
136
|
+
class AuthenticatedClient:
|
137
|
+
"""A Client which has been authenticated for use on secured endpoints
|
138
|
+
|
139
|
+
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
|
140
|
+
|
141
|
+
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
|
142
|
+
|
143
|
+
``cookies``: A dictionary of cookies to be sent with every request
|
144
|
+
|
145
|
+
``headers``: A dictionary of headers to be sent with every request
|
146
|
+
|
147
|
+
``timeout``: The maximum amount of a time a request can take. API functions will raise
|
148
|
+
httpx.TimeoutException if this is exceeded.
|
149
|
+
|
150
|
+
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
|
151
|
+
but can be set to False for testing purposes.
|
152
|
+
|
153
|
+
``follow_redirects``: Whether or not to follow redirects. Default value is False.
|
154
|
+
|
155
|
+
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
|
156
|
+
|
157
|
+
|
158
|
+
Attributes:
|
159
|
+
raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
|
160
|
+
status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
|
161
|
+
argument to the constructor.
|
162
|
+
token: The token to use for authentication
|
163
|
+
prefix: The prefix to use for the Authorization header
|
164
|
+
auth_header_name: The name of the Authorization header
|
165
|
+
"""
|
166
|
+
|
167
|
+
raise_on_unexpected_status: bool = field(default=False, kw_only=True)
|
168
|
+
_base_url: str = field(alias="base_url")
|
169
|
+
_cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
|
170
|
+
_headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
|
171
|
+
_timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout")
|
172
|
+
_verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl")
|
173
|
+
_follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
|
174
|
+
_httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
|
175
|
+
_client: Optional[httpx.Client] = field(default=None, init=False)
|
176
|
+
_async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
|
177
|
+
|
178
|
+
token: str
|
179
|
+
prefix: str = "Bearer"
|
180
|
+
auth_header_name: str = "Authorization"
|
181
|
+
|
182
|
+
def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient":
|
183
|
+
"""Get a new client matching this one with additional headers"""
|
184
|
+
if self._client is not None:
|
185
|
+
self._client.headers.update(headers)
|
186
|
+
if self._async_client is not None:
|
187
|
+
self._async_client.headers.update(headers)
|
188
|
+
return evolve(self, headers={**self._headers, **headers})
|
189
|
+
|
190
|
+
def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient":
|
191
|
+
"""Get a new client matching this one with additional cookies"""
|
192
|
+
if self._client is not None:
|
193
|
+
self._client.cookies.update(cookies)
|
194
|
+
if self._async_client is not None:
|
195
|
+
self._async_client.cookies.update(cookies)
|
196
|
+
return evolve(self, cookies={**self._cookies, **cookies})
|
197
|
+
|
198
|
+
def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient":
|
199
|
+
"""Get a new client matching this one with a new timeout (in seconds)"""
|
200
|
+
if self._client is not None:
|
201
|
+
self._client.timeout = timeout
|
202
|
+
if self._async_client is not None:
|
203
|
+
self._async_client.timeout = timeout
|
204
|
+
return evolve(self, timeout=timeout)
|
205
|
+
|
206
|
+
def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient":
|
207
|
+
"""Manually set the underlying httpx.Client
|
208
|
+
|
209
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
210
|
+
"""
|
211
|
+
self._client = client
|
212
|
+
return self
|
213
|
+
|
214
|
+
def get_httpx_client(self) -> httpx.Client:
|
215
|
+
"""Get the underlying httpx.Client, constructing a new one if not previously set"""
|
216
|
+
if self._client is None:
|
217
|
+
self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
|
218
|
+
self._client = httpx.Client(
|
219
|
+
base_url=self._base_url,
|
220
|
+
cookies=self._cookies,
|
221
|
+
headers=self._headers,
|
222
|
+
timeout=self._timeout,
|
223
|
+
verify=self._verify_ssl,
|
224
|
+
follow_redirects=self._follow_redirects,
|
225
|
+
**self._httpx_args,
|
226
|
+
)
|
227
|
+
return self._client
|
228
|
+
|
229
|
+
def __enter__(self) -> "AuthenticatedClient":
|
230
|
+
"""Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
|
231
|
+
self.get_httpx_client().__enter__()
|
232
|
+
return self
|
233
|
+
|
234
|
+
def __exit__(self, *args: Any, **kwargs: Any) -> None:
|
235
|
+
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
|
236
|
+
self.get_httpx_client().__exit__(*args, **kwargs)
|
237
|
+
|
238
|
+
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "AuthenticatedClient":
|
239
|
+
"""Manually the underlying httpx.AsyncClient
|
240
|
+
|
241
|
+
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
|
242
|
+
"""
|
243
|
+
self._async_client = async_client
|
244
|
+
return self
|
245
|
+
|
246
|
+
def get_async_httpx_client(self) -> httpx.AsyncClient:
|
247
|
+
"""Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
|
248
|
+
if self._async_client is None:
|
249
|
+
self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
|
250
|
+
self._async_client = httpx.AsyncClient(
|
251
|
+
base_url=self._base_url,
|
252
|
+
cookies=self._cookies,
|
253
|
+
headers=self._headers,
|
254
|
+
timeout=self._timeout,
|
255
|
+
verify=self._verify_ssl,
|
256
|
+
follow_redirects=self._follow_redirects,
|
257
|
+
**self._httpx_args,
|
258
|
+
)
|
259
|
+
return self._async_client
|
260
|
+
|
261
|
+
async def __aenter__(self) -> "AuthenticatedClient":
|
262
|
+
"""Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
|
263
|
+
await self.get_async_httpx_client().__aenter__()
|
264
|
+
return self
|
265
|
+
|
266
|
+
async def __aexit__(self, *args: Any, **kwargs: Any) -> None:
|
267
|
+
"""Exit a context manager for underlying httpx.AsyncClient (see httpx docs)"""
|
268
|
+
await self.get_async_httpx_client().__aexit__(*args, **kwargs)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"""Contains shared errors types that can be raised from API functions"""
|
2
|
+
|
3
|
+
|
4
|
+
class UnexpectedStatus(Exception):
|
5
|
+
"""Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True"""
|
6
|
+
|
7
|
+
def __init__(self, status_code: int, content: bytes):
|
8
|
+
self.status_code = status_code
|
9
|
+
self.content = content
|
10
|
+
|
11
|
+
super().__init__(
|
12
|
+
f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}"
|
13
|
+
)
|
14
|
+
|
15
|
+
|
16
|
+
__all__ = ["UnexpectedStatus"]
|