whylogs-container-client


Namewhylogs-container-client JSON
Version 1.0.18 PyPI version JSON
download
home_pageNone
SummaryA client library for accessing the whylogs python container
upload_time2024-04-30 17:31:11
maintainerNone
docs_urlNone
authorAnthony Naddeo
requires_python<4.0,>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # whylogs-container-client

A client library for accessing FastAPI.

See the [WhyLabs doc site](https://docs.whylabs.ai/docs/integrations-whylogs-container) for full documentation, or see the [API
endpoint](https://whylabs.github.io/whylogs-container-python-docs/whylogs-container-python.html#operation/log_docs_log_docs_post)
documentation for information on a specific API. The structure there mimics the module structure in the generated client.

## Usage

First, create a client:

```python
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`
   1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
   1. `asyncio`: Like `sync` but async instead of blocking
   1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking

1. APIs are grouped by their "tags" as Python modules.
1. APIs that do not have a tag are in `whylogs_container_client.api.default`

Here are some example requests for common APIs.

### Log Data

```python
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

```python
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

```python
import whylogs_container_client.api.manage.health as Health

Health.sync_detailed(client=client)
```

### Get Status

```python
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.

```python
# Example of using a custom certificate bundle
client.verify_ssl = "/path/to/certificate_bundle.pem"
```

```python
# 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):

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "whylogs-container-client",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Anthony Naddeo",
    "author_email": "anthony@whylabs.ai",
    "download_url": "https://files.pythonhosted.org/packages/85/ed/80bfad2e50e1074634bf88d2791e091dbb682068597ea5f50903c15eb01a/whylogs_container_client-1.0.18.tar.gz",
    "platform": null,
    "description": "# whylogs-container-client\n\nA client library for accessing FastAPI.\n\nSee the [WhyLabs doc site](https://docs.whylabs.ai/docs/integrations-whylogs-container) for full documentation, or see the [API\nendpoint](https://whylabs.github.io/whylogs-container-python-docs/whylogs-container-python.html#operation/log_docs_log_docs_post)\ndocumentation for information on a specific API. The structure there mimics the module structure in the generated client.\n\n## Usage\n\nFirst, create a client:\n\n```python\nfrom whylogs_container_client import AuthenticatedClient\n\n# Create an authenticated client for a container running on localhost\n# The token field should match the password that you set on your whylogs container deployment.\nclient = AuthenticatedClient(base_url=\"http://localhost:8000\", token=\"password\", prefix=\"\", auth_header_name=\"X-API-Key\")\n\nfrom whylogs_container_client import Client\n\n# Can use a regular Client if the container has no password set\nclient = Client(base_url=\"http://localhost:8000\")\n```\n\n## APIs\n\nThings to know:\n\n1. Every API has four ways of calling it.\n\n   1. `sync`: Blocking request that returns parsed data (if successful) or `None`\n   1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.\n   1. `asyncio`: Like `sync` but async instead of blocking\n   1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking\n\n1. APIs are grouped by their \"tags\" as Python modules.\n1. APIs that do not have a tag are in `whylogs_container_client.api.default`\n\nHere are some example requests for common APIs.\n\n### Log Data\n\n```python\nfrom datetime import datetime\n\nimport whylogs_container_client.api.profile.log as Log\nfrom whylogs_container_client.models import LogMultiple, LogRequest\n\n# Get current time in epoch milliseconds using datetime\ntime_ms = int(datetime.now().timestamp() * 1000)\n\ndata = LogRequest(\n    dataset_id=\"model-141\",\n    timestamp=time_ms,\n    multiple=LogMultiple(\n        columns=[\"custom_metric_1\", \"custom_metric_2\"],\n        data=[[1, 2], [3, 4]],\n    ),\n)\n\nresponse = Log.sync_detailed(client=client, body=data)\nif response.status_code != 200:\n    raise Exception(f\"Failed to log data. Status code: {response.status_code}\")\n```\n\n### Validate LLM\n\n```python\nfrom whylogs_container_client.models.evaluation_result import EvaluationResult\nfrom whylogs_container_client.models.llm_validate_request import LLMValidateRequest\nfrom whylogs_container_client.models.validation_result import ValidationResult\n\nrequest = LLMValidateRequest(\n    prompt=\"?\",\n    response=\"I'm sorry you feel that way.\",\n    dataset_id=\"model-139\",\n    id=\"myid\",\n)\n\nresponse = Evaluate.sync_detailed(client=client, body=request)\n\nif not isinstance(response.parsed, EvaluationResult):\n    raise Exception(f\"Failed to validate data. Status code: {response.status_code}. {response.parsed}\")\n\nresult: ValidationResult = response.parsed.validation_results\n```\n\n### Health check\n\n```python\nimport whylogs_container_client.api.manage.health as Health\n\nHealth.sync_detailed(client=client)\n```\n\n### Get Status\n\n```python\nimport whylogs_container_client.api.manage.status as Status\nfrom whylogs_container_client.models.process_logger_status_response import ProcessLoggerStatusResponse\n\nresponse = Status.sync_detailed(client=client)\n\nif response.parsed is None:\n    raise Exception(\"Unexpected response type\")\n\nresult: ProcessLoggerStatusResponse = response.parsed\n```\n\n## Certificates\n\nYou can customize or disable the certificate verification.\n\n```python\n# Example of using a custom certificate bundle\nclient.verify_ssl = \"/path/to/certificate_bundle.pem\"\n```\n\n```python\n# Adding event hooks to the httpx client\ndef log_request(request):\n    print(f\"Request event hook: {request.method} {request.url} - Waiting for response\")\n\ndef log_response(response):\n    request = response.request\n    print(f\"Response event hook: {request.method} {request.url} - Status {response.status_code}\")\n\nclient.httpx_args = {\"event_hooks\": {\"request\": [log_request], \"response\": [log_response]}}\n```\n\n## Advanced customizations\n\nYou can set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):\n\n```python\nimport httpx\nfrom whylogs_container_client import Client\n\nclient = Client(\n    base_url=\"https://api.example.com\",\n)\n# Note that base_url needs to be re-set, as would any shared cookies, headers, etc.\nclient.set_httpx_client(httpx.Client(base_url=\"https://api.example.com\", proxies=\"http://localhost:8030\"))\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A client library for accessing the whylogs python container",
    "version": "1.0.18",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "67c6b0dee040ce919a6efa3269586a2c829db048f8b60ba1af6fe8dd352644a1",
                "md5": "d2780a09dbe29eee621af18c8e2d6589",
                "sha256": "9b317588fa7bda22ba2afc5a893e8a7a1dd58dc66466008fc9d8348787b44d1a"
            },
            "downloads": -1,
            "filename": "whylogs_container_client-1.0.18-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d2780a09dbe29eee621af18c8e2d6589",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 52719,
            "upload_time": "2024-04-30T17:31:10",
            "upload_time_iso_8601": "2024-04-30T17:31:10.021637Z",
            "url": "https://files.pythonhosted.org/packages/67/c6/b0dee040ce919a6efa3269586a2c829db048f8b60ba1af6fe8dd352644a1/whylogs_container_client-1.0.18-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "85ed80bfad2e50e1074634bf88d2791e091dbb682068597ea5f50903c15eb01a",
                "md5": "c546746e123aa1706fc8af32856df61a",
                "sha256": "3f2bf9ff4090c3177ecd9f8493e01d8a20492da6df056ff1ed6e3c11bdaa9f67"
            },
            "downloads": -1,
            "filename": "whylogs_container_client-1.0.18.tar.gz",
            "has_sig": false,
            "md5_digest": "c546746e123aa1706fc8af32856df61a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 21560,
            "upload_time": "2024-04-30T17:31:11",
            "upload_time_iso_8601": "2024-04-30T17:31:11.913015Z",
            "url": "https://files.pythonhosted.org/packages/85/ed/80bfad2e50e1074634bf88d2791e091dbb682068597ea5f50903c15eb01a/whylogs_container_client-1.0.18.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-30 17:31:11",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "whylogs-container-client"
}
        
Elapsed time: 0.27416s