Skip to main content

Official Python SDK for the BrightBean API — YouTube packaging scoring.

Project description

brightbean — Python SDK

Official Python SDK for the BrightBean API. Score YouTube packaging (titles, thumbnails, or both) for click-through-rate.

Install

pip install brightbean

Requires Python 3.10+.

Quickstart

from brightbean import BrightBean

with BrightBean(api_key="bb_...") as client:
    result = client.score(
        title="10 Tips to Boost Your Coding Productivity",
        thumbnail_url="https://i.ytimg.com/vi/abc123/maxresdefault.jpg",
    )
    print(f"score={result.score:.2f} percentile={result.percentile}")

Mode is auto-detected on the server. Pass any combination of title, thumbnail_url, and thumbnail_base64:

Inputs Mode Credits
title only "title" 1
thumbnail_url or thumbnail_base64 only "thumbnail" 2
title + thumbnail "combined" 3

Async

import asyncio
from brightbean import AsyncBrightBean

async def main():
    async with AsyncBrightBean(api_key="bb_...") as client:
        return await client.score(title="My epic video")

asyncio.run(main())

Errors

The SDK raises typed exceptions for each documented status code:

Status Exception Notes
400 BadRequestError Validation failed.
401 AuthenticationError Missing, invalid, or expired API key.
402 InsufficientCreditsError Account is out of credits.
429 RateLimitError Too many requests. retry_after (int seconds).
503 ServiceUnavailableError Scoring service down. retry_after (int seconds).
5xx ServerError Other server-side failure.
network NetworkError DNS, connection refused, TLS, timeout.

All API errors inherit BrightBeanAPIError. Network failures raise NetworkError. Both inherit BrightBeanError for catch-all handling.

Retries

Idempotent GETs (me(), usage()) retry automatically on 5xx and network errors with exponential backoff + jitter. Tune via max_retries:

client = BrightBean(api_key="bb_...", max_retries=5)

score() is never auto-retried because it charges credits. Catch RateLimitError or ServiceUnavailableError and back off using retry_after if you need retry semantics.

Configuration

BrightBean(
    api_key="bb_...",                   # required
    base_url="https://api.brightbean.xyz",
    timeout=30.0,                       # seconds, or httpx.Timeout(...)
    max_retries=3,                      # idempotent GETs only
    user_agent=None,                    # override the default UA string
)

Account info

me = client.me()              # plan, credits remaining, period end
usage = client.usage()        # balance + last 20 ledger entries

Development

pip install -e .[dev]
openapi-python-client generate \
    --path ../../openapi.yaml \
    --config generator.yaml \
    --meta=none \
    --output-path ./brightbean/_generated \
    --overwrite
pytest && ruff check . && mypy brightbean

The brightbean/_generated/ directory is regenerated from the upstream OpenAPI spec. The hand-written facade (brightbean/_client.py, brightbean/errors.py, brightbean/__init__.py) wraps it to give the ergonomic BrightBean import shape.

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

brightbean-1.0.0rc1.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

brightbean-1.0.0rc1-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file brightbean-1.0.0rc1.tar.gz.

File metadata

  • Download URL: brightbean-1.0.0rc1.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for brightbean-1.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 e261b7e6a67391e9840328362b65ad6c73a6cf711c66ef7e93d6e560f88e2fb7
MD5 704295b09bf25ccab6ea0fc53c42bfde
BLAKE2b-256 ffe86e4ffdecbfaad811b2fd37f608910f1fefa2eb55d4d2ace7272a5773664d

See more details on using hashes here.

Provenance

The following attestation bundles were made for brightbean-1.0.0rc1.tar.gz:

Publisher: python-release.yml on JanSchm/social-intelligence-app

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file brightbean-1.0.0rc1-py3-none-any.whl.

File metadata

  • Download URL: brightbean-1.0.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for brightbean-1.0.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 6e0491444cbd806f80ab4059b87b0f130be486ab439635862b526cea6333463c
MD5 2718151644280fd18b02345e28a285b6
BLAKE2b-256 d461086687f340c0a8b00e51121adcf6ed13396a9ade2c0ce11eb3e109fb06e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for brightbean-1.0.0rc1-py3-none-any.whl:

Publisher: python-release.yml on JanSchm/social-intelligence-app

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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