Galileo python sdk
by @gyanesh-m
Complete reference for the Galileo AI platform Python SDK for evaluating, observing, and protecting GenAI applications. Use when building Python applications...
import os
from galileo import galileo_context
from galileo.openai import openaigalileo_context.init(project="my-project", log_stream="my-log-stream")
client = openai.OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
response = client.chat.completions.create(
messages=[{"role": "user", "content": "Explain quantum computing in one sentence."}],
model="gpt-4o",
)
print(response.choices[0].message.content)
galileo_context.flush()
1. Always set environment variables for GALILEO_API_KEY and GALILEO_CONSOLE_URL rather than hardcoding credentials.
2. Organize projects and log streams by application, environment, or team to keep traces manageable.
3. Call galileo_context.flush() at the end of each request or batch to ensure traces are uploaded. In web servers, flush at the end of each request handler.
4. Use the context manager (with galileo_context(...)) for scoped logging that auto-flushes on exit.
5. Use specific span types (retriever, tool, llm, workflow) to get the most out of Galileo's trace visualization.
6. Handle errors gracefully β wrap flush() calls in try/except to prevent logging failures from crashing your application.
7. Use the wrapped OpenAI client (from galileo.openai import openai) for zero-config automatic tracing of all OpenAI calls.
8. Leverage guardrail metrics in production to catch hallucinations, toxic content, and PII before they reach end users.
clawhub install galileo-python-sdk