Client & Get Spans

Descriptions of classes and methods related to Phoenix Client for extracting/downloading data from the Phoenix server (either local or remote).

phoenix.Client

class Client:
    def __init__(
        self,
        *,
        endpoint: Optional[str] = None,
        use_active_session_if_available: bool = True,
    ):
        ...

A client for making HTTP requests to the Phoenix server for extracting/downloading data. See Usagefor examples.

[source]

Parameters

  • endpoint (Optional[str]): Phoenix server endpoint. This is the URL for a remote server. If not provided, the endpoint will be inferred from environment variables. See Environment Variables.

  • use_active_session_if_available (Optional[bool]): This is set to False if endpoint is set explicitly. If True and px.active_session() is available in the same runtime environment, e.g. the same Jupyter notebook, then delegate the requests to the Session object instead of making an HTTP request to the Phoenix server.

Methods

  • get_spans_dataframe -> Optional[pandas.DataFrame] Returns spans in a pandas.dataframe. Filters can be applied. See LLM Traces for more about tracing your LLM application. Parameters

    • filter_condition (Optional[str]): A Python expression for filtering spans. See Usage below for examples.

    • start_time (Optional[datetime]): A Python datetime object for filtering spans by time.

    • stop_time (Optional[datetime]): A Python datetime object for filtering spans by time.

    • root_spans_only (Optional[bool]): Whether to return only root spans, i.e. spans without parents. Defaults to False.

    • project_name (Optional[str]): The name of the project to retrieve spans for. It can also be specified via an environment variable, or if left blank, defaults to the default project name.

  • query_spans -> Optional[Union[pandas.DataFrame, List[pandas.DataFrame]] Extract values from spans in a pandas.dataframe. See Querying Spansfor more details. Parameters

    • *queries (SpanQuery): One or more SpanQuery object. See Querying Spansfor more details.

    • start_time (Optional[datetime]): A Python datetime object for filtering spans by time.

    • stop_time (Optional[datetime]): A Python datetime object for filtering spans by time.

    • root_spans_only (Optional[bool]): Whether to return only root spans, i.e. spans without parents. Defaults to False.

    • project_name (Optional[str]): The name of the project to retrieve spans for. It can also be specified via an environment variable, or if left blank, defaults to the default project name.

  • get_evaluations -> List[Evaluations]

    Extract evaluations if any. Otherwise returns empty List. See Log Evaluation Resultsfor more details. Parameters

    • project_name (Optional[str]): The name of the project to retrieve spans for. It can also be specified via an environment variable, or if left blank, defaults to the default project name.

  • get_trace_dataset -> Optional[TraceDataset] Returns the trace dataset containing spans and evaluations. Parameters

    • project_name (Optional[str]): The name of the project to retrieve spans for. It can also be specified via an environment variable, or if left blank, defaults to the default project name.

  • Parameters

    • *evaluations (Evaluations): One or more Evaluations datasets. See Log Evaluation Resultsfor more details.

    • project_name (Optional[str]): The name of the project to send the evaluations for. It can also be specified via an environment variable, or if left blank, defaults to the default project name.

Usage

Get all spans from Phoenix as a pandas dataframe.

px.Client().get_spans_dataframe()

To extract/download spans from a remote server, set the endpoint argument to the remote URL. A remote server could be a Phoenix server instance running in the background on your machine, or one that's hosted on the internet. The endpoint can also be set via the PHOENIX_COLLECTOR_ENDPOINT environment variable.

px.Client(endpoint="http://remote.server.com").get_spans_dataframe()

Get spans associated with calls to LLMs.

px.Client().get_spans_dataframe("span_kind == 'LLM'")

Get spans associated with calls to retrievers in a Retrieval Augmented Generation use case.

px.Client().get_spans_dataframe("span_kind == 'RETRIEVER'")

Environment Variables

Some settings of the Phoenix Client can be configured through the environment variables below.

  • PHOENIX_COLLECTOR_ENDPOINT The endpoint of the Phoenix collector.

    • This is usually the URL to a Phoenix server either hosted on the internet or running in the background on your machine.

  • PHOENIX_PORT The port on which the server listens.

  • PHOENIX_HOST The host on which the server listens.

Below is an example of how to set up the port parameter as an environment variable.

import os

os.environ["PHOENIX_PORT"] = "54321"

Last updated