Skip to main content

Async Python client for the Chaturbate Events API.

Project description

CB Events

Async Python client for the Chaturbate Events API.

PyPI Tag Python OpenSSF Best Practices Builds License

Installation

pip install cb-events

With uv:

uv add cb-events

Quick Start

import asyncio
from cb_events import EventClient, Router, EventType, Event

router = Router()

username = "your_username"
token = "your_api_token"

@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")

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

asyncio.run(main())

Generate API token at https://chaturbate.com/statsapi/authtoken/ with Events API scope.

For usage examples, see the examples folder.

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

from cb_events import ClientConfig

config = ClientConfig(
    timeout=10,                   # Request timeout (seconds)
    use_testbed=False,            # Use testbed endpoint with test tokens
    strict_validation=False,      # False skips & logs invalid events; True raises.
    retry_attempts=8,             # Total attempts (initial + retries)
    retry_backoff=1.0,            # Initial backoff (seconds)
    retry_factor=2.0,             # Backoff multiplier
    retry_max_delay=30.0,         # Max retry delay (seconds)
    next_url_allowed_hosts=None,  # None = API host only; list adds extra hosts
)

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

Rate Limiting

Default: 2000 requests/60s per client.

Shared limiter:

from aiolimiter import AsyncLimiter

limiter = AsyncLimiter(max_rate=2000, time_period=60)
client1 = EventClient(username1, token1, rate_limiter=limiter)
client2 = EventClient(username2, token2, rate_limiter=limiter)

Event Properties

event.user          # User object (most events)
event.tip           # Tip object (TIP only)
event.message       # Message object (CHAT_MESSAGE, PRIVATE_MESSAGE)
event.room_subject  # RoomSubject object (ROOM_SUBJECT_CHANGE)
event.broadcaster   # Broadcaster username string

Error Handling

AuthError is a subclass of EventsErrorexcept EventsError catches both. Put AuthError first if you need to distinguish them.

from cb_events import AuthError, EventsError

try:
    async with EventClient(username, token) as client:
        async for event in client:
            await router.dispatch(event)
except AuthError:
    # Authentication failed (401/403) — never retried
    pass
except EventsError as e:
    # All other API/network errors — check e.status_code, e.response_text
    pass

Retries: 429, 5xx, Cloudflare 521-524. Not retriable: 401/403.

Handlers: Sequential execution. Errors logged but don't stop processing.

Logging

import logging

logging.getLogger('cb_events').setLevel(logging.DEBUG)

Requirements

Python 3.10+

License

MIT


Not affiliated with Chaturbate.

Project details


Release history Release notifications | RSS feed

This version

7.0.0

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-7.0.0.tar.gz (259.4 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-7.0.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cb_events-7.0.0.tar.gz
Algorithm Hash digest
SHA256 efe37ecb56d64ad637955d363d45ad3184b85d131f021d78f7e2c6a53add50c2
MD5 7c494a44b9e1b13c35dd6dd334dab702
BLAKE2b-256 69985c71b02b536cdbb4ebde4583b2b1ce2761a1dbffdd72bf7f3326f7a70308

See more details on using hashes here.

Provenance

The following attestation bundles were made for cb_events-7.0.0.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-7.0.0-py3-none-any.whl.

File metadata

  • Download URL: cb_events-7.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 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-7.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec68617ae94beed244bcfce16bc69a136bfcd77c766ed9844c132f12b9d94c55
MD5 516804dc6e1e24c3dd5e70ec97c2b868
BLAKE2b-256 1a4a2b36d85038fb5e8661fafee388488b2a98a3505ba19ef896a10c00df664e

See more details on using hashes here.

Provenance

The following attestation bundles were made for cb_events-7.0.0-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