No project description provided
Project description
Bland AI Python Library
The Bland AI Python Library provides convenient access to the Bland AI API from applications written in Python.
The library includes type definitions for all request and response fields, and offers both synchronous and asynchronous clients powered by httpx.
Installation
Add this dependency to your project's build file:
pip install bland
# or
poetry add bland
Usage
Simply import BlandAI
and start making calls to our API.
from blandai import PronunciationObject, SendCall
from blandai.client import BlandAI
client = BlandAI(
api_key="YOUR_API_KEY" # Defaults to your BLAND_API_KEY environment variable
)
client.call(
request=SendCall(
phone_number="29382721828",
task="Would love for you to check out our AI API!",
transfer_list={
"default": "+1234567890",
"sales": "+1234567890",
"support": "+1234567890",
"billing": "+1234567890",
},
model="enhanced",
pronunciation_guide=[
PronunciationObject(
word="API",
pronunciation="A P I",
),
PronunciationObject(
word="AI",
pronunciation="ei ai",
),
],
),
)
Async Client
The SDK also exports an async client so that you can make non-blocking calls to our API.
from blandai import PronunciationObject, SendCall
from blandai.client import BlandAI
client = AsyncBlandAI(
api_key="YOUR_API_KEY" # Defaults to your BLAND_API_KEY environment variable
)
async def main() -> None:
await client.call(
request=SendCall(
phone_number="29382721828",
task="Would love for you to check out our AI API!",
transfer_list={
"default": "+1234567890",
"sales": "+1234567890",
"support": "+1234567890",
"billing": "+1234567890",
},
model="enhanced",
pronunciation_guide=[
PronunciationObject(
word="API",
pronunciation="A P I",
),
PronunciationObject(
word="AI",
pronunciation="ei ai",
),
],
),
)
asyncio.run(main())
BlandAI Module
All of the models are nested within the BlandAI module. Let IntelliSense guide you!
Exception Handling
All errors thrown by the SDK will be subclasses of ApiError
.
import blandai
try:
client.call(...)
except blandai.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 blandai.client import BlandAI
client = BlandAI(
# All timeouts are 20 seconds
timeout=20.0,
)
# Override timeout for a specific method
client.call(..., {
timeout_in_seconds=20.0
})
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 blandai.client import BlandAI
client = BlandAI(
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 Preview, and there may be breaking changes between versions without a major version update.
To ensure a reproducible environment (and minimize risk of breaking changes), we recommend pinning a specific package version.
Contributing
While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
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 bland-0.3.0.tar.gz
.
File metadata
- Download URL: bland-0.3.0.tar.gz
- Upload date:
- Size: 64.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1061-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 259ea309061c02cc8c29c0d04edcd23701a83c38b36578dcbf6bb5fe5d47bd0d |
|
MD5 | 7f3ba78bc5e57c3ef94f8f895d688c1d |
|
BLAKE2b-256 | ba5268280fe786ee4795afbe57e7d7558b67a01f2be275e6de6493073fd0b1fe |
File details
Details for the file bland-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: bland-0.3.0-py3-none-any.whl
- Upload date:
- Size: 125.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1061-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0ab9fcf0b54339e2c24416f2ab9ee567fe260355ae1a3a87ca1e92a3f0ca93d |
|
MD5 | 7b185c4a2301eaaeba821c358067b6a9 |
|
BLAKE2b-256 | b8e9ac9092e00ed2de30bf1a8b48344af8ddd3c46dc77072454c8da5405bd7c3 |