Python SDK Reference
Python SDK Reference
Introduction
This document provides a comprehensive reference for the Galileo Python SDK, covering all the key classes, methods, and functions available for logging and analyzing your LLM applications.
Installation
Initialization/Authentication
You can configure Galileo using environment variables:
Core Components
OpenAI Wrapper
The simplest way to get started is to use our OpenAI client wrapper:
@log Decorator
The @log
decorator allows you to capture function inputs and outputs as spans:
galileo_context
The galileo_context
context manager provides control over trace context:
GalileoLogger
For more manual control over logging:
Datasets
For creating and managing datasets:
Prompts
For creating and using prompt templates:
Experiments
For running experiments:
LangChain Integration
For integrating with LangChain:
API Reference
galileo.openai
openai.OpenAI
: A wrapped version of the OpenAI client that automatically logs all API calls.
galileo.log
@log
: A decorator for capturing function inputs and outputs as spans.- Parameters:
span_type
: The type of span to create (“workflow”, “llm”, “retriever”, “tool”).name
: A custom name for the span.project
: The project to log to.log_stream
: The log stream to log to.params
: Additional parameters to include in the span.
- Parameters:
galileo.galileo_context
galileo_context
: A context manager for controlling logging behavior.- Parameters:
project
: The project to log to.log_stream
: The log stream to log to.
- Methods:
init(project, log_stream)
: Initialize the context.flush()
: Flush all traces to Galileo.
- Parameters:
galileo.GalileoLogger
GalileoLogger
: A class for manual control over logging.- Parameters:
project
: The project to log to.log_stream
: The log stream to log to.
- Methods:
start_trace(input, name, tags, metadata, duration_ns, created_at)
: Start a new trace.add_llm_span(input, output, model, ...)
: Add an LLM span to the trace.add_retriever_span(input, output, name, ...)
: Add a retriever span to the trace.add_tool_span(input, output, name, ...)
: Add a tool span to the trace.add_workflow_span(input, output, name, ...)
: Add a workflow span to the trace.conclude(output, duration_ns, status_code, conclude_all)
: Conclude the trace.flush()
: Flush the trace to Galileo.
- Parameters:
galileo.datasets
create_dataset(name, content)
: Create a new dataset.get_dataset(name, id, with_content)
: Get an existing dataset.list_datasets(limit)
: List all available datasets.delete_dataset(name, id)
: Delete a dataset.
galileo.prompts
create_prompt_template(name, project, messages)
: Create a new prompt template.get_prompt_template(project, name)
: Get an existing prompt template.
galileo.experiments
run_experiment(name, dataset, prompt, metrics, project)
: Run an experiment.create_experiment(project_id, experiment_name)
: Create a new experiment.get_experiment(project_id, experiment_name)
: Get an existing experiment.get_experiments(project_id)
: List all experiments in a project.
galileo.handlers.langchain
GalileoCallback
: A callback handler for LangChain.- Parameters:
galileo_logger
: A custom logger instance.start_new_trace
: Whether to start a new trace for each chain.flush_on_chain_end
: Whether to flush traces when chains end.
- Parameters: