No project description provided
Project description
Credal Python SDK
The Credal Python Library provides convenient access to the Credal API from applications written in Python.
Documentation
Docs for the API endpoints available through the SDK can be found here.
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="ravin@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:
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"),
),
)
Beta Status
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning the package version to a specific version. This way, you can install the same version each time without breaking changes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file credal-0.0.4.tar.gz
.
File metadata
- Download URL: credal-0.0.4.tar.gz
- Upload date:
- Size: 24.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1064-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d8891377431a8108f02fc16a69a793e2f703e142c3778cd67161a4ae8e2e2d3 |
|
MD5 | fe95aee3bd5d60d6fa165341099cefa0 |
|
BLAKE2b-256 | 44f7cab1c2da9b06519a668f4d340a865305253639a3468e886e7343fbcf6b15 |
File details
Details for the file credal-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: credal-0.0.4-py3-none-any.whl
- Upload date:
- Size: 55.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1064-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f60960c8a5330c02328597e556e63eecc93f60e7ac34aa5befb2627784981ae |
|
MD5 | 982eafb9e1f32333e4abdb982c54b406 |
|
BLAKE2b-256 | 6992081a88376b30655e9ffee7af429720dff666b48a1fb2d934df9071c59949 |