Skip to main content

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!

Metadata

Release files for bland 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bland 0.3.0
File Size Uploaded
bland-0.3.0.tar.gz 64.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bland 0.3.0
File Interpreter ABI Platform
bland-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 190.2 kB

Release files / bland-0.3.0.tar.gz

Download URL bland-0.3.0.tar.gz
Size 64.2 kB
Tags Source
SHA-256 checksum
How to use checksums
259ea309061c02cc8c29c0d04edcd23701a83c38b36578dcbf6bb5fe5d47bd0d
BLAKE2b-256 checksum
How to use checksums
ba5268280fe786ee4795afbe57e7d7558b67a01f2be275e6de6493073fd0b1fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1061-azure

Release files / bland-0.3.0-py3-none-any.whl

Download URL bland-0.3.0-py3-none-any.whl
Size 125.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e0ab9fcf0b54339e2c24416f2ab9ee567fe260355ae1a3a87ca1e92a3f0ca93d
BLAKE2b-256 checksum
How to use checksums
b8e9ac9092e00ed2de30bf1a8b48344af8ddd3c46dc77072454c8da5405bd7c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1061-azure

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page