Skip to main content

An asynchronous client for the Chaturbate Events API.

Project description

CB Events

Async Python client for the Chaturbate Events API with real-time event streaming.

PyPI Python License

Installation

$ uv pip install cb-events

Usage

import asyncio
import os
from cb_events import EventClient, EventRouter, EventType, Event

router = EventRouter()

@router.on(EventType.TIP)
async def handle_tip(event: Event) -> None:
    if event.user and event.tip:
        print(f"{event.user.username} tipped {event.tip.tokens} tokens")

@router.on(EventType.CHAT_MESSAGE)
async def handle_chat(event: Event) -> None:
    if event.user and event.message:
        print(f"{event.user.username}: {event.message.message}")

async def main():
    username = os.getenv("CB_USERNAME")
    token = os.getenv("CB_TOKEN")

    async with EventClient(username, token) as client:
        async for event in client:
            await router.dispatch(event)

asyncio.run(main())

Event Types

  • TIP, FANCLUB_JOIN, MEDIA_PURCHASE
  • CHAT_MESSAGE, PRIVATE_MESSAGE
  • USER_ENTER, USER_LEAVE, FOLLOW, UNFOLLOW
  • BROADCAST_START, BROADCAST_STOP, ROOM_SUBJECT_CHANGE

Configuration

Environment variables:

export CB_USERNAME="username"
export CB_TOKEN="api_token"

Direct instantiation:

from cb_events import EventClient, EventClientConfig

client = EventClient("username", "token")

Configuration options (defaults shown):

from cb_events import EventClient, EventClientConfig

client = EventClient(
    username="your_username",
    token="your_api_token",
    config=EventClientConfig(
        timeout=10,              # Timeout for API requests in seconds
        use_testbed=False,       # Use testbed API endpoint
        retry_attempts=8,        # Maximum retry attempts for failed requests
        retry_backoff=1.0,       # Initial backoff time in seconds
        retry_factor=2.0,        # Exponential backoff multiplier
        retry_max_delay=30.0,    # Maximum delay between retries in seconds
    )
)

Note: The config parameter must be passed as a keyword argument.

Error Handling

from cb_events import AuthError, EventsError, RouterError

try:
    async with EventClient(username, token) as client:
        async for event in client:
            await router.dispatch(event)
except AuthError:
    # Authentication failed (401/403)
    pass
except RouterError as e:
    # Handler execution failed
    print(f"Handler '{e.handler_name}' failed on {e.event_type}")
except EventsError as e:
    # API errors (HTTP errors, network issues)
    if e.status_code:
        print(f"API error {e.status_code}: {e.message}")

Handler exceptions are caught, logged, and re-raised as RouterError with context.

Automatic retry on 429, 5xx, and Cloudflare error codes. No retry on authentication errors.

Requirements

  • Python ≥3.11
  • aiohttp, pydantic, aiolimiter
$ uv pip compile pyproject.toml -o requirements.txt

License

MIT licensed. See LICENSE.

Disclaimer

Not affiliated with Chaturbate.

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

cb_events-3.0.2.tar.gz (199.3 kB view details)

Uploaded Source

Built Distribution

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

cb_events-3.0.2-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file cb_events-3.0.2.tar.gz.

File metadata

  • Download URL: cb_events-3.0.2.tar.gz
  • Upload date:
  • Size: 199.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cb_events-3.0.2.tar.gz
Algorithm Hash digest
SHA256 5fe8dca9e8737a65b72545e7c3b2962bcd1c3ba47d2bc31a6ce59c6ae96e1431
MD5 7c50c3129330fbf82226a567cf3bdb13
BLAKE2b-256 5613919c4206eef7424f338a05339b109c6ce407fd707c2f4c25a567a2919ad7

See more details on using hashes here.

Provenance

The following attestation bundles were made for cb_events-3.0.2.tar.gz:

Publisher: ci-cd.yml on MountainGod2/cb-events

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

File details

Details for the file cb_events-3.0.2-py3-none-any.whl.

File metadata

  • Download URL: cb_events-3.0.2-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cb_events-3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0a478d2eead28c4ed23e0fa50b2fb22d9e3e223ad2f3b37e9b0f3d6f70dcf7a6
MD5 481207e84298d0b2ebf3b9aed0224c74
BLAKE2b-256 6b69ad5a1bde22a40302c304abdddee975d95e2b4ac62c673dd1b1f91ec2d454

See more details on using hashes here.

Provenance

The following attestation bundles were made for cb_events-3.0.2-py3-none-any.whl:

Publisher: ci-cd.yml on MountainGod2/cb-events

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