dbnl

close_run

dbnl.close_run(*, run: Run, wait_for_close: bool = True)None

Mark the specified dbnl Run status as closed. A closed run is finalized and considered complete. Once a Run is marked as closed, it can no longer be used for reporting Results.

Note that the Run will not be closed immediately. It will transition into a closing state and will be closed in the background. If wait_for_close is set to True, the function will block for up to 3 minutes until the Run is closed.

  • Parameters:

    • run – The Run to be closed

    • wait_for_close – If True, the function will block for up to 3 minutes until the Run is closed, defaults to True

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

    • DBNLError – Run did not close after waiting for 3 minutes

IMPORTANT

A run must be closed for uploaded results to be shown on the UI.

copy_project

dbnl.copy_project(*, project: Project, name: str, description: str | None = None) → Project

Copy a Project; a convenience method wrapping exporting and importing a project with a new name and description

  • Parameters:

    • project – The project to copy

    • name – A name for the new Project

    • description – An optional description for the new Project. Description is limited to 255 characters.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

    • DBNLConflictingProjectError – Project with the same name already exists

  • Returns: The newly created Project

Examples:

create_metric

Create a new Metric

  • Parameters:

    • project – The Project to create the Metric for

    • name – Name for the Metric

    • expression_template – Expression template string e.g. token_count({RUN}.question)

    • description – Optional description of what computation the metric is performing

    • greater_is_better – Flag indicating whether greater values are semantically ‘better’ than lesser values

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

  • Returns: Created Metric

create_project

Create a new Project

  • Parameters:

    • name – Name for the Project

    • description – Description for the Project, defaults to None. Description is limited to 255 characters.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLAPIValidationError – dbnl API failed to validate the request

    • DBNLConflictingProjectError – Project with the same name already exists

  • Returns: Project

Examples:

create_run

Create a new Run

  • Parameters:

    • project – The Project this Run is associated with.

    • run_schema – The schema for data that will be associated with this run. dbnl will validate data you upload against this schema.

    • display_name – An optional display name for the Run, defaults to None. display_name does not have to be unique.

    • metadata – Additional key-value pairs you want to track, defaults to None.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

  • Returns: Newly created Run

create_run_query

Create a new RunQuery for a project to use as a baseline Run. Currently supports key=”offset_from_now” with value as a positive integer, representing the number of runs to go back for the baseline. For example, query={“offset_from_now”: 1} will use the latest run as the baseline, so that each run compares against the previous run.

  • Parameters:

    • project – The Project to create the RunQuery for

    • name – A name for the RunQuery

    • query – A dict describing how to find a Run dynamically. Currently, only supports “offset_from_now”: int as a key-value pair.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

  • Returns: A new dbnl RunQuery, typically used for finding a Dynamic Baseline for a Test Session

Examples:

create_run_schema

Create a new RunSchema

  • Parameters:

    • columns – List of column schema specs for the uploaded data, required keys name and type, optional keys component, description and greater_is_better.

    • scalars – List of scalar schema specs for the uploaded data, required keys name and type, optional keys component, description and greater_is_better.

    • index – Optional list of column names that are the unique identifier.

    • components_dag – Optional dictionary representing the DAG of components.

  • Returns: The RunSchema

Supported Types

  • int

  • float

  • boolean

  • string

  • category

  • list

Components

The optional component key is for specifying the source of the data column in relationship to the AI/ML app subcomponents. Components are used in visualizing the components DAG.

The components_dag dictionary specifies the topological layout of the AI/ML app. For each key-value pair, the key represents the source component, and the value is a list of the leaf components. The following code snippet describes the DAG shown above.

Examples:

Basic

With `scalars`, `index`, and `components_dag`

create_run_schema_from_results

Create a new RunSchema from the column results, as well as scalar results if provided

  • Parameters:

    • column_data – A pandas DataFrame with all the column results for which we want to generate a RunSchema.

    • scalar_data – A dict or pandas DataFrame with all the scalar results for which we want to generate a RunSchema.

    • index – An optional list of the column names that can be used as unique identifiers.

  • Raises:DBNLInputValidationError – Input does not conform to expected format

  • Returns: The RunSchema based on the provided results

Examples:

create_test_session

Create a new TestSession with the given Run as the Experiment Run, and the given Run or RunQuery as the baseline if provided

  • Parameters:

    • experiment_run – The Run to create the TestSession for

    • baseline – The Run or RunQuery to use as the Baseline Run, defaults to None. If None, the Baseline set for the Project is used.

    • include_tags – Optional list of Test Tag names to include in the Test Session.

    • exclude_tags – Optional list of Test Tag names to exclude in the Test Session.

    • require_tags – Optional list of Test Tag names to require in the Test Session.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

  • Returns: The newly created TestSession

