Init
patronus.init
init
init(
project_name: Optional[str] = None,
app: Optional[str] = None,
api_url: Optional[str] = None,
otel_endpoint: Optional[str] = None,
api_key: Optional[str] = None,
service: Optional[str] = None,
**kwargs: Any,
) -> context.PatronusContext
Initializes the Patronus SDK with the specified configuration.
This function sets up the SDK with project details, API connections, and telemetry. It must be called before using evaluators or experiments to ensure proper recording of results and metrics.
Note
init()
should not be used for running experiments.
Experiments have its own initialization process.
You can configure them by passing configuration options to run_experiment()
or using configuration file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project_name
|
Optional[str]
|
Name of the project for organizing evaluations and experiments. Falls back to configuration file, then defaults to "Global" if not provided. |
None
|
app
|
Optional[str]
|
Name of the application within the project. Falls back to configuration file, then defaults to "default" if not provided. |
None
|
api_url
|
Optional[str]
|
URL for the Patronus API service. Falls back to configuration file or environment variables if not provided. |
None
|
otel_endpoint
|
Optional[str]
|
Endpoint for OpenTelemetry data collection. Falls back to configuration file or environment variables if not provided. |
None
|
api_key
|
Optional[str]
|
Authentication key for Patronus services. Falls back to configuration file or environment variables if not provided. |
None
|
service
|
Optional[str]
|
Service name for OpenTelemetry traces. Falls back to configuration file or environment variables if not provided. |
None
|
**kwargs
|
Any
|
Additional configuration options for the SDK. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
PatronusContext |
PatronusContext
|
The initialized context object. |
Example
Source code in src/patronus/init.py
build_context
build_context(
service: str,
project_name: str,
app: Optional[str],
experiment_id: Optional[str],
experiment_name: Optional[str],
api_url: Optional[str],
otel_endpoint: str,
api_key: str,
client_http: Optional[Client] = None,
client_http_async: Optional[AsyncClient] = None,
timeout_s: int = 60,
**kwargs: Any,
) -> context.PatronusContext
Builds a Patronus context with the specified configuration parameters.
This function creates the context object that contains all necessary components
for the SDK operation, including loggers, tracers, and API clients. It is used
internally by the init()
function but can also be used directly for more
advanced configuration scenarios.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
str
|
Service name for OpenTelemetry traces. |
required |
project_name
|
str
|
Name of the project for organizing evaluations and experiments. |
required |
app
|
Optional[str]
|
Name of the application within the project. |
required |
experiment_id
|
Optional[str]
|
Unique identifier for an experiment when running in experiment mode. |
required |
experiment_name
|
Optional[str]
|
Display name for an experiment when running in experiment mode. |
required |
api_url
|
Optional[str]
|
URL for the Patronus API service. |
required |
otel_endpoint
|
str
|
Endpoint for OpenTelemetry data collection. |
required |
api_key
|
str
|
Authentication key for Patronus services. |
required |
client_http
|
Optional[Client]
|
Custom HTTP client for synchronous API requests. If not provided, a new client will be created. |
None
|
client_http_async
|
Optional[AsyncClient]
|
Custom HTTP client for asynchronous API requests. If not provided, a new client will be created. |
None
|
timeout_s
|
int
|
Timeout in seconds for HTTP requests (default: 60). |
60
|
**kwargs
|
Any
|
Additional configuration options, including: - integrations: List of OpenTelemetry instrumentors to enable. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
PatronusContext |
PatronusContext
|
The initialized context object containing all necessary components for SDK operation. |
Source code in src/patronus/init.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|