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.0rc3.tar.gz (34.0 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.0rc3-py3-none-any.whl (76.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: brightbean-1.0.0rc3.tar.gz
  • Upload date:
  • Size: 34.0 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.0rc3.tar.gz
Algorithm Hash digest
SHA256 cc59d258991096bc3ebc594c861187da8c647a16d44e608fc5ef55c1c8259133
MD5 cd8aaf6cd9f124b95f33b983708d17c8
BLAKE2b-256 a7a54b4305d7cb14b087d0473829204a473e85f3cffb5d061ec0a14768c4cbab

See more details on using hashes here.

Provenance

The following attestation bundles were made for brightbean-1.0.0rc3.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.0rc3-py3-none-any.whl.

File metadata

  • Download URL: brightbean-1.0.0rc3-py3-none-any.whl
  • Upload date:
  • Size: 76.2 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.0rc3-py3-none-any.whl
Algorithm Hash digest
SHA256 6866ffe09c5ff436c8e6452fa213b9e0fe6eccf3078b42ce57d61cd823bdff84
MD5 13604b5ac982c1c8b67024f2f7fe35bf
BLAKE2b-256 0021f47afcf5c029dd8f71348270e8a95d65f23cf432773671e4ae18dcd53063

See more details on using hashes here.

Provenance

The following attestation bundles were made for brightbean-1.0.0rc3-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