Skip to main content

No project description provided

Project description

Bland AI Python Library

fern shield pypi

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!

Alt text

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bland-0.3.0.tar.gz (64.2 kB view hashes)

Uploaded Source

Built Distribution

bland-0.3.0-py3-none-any.whl (125.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page