Arize Phoenix Client
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
- breaking The legacy `phoenix.session.client.Client` (accessed as `px.Client()`) has been removed in `arize-phoenix 14.0.0` (corresponding to `arize-phoenix-client 2.3.1+`). All client interactions must now use `from phoenix.client import Client`.
- breaking Evals 1.0 and the legacy experiments module have been removed. This affects `arize-phoenix-evals 3.0.0` and `arize-phoenix-client 2.3.1+`.
- deprecated The `client.annotations` module was removed. Its functionality has been integrated into `client.spans`.
Install
-
pip install arize-phoenix-client
Imports
- Client
from phoenix.client import Client
- AsyncClient
from phoenix.client import AsyncClient
Quickstart
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.")