Skip to main content

No project description provided

Project description

Credal Python Library

fern shield PyPI - Python Version

The Credal Python library provides convenient access to the Credal API from Python.

Documentation

Docs for the API endpoints available through the SDK can be found in our API Reference.

Reference

A full reference of the SDK is available here.

Installation

pip install --upgrade credal

Usage

from credal.client import CredalApi

client = CredalApi(
    api_key="YOUR_API_KEY",
)

client.copilots.send_message(
    message="Is Credal SOC 2 compliant?",
    user_email="jack@credal.ai",
)

Self Hosted

client = CredalApi(
    api_key="YOUR_API_KEY",
    base_url="https://<custom-domain>/api",
)

Async Client

from credal.client import AsyncCredalApi

client = AsyncCredalApi(
    api_key="YOUR_API_KEY",
)

Exception Handling

All errors thrown by the SDK will be subclasses of ApiError.

import credal

...

try:
    client.copilots.send_message(...)
except credal.core.ApiError as e: # Handle all errors
    print(e.status_code)
    print(e.body)

Advanced

Timeouts

By default, requests time out after 60 seconds. You can configure this with a timeout option at the client or request level.

from credal.client import CredalApi

client = CredalApi(
    ...,
    # All timeouts are 20 seconds
    timeout=20.0,
)

# Override timeout for a specific method
client.copilots.send_message(..., {
    timeout_in_seconds=20.0
})

Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retriable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retriable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the max_retries request option to configure this behavior.

client.copilots.send_message(..., {
    max_retries=1
})

Custom HTTP client

You can override the httpx client to customize it for your use-case. Some common use-cases include support for proxies and transports.

import httpx

from credal.client import CredalApi

client = CredalApi(...,
    http_client=httpx.Client(
        proxies="http://my.test.proxy.example.com",
        transport=httpx.HTTPTransport(local_address="0.0.0.0"),
    ),
)

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

credal-0.0.28.tar.gz (45.1 kB view details)

Uploaded Source

Built Distribution

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

credal-0.0.28-py3-none-any.whl (93.5 kB view details)

Uploaded Python 3

File details

Details for the file credal-0.0.28.tar.gz.

File metadata

  • Download URL: credal-0.0.28.tar.gz
  • Upload date:
  • Size: 45.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/6.11.0-1014-azure

File hashes

Hashes for credal-0.0.28.tar.gz
Algorithm Hash digest
SHA256 1608f823af072a0825a47564c882774b2db59b24ad99ef295c9e57816016e4a8
MD5 0aa63d4932a70e1d146f1ec3a18cd041
BLAKE2b-256 253bff13b589198ca1b9627c625f9908a79857c77b80dcc53a1d2f5ac888801f

See more details on using hashes here.

File details

Details for the file credal-0.0.28-py3-none-any.whl.

File metadata

  • Download URL: credal-0.0.28-py3-none-any.whl
  • Upload date:
  • Size: 93.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/6.11.0-1014-azure

File hashes

Hashes for credal-0.0.28-py3-none-any.whl
Algorithm Hash digest
SHA256 a09d4cf97a21c6a9d6dc1dd0226a3c699c46bec7936afae440e29c388174f2bf
MD5 1ff2d96aa8c17557a3f3d46e758d9f9c
BLAKE2b-256 6045732c9d8a50c23ce75309c44aea56bd0bf6f3edd2c7b184424c209f199fed

See more details on using hashes here.

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