Calling this will start evaluating Tests associated with a Run. Typically, the Run you just completed will be the “Experiment” and you’ll compare it to some earlier “Baseline Run”.

IMPORTANT

Referenced Runs must already be closed before a Test Session can begin.

Managing Tags

Suppose we have the following Tests with the associated Tags in our Project

  • Test1 with tags [“A”, “B”]

  • Test2 with tags [“A”]

  • Test3 with tags [“B”]

include_tags=[“A”, “B”] will trigger Tests 1, 2, and 3. require_tags=[“A”, “B”] will only trigger Test 1. exclude_tags=[“A”] will only trigger Test 3. include_tags=[“A”] and exclude_tags=[“B”] will only trigger Test 2.

Examples:

delete_metric

Delete a Metric by ID

  • Parameters:metric_id – ID of the metric to delete

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLAPIValidationError – dbnl API failed to validate the request

  • Returns: None

export_project_as_json

Export a Project alongside its Test Specs, Tags, and Notification Rules as a JSON object

  • Parameters:project – The Project to export as JSON.

  • Raises:DBNLNotLoggedInError – dbnl SDK is not logged in

  • Returns: JSON object representing the Project

Sample Project JSON

Examples:

get_column_results

Get column results for a Run

  • Parameters:run – The Run from which to retrieve the results.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

    • DBNLDownloadResultsError – Failed to download results (e.g. Run is not closed)

  • Returns: A pandas DataFrame of the column results for the Run.

IMPORTANT

You can only retrieve results for a Run that has been closed.

Examples:

get_latest_run

Get the latest Run for a project

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLResourceNotFoundError – Run not found

  • Parameters:project – The Project to get the latest Run for

  • Returns: The latest Run

get_metric_by_id

Get a Metric by ID

  • Parameters:metric_id – ID of the metric to get

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLAPIValidationError – dbnl API failed to validate the request

  • Returns: The requested metric

get_my_namespaces

Get all the namespaces that the user has access to

  • Raises:DBNLNotLoggedInError – dbnl SDK is not logged in

  • Returns: List of namespaces

get_or_create_project

Get the Project with the specified name or create a new one if it does not exist

  • Parameters:

    • name – Name for the Project

    • description – Description for the Project, defaults to None

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLAPIValidationError – dbnl API failed to validate the request

  • Returns: Newly created or matching existing Project

Examples:

get_project

Retrieve a Project by name.

  • Parameters:name – The name for the existing Project.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLProjectNotFoundError – Project with the given name does not exist.

  • Returns: Project

Examples:

get_results

Get all results for a Run

  • Parameters:run – The Run from which to retrieve the results.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

    • DBNLDownloadResultsError – Failed to download results (e.g. Run is not closed)

  • Returns: A named tuple comprised of columns and scalars fields. These are the pandas DataFrames of the uploaded data for the Run.

IMPORTANT

You can only retrieve results for a Run that has been closed.

Examples:

get_run

Retrieve a Run with the given ID

  • Parameters:run_id – The ID of the dbnl Run. Run ID starts with the prefix run_. Run ID can be found at the Run detail page.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

    • DBNLRunNotFoundError – A Run with the given ID does not exist.

  • Returns: The Run with the given run_id.

Examples:

get_run_query

Retrieve a RunQuery with the given name, unique to a project

  • Parameters:

    • project – The Project from which to retrieve the RunQuery.

    • name – The name of the RunQuery to retrieve.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLRessourceNotFoundError – RunQuery not found

  • Returns: RunQuery with the given name.

Examples:

get_scalar_results

Get scalar results for a Run

  • Parameters:run – The Run from which to retrieve the scalar results.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

    • DBNLDownloadResultsError – Failed to download results (e.g. Run is not closed)

  • Returns: A pandas DataFrame of the scalar results for the Run.

IMPORTANT

You can only retrieve results for a Run that has been closed.

Examples:

import_project_from_json

Create a new Project from a JSON object

  • Parameters:params – JSON object representing the Project, generally based on a Project exported via export_project_as_json(). See export_project_as_json() for the expected format.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLAPIValidationError – dbnl API failed to validate the request

    • DBNLConflictingProjectError – Project with the same name already exists

  • Returns: Project created from the JSON object

Examples:

login

Setup dbnl SDK to make authenticated requests. After login is run successfully, the dbnl client will be able to issue secure and authenticated requests against hosted endpoints of the dbnl service.

  • Parameters:

    • api_token – dbnl API token for authentication; token can be found at /tokens page of the dbnl app. If None is provided, the environment variable DBNL_API_TOKEN will be used by default.

    • namespace_id – The namespace ID to use for the session; available namespaces can be found with get_my_namespaces().

    • api_url – The base url of the Distributional API. For SaaS users, set this variable to api.dbnl.com. For other users, please contact your sys admin. If None is provided, the environment variable DBNL_API_URL will be used by default.

    • app_url – An optional base url of the Distributional app. If this variable is not set, the app url is inferred from the DBNL_API_URL variable. For on-prem users, please contact your sys admin if you cannot reach the Distributional UI.

