Arize Phoenix Client

2.3.1 · active · verified Sun Apr 12

The Arize Phoenix Client is a lightweight Python package designed for interacting with the Phoenix platform via its OpenAPI REST interface. It enables users to programmatically manage datasets, run experiments, analyze traces, and collect feedback, primarily focusing on LLM observability. The library is actively maintained with frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Phoenix client and interact with datasets. It shows how to create a dataset from a Pandas DataFrame and then retrieve it. Ensure your Phoenix server is running and accessible, and configure `PHOENIX_BASE_URL` and `PHOENIX_API_KEY` (if using cloud) via environment variables or directly in the `Client` constructor.

import os
from phoenix.client import Client
import pandas as pd

# Configure Phoenix Client using environment variables or directly
# For local Phoenix server (default): export PHOENIX_BASE_URL="http://localhost:6006"
# For Phoenix Cloud: export PHOENIX_API_KEY="your-api-key" and export PHOENIX_BASE_URL="https://app.phoenix.arize.com/s/your-space"
# Ensure PHOENIX_BASE_URL is set, or pass it directly.

# Example: Directly configuring for a local server, ensure a Phoenix server is running.
client = Client(base_url=os.environ.get('PHOENIX_BASE_URL', 'http://localhost:6006'))

try:
    # Create a simple DataFrame
    df = pd.DataFrame({
        "question": [
            "What is the capital of France?",
            "Who wrote Hamlet?"
        ],
        "answer": [
            "Paris",
            "William Shakespeare"
        ]
    })

    # Create a dataset in Phoenix
    dataset_name = "my-qa-dataset"
    dataset = client.datasets.create_dataset(
        name=dataset_name,
        dataframe=df,
        input_keys=["question"],
        output_keys=["answer"]
    )

    print(f"Successfully created dataset: {dataset.name} with {len(dataset)} examples.")

    # Retrieve the dataset
    retrieved_dataset = client.datasets.get_dataset(dataset=dataset_name)
    print(f"Retrieved dataset: {retrieved_dataset.name}.")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure the Phoenix server is running and accessible at the specified base_url.")

view raw JSON →