Skip to main content

A client library for accessing the whylogs python container

Project description

whylogs-container-client

A client library for accessing FastAPI.

See the WhyLabs doc site for full documentation, or see the API endpoint documentation for information on a specific API. The structure there mimics the module structure in the generated client.

Usage

First, create a client:

from whylogs_container_client import AuthenticatedClient

# 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")

from whylogs_container_client import Client

# Can use a regular Client if the container has no password set
client = Client(base_url="http://localhost:8000")

APIs

Things to know:

  1. Every API has four ways of calling it.

    1. sync: Blocking request that returns parsed data (if successful) or None
    2. sync_detailed: Blocking request that always returns a Request, optionally with parsed set if the request was successful.
    3. asyncio: Like sync but async instead of blocking
    4. asyncio_detailed: Like sync_detailed but async instead of blocking
  2. APIs are grouped by their "tags" as Python modules.

  3. APIs that do not have a tag are in whylogs_container_client.api.default

Here are some example requests for common APIs.

Log Data

from datetime import datetime

import whylogs_container_client.api.profile.log as Log
from whylogs_container_client.models import LogMultiple, LogRequest

# Get current time in epoch milliseconds using datetime
time_ms = int(datetime.now().timestamp() * 1000)

data = LogRequest(
    dataset_id="model-141",
    timestamp=time_ms,
    multiple=LogMultiple(
        columns=["custom_metric_1", "custom_metric_2"],
        data=[[1, 2], [3, 4]],
    ),
)

response = Log.sync_detailed(client=client, body=data)
if response.status_code != 200:
    raise Exception(f"Failed to log data. Status code: {response.status_code}")

Validate LLM

from whylogs_container_client.models.evaluation_result import EvaluationResult
from whylogs_container_client.models.llm_validate_request import LLMValidateRequest
from whylogs_container_client.models.validation_result import ValidationResult

request = LLMValidateRequest(
    prompt="?",
    response="I'm sorry you feel that way.",
    dataset_id="model-139",
    id="myid",
)

response = Evaluate.sync_detailed(client=client, body=request)

if not isinstance(response.parsed, EvaluationResult):
    raise Exception(f"Failed to validate data. Status code: {response.status_code}. {response.parsed}")

result: ValidationResult = response.parsed.validation_results

Health check

import whylogs_container_client.api.manage.health as Health

Health.sync_detailed(client=client)

Get Status

import whylogs_container_client.api.manage.status as Status
from whylogs_container_client.models.process_logger_status_response import ProcessLoggerStatusResponse

response = Status.sync_detailed(client=client)

if response.parsed is None:
    raise Exception("Unexpected response type")

result: ProcessLoggerStatusResponse = response.parsed

Certificates

You can customize or disable the certificate verification.

# Example of using a custom certificate bundle
client.verify_ssl = "/path/to/certificate_bundle.pem"
# Adding event hooks to the httpx client
def log_request(request):
    print(f"Request event hook: {request.method} {request.url} - Waiting for response")

def log_response(response):
    request = response.request
    print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")

client.httpx_args = {"event_hooks": {"request": [log_request], "response": [log_response]}}

Advanced customizations

You can set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):

import httpx
from whylogs_container_client import Client

client = 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"))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whylogs_container_client-1.0.12.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

whylogs_container_client-1.0.12-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

Details for the file whylogs_container_client-1.0.12.tar.gz.

File metadata

  • Download URL: whylogs_container_client-1.0.12.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.8 Linux/6.5.0-1016-azure

File hashes

Hashes for whylogs_container_client-1.0.12.tar.gz
Algorithm Hash digest
SHA256 67b970a6f8ef713693145696cbf7df2652e5e1013349bfb6648fcc82d04967f5
MD5 1afd91252a0973bdc32b411d31cc9e59
BLAKE2b-256 c8e3e283d7f74419618b1c0bb529de5e06ee047bc719e36c32365aae687e0e56

See more details on using hashes here.

File details

Details for the file whylogs_container_client-1.0.12-py3-none-any.whl.

File metadata

File hashes

Hashes for whylogs_container_client-1.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 d15bdcadb3fda40bdf5b3f5a0688c1b1eacc5ae787014cff1869f9d34232464c
MD5 e0899127de2de5a55de7ca41d139f24f
BLAKE2b-256 01cf789eb360ef9e16ce1f45a65279de7c5c6c8c39b5f526eff83432c41764cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page