WhyLabs API Client
The `whylabs-client` is a Python client library that provides a convenient way to interact with the WhyLabs API for end-to-end AI observability. It enables users to manage models, datasets, and monitors on the WhyLabs Platform. The library is automatically generated by the OpenAPI Generator project. Current version is 0.6.16.
Common errors
-
RecursionError: maximum recursion depth exceeded
cause Attempting to import large portions of the auto-generated client (`whylabs_client.api` or `whylabs_client.model`) at once, which can hit Python's default recursion limit due to the complexity of the OpenAPI spec.fixRefactor imports to be more specific, e.g., `from whylabs_client.api.your_api_module import YourApiClass` and `from whylabs_client.model.your_model import YourModel`. Alternatively, increase Python's recursion limit with `sys.setrecursionlimit(new_limit)` (use with caution). -
whylabs_client.ApiException: (429) Too Many Requests
cause Your application has exceeded the API rate limits or profile limits set by the WhyLabs platform.fixImplement retry mechanisms with exponential backoff. Review your data ingestion strategy to ensure it adheres to WhyLabs' profile and rate limits. Consider aggregating data locally before uploading or adjusting your upload frequency. -
Seeing more rows in WhyLabs than I had in my dataset
cause This typically occurs when the same dataset is logged multiple times. WhyLabs merges profiles uploaded for the same day (or hour), rather than overwriting previous ones.fixIf duplicate profiles are not desired, ensure your logging mechanism only uploads a unique profile for a given time granularity. To remove existing duplicates, a new model might need to be created and backfilled with correct data, or contact support for options if still available.
Warnings
- breaking WhyLabs, Inc. officially discontinued operations. While the platform has been open-sourced, future commercial support and active development from the original company are no longer available.
- gotcha Importing the entire `whylabs_client.api` or `whylabs_client.model` modules directly can lead to a `RecursionError: maximum recursion depth exceeded` if the generated OpenAPI specification is very large.
- gotcha WhyLabs API enforces profile and rate limits. Exceeding these quotas will result in a `TooManyRequests` error.
Install
-
pip install whylabs-client
Imports
- Configuration
from whylabs_client import Configuration
- ApiClient
from whylabs_client import ApiClient
- ApiClass
import whylabs_client.api
from whylabs_client.api import some_api
Quickstart
import os
import whylabs_client
from whylabs_client.api import api_key_api
# Configure API key authorization
configuration = whylabs_client.Configuration(
host="https://api.whylabsapp.com"
)
configuration.api_key['ApiKeyAuth'] = os.environ.get('WHYLABS_API_KEY', '')
# It's good practice to set discard_unknown_keys to True if you encounter parsing issues
# configuration.discard_unknown_keys = True
try:
with whylabs_client.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = api_key_api.ApiKeyApi(api_client)
# Example: List user API keys (requires appropriate permissions)
# This call might not be available or might require specific permissions/parameters
# depending on your API key scope. This is illustrative.
# response = api_instance.list_user_api_keys()
# print(response)
print("Successfully configured WhyLabs API client.")
print("Ensure WHYLABS_API_KEY environment variable is set for actual API calls.")
except whylabs_client.ApiException as e:
print(f"Exception when calling WhyLabs API: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")