DefendAI Documentation: Wozway Python SDK
The SDK can be installed with either pip package manager.
pip install defendai-wozwayfrom 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)
passfrom 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
passThis 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 methods
- get_activities - Retrieve paginated activity data with filtering, sorting, and search options.
- delete_api_key - Delete an API key
- get_applications - Retrieve a list of applications
- post_application - Create or update an application
- delete_application - Delete an application
- post_connection - Create or update a connection.
- delete_connection_id_ - Delete a connection by ID.
- get_connections - Retrieve all connections for the user.
- post_resolve_incident - Resolve an incident
- get_incidents - Retrieve incident data
- get_policies - Retrieve a paginated list of policies with optional filters and sorting.
- post_policy - Create a new policy
- put_policy - Update an existing policy
- delete_policy - Delete an existing policy
- post_forgot_password - Initiate password reset process
- get_users - Retrieve a list of users
- post_user - Create a new user.
- put_user - Update an existing user.
- delete_user - Delete a user.
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 | */* |
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)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 |
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
passThe 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
passYou 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.