Package: whylogs-container-client
whylogs-container-clientA client library for accessing FastAPI.See theWhyLabs doc sitefor full documentation, or see theAPI
endpointdocumentation for information on a specific API. The structure there mimics the module structure in the generated client.UsageFirst, create a client:fromwhylogs_container_clientimportAuthenticatedClient# Create an authenticated client for a container running on localhost# The token field should match the password that you set on your whylogs container deployment.client=AuthenticatedClient(base_url="http://localhost:8000",token="password",prefix="",auth_header_name="X-API-Key")fromwhylogs_container_clientimportClient# Can use a regular Client if the container has no password setclient=Client(base_url="http://localhost:8000")APIsThings to know:Every API has four ways of calling it.sync: Blocking request that returns parsed data (if successful) orNonesync_detailed: Blocking request that always returns aRequest, optionally withparsedset if the request was successful.asyncio: Likesyncbut async instead of blockingasyncio_detailed: Likesync_detailedbut async instead of blockingAPIs are grouped by their "tags" as Python modules.APIs that do not have a tag are inwhylogs_container_client.api.defaultHere are some example requests for common APIs.Log Dataimportwhylogs_container_client.api.profile.logasLogfromwhylogs_container_client.modelsimportLogRequest,LogMultiplefromdatetimeimportdatetime# Get current time in epoch milliseconds using datetimetime_ms=int(datetime.now().timestamp()*1000)data=LogRequest(dataset_id="model-1",timestamp=time_ms,multiple=LogMultiple(columns=["col1","col2"],data=[[1,2],[3,4]],))response=Log.sync_detailed(client=client,json_body=data)ifresponse.status_code!=200:raiseException(f"Failed to log data. Status code:{response.status_code}")# API is async, it won't fail and has no return bodyValidate LLMimportwhylogs_container_client.api.llm.validate_llmasValidateLLMfromwhylogs_container_client.models.llm_validate_requestimportLLMValidateRequestfromwhylogs_container_client.models.validation_reportimportValidationReport# Validate a prompt and response pair for LLM validationsrequest=LLMValidateRequest(prompt="This is a test prompt",response="This is a test response",dataset_id="model-1",)response=ValidateLLM.sync_detailed(client=client,json_body=request)ifnotisinstance(response.parsed,ValidationReport):raiseException(f"Failed to validate data. Status code:{response.status_code}.{response.parsed}")report:ValidationReport=response.parsedHealth checkimportwhylogs_container_client.api.manage.healthasHealth# Check if the container is runningHealth.sync_detailed(client=client)Get Statusimportwhylogs_container_client.api.manage.statusasStatusfromwhylogs_container_client.modelsimportProcessLoggerStatusResponse# Get the current status of the containerresponse=Status.sync_detailed(client=client)ifnotresponse.parsed:raiseException(f"Failed to get status. Status code:{response.status_code}")status:ProcessLoggerStatusResponse=response.parsedCertificatesYou can customize or disable the certificate verification.# Example of using a custom certificate bundleclient.verify_ssl="/path/to/certificate_bundle.pem"# Adding event hooks to the httpx clientdeflog_request(request):print(f"Request event hook:{request.method}{request.url}- Waiting for response")deflog_response(response):request=response.requestprint(f"Response event hook:{request.method}{request.url}- Status{response.status_code}")client.httpx_args={"event_hooks":{"request":[log_request],"response":[log_response]}}Advanced customizationsThere are more settings on the generatedClientclass which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlyinghttpx.Clientorhttpx.AsyncClient(depending on your use-case):fromwhylogs_container_clientimportClientdeflog_request(request):print(f"Request event hook:{request.method}{request.url}- Waiting for response")deflog_response(response):request=response.requestprint(f"Response event hook:{request.method}{request.url}- Status{response.status_code}")client=Client(base_url="https://api.example.com",httpx_args={"event_hooks":{"request":[log_request],"response":[log_response]}},)# Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):importhttpxfromwhylogs_container_clientimportClientclient=Client(base_url="https://api.example.com",)# Note that base_url needs to be re-set, as would any shared cookies, headers, etc.client.set_httpx_client(httpx.Client(base_url="https://api.example.com",proxies="http://localhost:8030"))