Skip to main content

Python Client SDK

Project description

defendai-wozway



Summary

DefendAi Documentation: Wozway Python SDK

Table of Contents

SDK Installation

The SDK can be installed with either pip package manager.

PIP

pip install defendai-wozway

SDK Example Usage

Simple Getting Started Example

from defendai_wozway import Wozway
import os

with Wozway(
    bearer_auth=os.getenv("WOZWAY_BEARER_AUTH", ""),
) as s:
    res = s.activities.get_activities()
    if res is not None:
        print(rs)
      pass
from defendai_wozway import Wozway
import os

with Wozway(
    bearer_auth=os.getenv("WOZWAY_BEARER_AUTH", ""),
) as s:
    res = s.activities.get_activities(request={
        "search": "Prompt description",
        "filters": "{\"verdicts\":[\"BLOCK\"],\"appNames\":[\"openai-app\"],\"modelNames\":[\"openai\"]}",
    })

    if res is not None:
        # handle response
        pass

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme Environment Variable
bearer_auth https HTTP Bearer WOZWAY_BEARER_AUTH

To authenticate with the API the bearer_auth parameter must be set when initializing the SDK client instance. For example:

Available Resources and Operations

Available methods

activities

  • get_activities - Retrieve paginated activity data with filtering, sorting, and search options.

api_keys

applications

connections

incidents

policies

users

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception.

By default, an API error will raise a models.APIError exception, which has the following properties:

Property Type Description
.status_code int The HTTP status code
.message str The error message
.raw_response httpx.Response The raw HTTP response
.body str The response content

When custom error responses are specified for an operation, the SDK may also raise their associated exceptions. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the delete_api_key_async method may raise the following exceptions:

Error Type Status Code Content Type
models.DeleteAPIKeyAPIKeysResponseBody 400 application/json
models.DeleteAPIKeyAPIKeysResponseResponseBody 500 application/json
models.APIError 4XX, 5XX */*

Example

from defendai_wozway import Wozway, models
import os

with Wozway(
    bearer_auth=os.getenv("WOZWAY_BEARER_AUTH", ""),
) as s:
    res = None
    try:
        res = s.api_keys.delete_api_key(api_key="<value>")

        if res is not None:
            # handle response
            pass

    except models.DeleteAPIKeyAPIKeysResponseBody as e:
        # handle e.data: models.DeleteAPIKeyAPIKeysResponseBodyData
        raise(e)
    except models.DeleteAPIKeyAPIKeysResponseResponseBody as e:
        # handle e.data: models.DeleteAPIKeyAPIKeysResponseResponseBodyData
        raise(e)
    except models.APIError as e:
        # handle exception
        raise(e)

Server Selection

Select Server by Index

You can override the default server globally by passing a server index to the server_idx: int optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

# Server
1 https://api.defendai.tech

Example

from defendai_wozway import Wozway
import os

with Wozway(
    server_idx=1,
    bearer_auth=os.getenv("WOZWAY_BEARER_AUTH", ""),
) as s:
    res = s.activities.get_activities(request={
        "search": "Example text",
        "filters": "{\"verdicts\":[\"BLOCK\"],\"appNames\":[\"app1\",\"app2\"],\"modelNames\":[\"modelA\",\"modelB\"]}",
    })

    if res is not None:
        # handle response
        pass

Override Server URL Per-Client

The default server can also be overridden globally by passing a URL to the server_url: str optional parameter when initializing the SDK client instance. For example:

from defendai_wozway import Wozway
import os

with Wozway(
    server_url="http://playground.defendai.tech",
    bearer_auth=os.getenv("WOZWAY_BEARER_AUTH", ""),
) as s:
    res = s.activities.get_activities(request={
        "search": "Example text",
        "filters": "{\"verdicts\":[\"BLOCK\"],\"appNames\":[\"app1\",\"app2\"],\"modelNames\":[\"modelA\",\"modelB\"]}",
    })

    if res is not None:
        # handle response
        pass

Debugging

You can setup your SDK to emit debug logs for SDK requests and responses.

You can pass your own logger class directly into your SDK.

from defendai_wozway import Wozway
import logging

logging.basicConfig(level=logging.DEBUG)
s = Wozway(debug_logger=logging.getLogger("defendai_wozway"))

You can also enable a default debug logger by setting an environment variable WOZWAY_DEBUG to true.

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

defendai_wozway-0.1.2.tar.gz (37.6 kB view details)

Uploaded Source

Built Distribution

defendai_wozway-0.1.2-py3-none-any.whl (60.6 kB view details)

Uploaded Python 3

File details

Details for the file defendai_wozway-0.1.2.tar.gz.

File metadata

  • Download URL: defendai_wozway-0.1.2.tar.gz
  • Upload date:
  • Size: 37.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for defendai_wozway-0.1.2.tar.gz
Algorithm Hash digest
SHA256 835f9049b86196afc0fe62cd6f1a78386308005c818334c7e9e85465d8f9853d
MD5 24dc0f491b57b16fb9d649a93e8926a5
BLAKE2b-256 9463e2591a563bdbf95f15dbb5abb91e4b86e5e28be1738c2986f082d6d23ddd

See more details on using hashes here.

File details

Details for the file defendai_wozway-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for defendai_wozway-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 54651a858d5f5f41dccc9125b4cdf79162c3b04fdddbfad9bb8073153935df48
MD5 7d86ce636d27832bb3da50f7728cebfa
BLAKE2b-256 ab20400f687f3c33a3adfe11c0df8a93004839806afe40bf164c329bf8455c9d

See more details on using hashes here.

Supported by

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