Get started with ZeroEval tracing in Python applications
The ZeroEval Python SDK provides seamless integration with your Python applications through automatic instrumentation and a simple decorator-based API.
import zeroeval as ze# Option 1: ZEROEVAL_API_KEY in your environment variable fileze.init()# Option 2: Provide API key directly from# https://app.zeroeval.com/settings?tab=api-keysze.init(api_key="YOUR_API_KEY")
Run zeroeval setup once to save your API key securely to
~/.config/zeroeval/config.json
import zeroeval as zedef complex_workflow(): with ze.span(name="data_pipeline") as pipeline_span: # Fetch stage with ze.span(name="fetch_stage") as fetch_span: data = fetch_external_data() fetch_span.set_io(output_data=str(data)) # Process stage with ze.span(name="process_stage") as process_span: processed = transform_data(data) process_span.set_io( input_data=str(data), output_data=str(processed) ) # Save stage with ze.span(name="save_stage") as save_span: result = save_to_database(processed) save_span.set_io(output_data=f"Saved {result} records")
# Get the current spancurrent_span = ze.get_current_span()# Get the current trace IDtrace_id = ze.get_current_trace()# Get the current session IDsession_id = ze.get_current_session()