report_column_results

Report all column results to dbnl

  • Parameters:

    • run – The Run that the results will be reported to

    • data – A pandas DataFrame with all the results to report to dbnl. The columns of the DataFrame must match the columns of the Run’s schema.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

IMPORTANT

All data should be reported to dbnl at once. Calling dbnl.report_column_results more than once will overwrite the previously uploaded data.

WARNING

Once a Run is closed, you can no longer call report_column_results to send data to dbnl.

Examples:

report_results

Report all results to dbnl

  • Parameters:

    • run – The Run that the results will be reported to

    • column_data – A pandas DataFrame with all the results to report to dbnl. The columns of the DataFrame must match the columns of the Run’s schema.

    • scalar_data – A dictionary or single-row pandas DataFrame with the scalar results to report to dbnl, defaults to None.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

IMPORTANT

All data should be reported to dbnl at once. Calling dbnl.report_results more than once will overwrite the previously uploaded data.

WARNING

Once a Run is closed, you can no longer call report_results to send data to dbnl.

Examples:

report_run_with_results

Create a new Run, report results to it, and close it.

  • Parameters:

    • project – The Project to create the Run in.

    • column_data – A pandas DataFrame with the results for the columns.

    • scalar_data – An optional dictionary or DataFrame with the results for the scalars, if any.

    • display_name – An optional display name for the Run.

    • index – An optional list of column names to use as the unique identifier for rows in the column data.

    • run_schema – An optional RunSchema to use for the Run. Will be inferred from the data if not provided.

    • metadata – Any additional key:value pairs you want to track.

    • wait_for_close – If True, the function will block for up to 3 minutes until the Run is closed, defaults to True.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

  • Returns: The closed Run with the uploaded data.

IMPORTANT

If no schema is provided, the schema will be inferred from the data. If provided, the schema will be used to validate the data.

Examples:

Implicit Schema

Explicit Schema

report_run_with_results_and_start_test_session

Create a new Run, report results to it, and close it. Wait for close to finish and start a TestSession with the given inputs.

  • Parameters:

    • project – The Project to create the Run in.

    • column_data – A pandas DataFrame with the results for the columns.

    • scalar_data – An optional dictionary or DataFrame with the results for the scalars, if any.

    • display_name – An optional display name for the Run.

    • index – An optional list of column names to use as the unique identifier for rows in the column data.

    • run_schema – An optional RunSchema to use for the Run. Will be inferred from the data if not provided.

    • metadata – Any additional key:value pairs you want to track.

    • wait_for_close – If True, the function will block for up to 3 minutes until the Run is closed, defaults to True.

    • baseline – The Run or RunQuery to use as the baseline run, defaults to None. If None, the baseline defined in the TestConfig is used.

    • include_tags – Optional list of Test Tag names to include in the Test Session.

    • exclude_tags – Optional list of Test Tag names to exclude in the Test Session.

    • require_tags – Optional list of Test Tag names to require in the Test Session.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

  • Returns: The closed Run with the uploaded data.

IMPORTANT

If no schema is provided, the schema will be inferred from the data. If provided, the schema will be used to validate the data.

Examples:

report_scalar_results

Report scalar results to dbnl

  • Parameters:

    • run – The Run that the scalars will be reported to

    • data – A dictionary or single-row pandas DataFrame with the scalar results to report to dbnl.

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLInputValidationError – Input does not conform to expected format

IMPORTANT

All data should be reported to dbnl at once. Calling dbnl.report_scalar_results more than once will overwrite the previously uploaded data.

WARNING

Once a Run is closed, you can no longer call report_scalar_results to send data to dbnl.

Examples:

set_run_as_baseline

Set the given Run as the Baseline Run in the Project’s Test Config

  • Parameters:run – The Run to set as the Baseline Run.

  • Raises:DBNLResourceNotFoundError – If the test configurations are not found for the project.

set_run_query_as_baseline

Set a given RunQuery as the Baseline Run in a Project’s Test Config

  • Parameters:run_query – The RunQuery to set as the Baseline RunQuery.

  • Raises:DBNLResourceNotFoundError – If the test configurations are not found for the project.

wait_for_run_close

Wait for a Run to close. Polls every polling_interval_s seconds until it is closed.

  • Parameters:

    • run – Run to wait for

    • timeout_s – Total wait time (in seconds) for Run to close, defaults to 180.0

    • polling_interval_s – Time between polls (in seconds), defaults to 3.0

  • Raises:

    • DBNLNotLoggedInError – dbnl SDK is not logged in

    • DBNLError – Run did not close after waiting for the timeout_s seconds

    • DBNLRunError – Run ended in ERRORED state

Was this helpful?