Python SDK
The Splunk Agent Observability Python SDK on PyPI.
Installation
Initialization and authentication
These steps vary depending on your deployment type. Select the tab for your deployment type below to view the documentation.- On-premises
- SaaS
This section only applies to on-premises, standalone, and custom deployments. The following environment variables are used for these deployments:
To set up the Python SDK for an on-premises, standalone, or custom deployment:
1
Set your API key and deployment URL
Set your Agent Observability API key and deployment URL:
2
(Optional) Set a separate API URL
Set
SPLUNK_AO_API_URL only if your deployment uses a separate API URL that cannot be derived from the deployment URL:3
(Optional) Set your project and Agent Stream
Set the following environment variables to define the project and Agent Stream that Splunk Agent Observability should use. You can also provide these names through the SDK later.
Logging
The Splunk Agent Observability SDKs allow you to log all prompts, responses, and statistics around your LLM usage. There are three main ways to log your application:- Use a third-party integration - use wrappers that integrate with common SDKs to automatically log LLM calls or agentic workflows.
- Use a decorator - by decorating a function that calls an LLM with the
@logdecorator orlogwrapper, the Splunk Agent Observability SDK logs all AI prompts within. - Directly using the
SplunkAOLoggerclass - For more control over your logging, you can use theSplunkAOLoggerdirectly. This allows you to manually create sessions, start traces, and log spans. This can be mixed with the other methods, for example accessing the logger directly inside a decorated function call to manually add spans.
Log experiments
Experiments are logged automatically when they are run, but you can use these same SDK concepts inside the code being run by your experiment for greater control and additional logging. This allows you to not only create distinct experiments, such as in notebooks, but to also add experiments to your production application code. See our run experiments with code documentation for more details.Next steps
Logging with the SDKs
Learn how to log experiments
Learn how to run experiments with multiple data points using datasets and prompt templates
Splunk Agent Observability logger
Log with full control over sessions, traces, and spans using the Splunk Agent Observability logger.
Log decorator
Quickly add logging to your code with the log decorator and wrapper.
Splunk Agent Observability context
Manage logging using the Splunk Agent Observability context manager.
How-to guides
Log Using the OpenAI Wrapper
Learn how to integrate and use OpenAI’s API with Splunk Agent Observability’s wrapper client.
Python
Python
Log Using the @log Decorator
Learn how to use the Splunk Agent Observability @log decorator to log functions to traces
Python
Python
Create Traces and Spans
Learn how to create log traces and spans manually in your AI apps
Python
Python
SDK reference
Python SDK Reference
The Splunk Agent Observability Python SDK reference.
