Skip to main content

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

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

# Get current time in epoch milliseconds using datetime
time_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)
if response.status_code != 200:
    raise Exception(f"Failed to log data. Status code: {response.status_code}")
# API is async, it won't fail and has no return body

Validate LLM

import whylogs_container_client.api.llm.validate_llm as ValidateLLM
from whylogs_container_client.models.llm_validate_request import LLMValidateRequest
from whylogs_container_client.models.validation_report import ValidationReport

# Validate a prompt and response pair for LLM validations
request = 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)
if not isinstance(response.parsed, ValidationReport):
    raise Exception(f"Failed to validate data. Status code: {response.status_code}. {response.parsed}")
report: ValidationReport = response.parsed

Health check

import whylogs_container_client.api.manage.health as Health

# Check if the container is running
Health.sync_detailed(client=client)

Get Status

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

# Get the current status of the container
response = Status.sync_detailed(client=client)
if not response.parsed:
    raise Exception(f"Failed to get status. Status code: {response.status_code}")
status: 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

There are more settings on the generated Client class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying httpx.Client or httpx.AsyncClient (depending on your use-case):

from whylogs_container_client import 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 = 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):

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

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.9.tar.gz (17.2 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.9-py3-none-any.whl (38.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for whylogs_container_client-1.0.9.tar.gz
Algorithm Hash digest
SHA256 9e6905b26fe834c71ca3f2d21462219f792853db49d7bd1abe1b59e34ed1a3e1
MD5 5dc69578e4d55293b9945f0734d0fa26
BLAKE2b-256 e94d6386d41bbae74c8626b1c6076e3f268c005d1e9e437287f3febebf7213ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for whylogs_container_client-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 d833365b7bfc7d70512921270a00f5a500ba38d51273791d9a2d789440919db1
MD5 1a641a833e888fc7664a07f40f7d73d2
BLAKE2b-256 99e2a0458e921b3d346f8ddf8097ea0ee2f188a0f92c70ea2400308dad8ce0fc

See more details on using hashes here.

Release history Release notifications | RSS feed

2.3.0

2 files

2.2.3

2 files

2.2.2

2 files

2.2.1

2 files

2.2.0

2 files

2.1.0

2 files

2.0.4

2 files

2.0.3

2 files

2.0.2

2 files

2.0.1

2 files

2.0.0

2 files

1.0.23

2 files

1.0.22

2 files

1.0.21

2 files

1.0.20

2 files

1.0.19

2 files

1.0.18

2 files

1.0.17

2 files

1.0.16

2 files

1.0.15

2 files

1.0.14

2 files

1.0.13

2 files

1.0.12

2 files

1.0.11

2 files

1.0.10

2 files

This release

1.0.9 This release

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.1

2 files

1.0.0

2 files

0.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page