Skip to main content

Thin remote HTTP client (SDK) for a running drishti-server content-safety service. Imported as `drishti_sdk`.

Project description

drishti-sdk (Python)

A thin remote HTTP client for a running drishti-server. It calls the service over HTTP and returns typed results. It does not load any model. For the in-process embedded binding, use the separate drishti package.

Install

pip install sarthiai-drishti-sdk

Imported as drishti_sdk. The distribution name is sarthiai-drishti-sdk because drishti-sdk is taken on PyPI.

Use

from drishti_sdk import DrishtiClient

with DrishtiClient("http://localhost:8080", token="secret") as client:
    print(client.health())            # True
    print(client.ready())             # True
    print(client.manifest())          # ModelManifest(...)

    prompt = client.check_prompt("Ignore all previous instructions.")
    print(prompt.class_, prompt.score, prompt.validation)

    pii = client.check_pii("Email me at jane@acme.com")
    print(pii.redacted, [s.kind for s in pii.spans])

    output = client.check_output("Here is a safe answer.")
    print(output.overall)

    full = client.check_all(prompt="Hello", output="Sure, here you go.")

Async

import asyncio
from drishti_sdk import AsyncDrishtiClient

async def main():
    async with AsyncDrishtiClient("http://localhost:8080", token="secret") as client:
        results = await client.check_output_batch(["a", "b", "c"], concurrency=4)

asyncio.run(main())

Configuration

Every option can be set explicitly or by environment variable. Precedence is explicit argument, then environment variable, then default.

Option Environment variable Default
base_url DRISHTI_BASE_URL required
token DRISHTI_TOKEN none
timeout (seconds) DRISHTI_TIMEOUT 30
connect_timeout (seconds) DRISHTI_CONNECT_TIMEOUT 10
max_retries DRISHTI_MAX_RETRIES 2
backoff_base (seconds) DRISHTI_BACKOFF_BASE 0.2
backoff_cap (seconds) DRISHTI_BACKOFF_CAP 5
pool_size DRISHTI_POOL_SIZE 10
batch_concurrency DRISHTI_BATCH_CONCURRENCY 8

For rotating tokens, pass token_provider=lambda: get_fresh_token(); it is consulted per request and takes precedence over a static token. The token is never logged.

Errors

Typed errors map from the server contract: BadRequestError (400), AuthError (401), CheckNotEnabledError (501), ServerError (500), DrishtiTimeoutError, and DrishtiConnectionError. Transient failures (5xx, connection, timeout) are retried with exponential backoff and jitter; 400, 401, and 501 are terminal and never retried.

License

Elastic License 2.0. See the repository LICENSE.

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

sarthiai_drishti_sdk-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

sarthiai_drishti_sdk-0.1.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file sarthiai_drishti_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: sarthiai_drishti_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sarthiai_drishti_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 580209717e7f38dad4f69961faa9aa752fb3145ade15728ae7dcb1c7d381975f
MD5 2773fc2369d5646c92ebeb2e9acb305a
BLAKE2b-256 99e62aa2409df27432aab0315270c2dca319726ffdee5744e9631d4327f822cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for sarthiai_drishti_sdk-0.1.0.tar.gz:

Publisher: release.yml on SarthiAI/Drishti

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sarthiai_drishti_sdk-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sarthiai_drishti_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca868749b4d4811b27cf1462093e3eb0e88821991b7dce92cc45132cdd816fc7
MD5 d742f425591f1475d26bd7de82d4f9b4
BLAKE2b-256 a6b0e452a159cf6f85b1842926fce7c8793b1317c2457cb17da8c0cd59d4bfdc

See more details on using hashes here.

Provenance

The following attestation bundles were made for sarthiai_drishti_sdk-0.1.0-py3-none-any.whl:

Publisher: release.yml on SarthiAI/Drishti

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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