cb_events.models¶
Data models for Chaturbate Events API.
This module defines Pydantic models for deserializing and validating events from the Chaturbate Events API. All models are immutable (frozen) and use camelCase aliases to match the API’s JSON format.
- Model Hierarchy:
BaseEventModel: Base class with shared configuration. Event: Main event container with type and nested data. User: User information attached to events. Message: Chat or private message content. Tip: Tip transaction details. Media: Media purchase information. RoomSubject: Room subject/title changes.
Example
Accessing nested event data:
event = Event.model_validate(api_response)
if event.type == EventType.TIP and event.tip:
print(f"Received {event.tip.tokens} tokens")
if event.user:
print(f"From: {event.user.username}")
Attributes¶
Logger for the cb_events.models module. |
Classes¶
Base model for all event-related data structures. |
|
Event from the Chaturbate Events API. |
|
Event types from the Chaturbate Events API. |
|
Media purchase transaction details. |
|
Chat or private message content. |
|
Room subject or title information. |
|
Tip transaction details. |
|
User information attached to events. |
Module Contents¶
- class cb_events.models.BaseEventModel(/, **data: Any)[source]¶
Bases:
pydantic.BaseModelBase model for all event-related data structures.
Provides shared Pydantic configuration for JSON deserialization with camelCase to snake_case conversion and immutability.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class cb_events.models.Event(/, **data: Any)[source]¶
Bases:
BaseEventModelEvent from the Chaturbate Events API.
The main event container that wraps all event types. Use the typed properties to access nested data safely—they return None if data is missing or invalid for the event type.
Example
Safe access to nested data:
if event.type == EventType.TIP: if tip := event.tip: print(f"Tip: {tip.tokens} tokens") if user := event.user: print(f"From: {user.username}")
Note
Failures to parse nested model data are logged as a warning and return None. Scalar convenience accessors, such as
broadcaster, return None quietly when the value is missing or invalid.Warning
All string fields in event data (e.g.
message.message,user.username,tip.message) originate from untrusted user input and are not sanitized by this library. Escape or validate them before use in HTML, SQL, or shell contexts.Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- property media: Media | None[source]¶
Media purchase data if present and valid (MEDIA_PURCHASE only).
- property room_subject: RoomSubject | None[source]¶
Room subject if present and valid (ROOM_SUBJECT_CHANGE only).
- class cb_events.models.EventType[source]¶
-
Event types from the Chaturbate Events API.
Each member represents a distinct event category that can be received from the API. Use with Router.on() to register type-specific handlers.
Example
Filtering events by type:
@router.on(EventType.TIP) async def handle_tip(event: Event) -> None: print(f"Tip received: {event.tip.tokens}")
Initialize self. See help(type(self)) for accurate signature.
- class cb_events.models.Media(/, **data: Any)[source]¶
Bases:
BaseEventModelMedia purchase transaction details.
Contains information about a media purchase event.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class cb_events.models.Message(/, **data: Any)[source]¶
Bases:
BaseEventModelChat or private message content.
Represents message data from chatMessage and privateMessage events.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class cb_events.models.RoomSubject(/, **data: Any)[source]¶
Bases:
BaseEventModelRoom subject or title information.
Contains the updated room subject from roomSubjectChange events.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class cb_events.models.Tip(/, **data: Any)[source]¶
Bases:
BaseEventModelTip transaction details.
Contains information about a tip event including the amount and optional message.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- class cb_events.models.User(/, **data: Any)[source]¶
Bases:
BaseEventModelUser information attached to events.
Contains details about the user who triggered the event, including display name, membership status, and various flags.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- color_group: str | None = None[source]¶
Color group of the user.
Known values:
"o"(owner),"m"(moderator),"f"(fanclub),"l"(dark purple),"p"(light purple),"tr"(dark blue),"t"(light blue),"g"(grey).
- fc_auto_renew: bool = False[source]¶
Whether the user’s fanclub membership is a recurring subscription.
- gender: str | None = None[source]¶
Gender of the user.
Known values:
"m"(male),"f"(female),"c"(couple),"t"(trans).
- language: str | None = None[source]¶
User’s preferred language.
Known values:
"de"(German),"en"(English),"es"(Spanish),"fr"(French),"it"(Italian),"ja"(Japanese),"ko"(Korean),"pl"(Polish),"pt"(Portuguese),"ru"(Russian),"zh"(Chinese).
- recent_tips: Literal['none', 'few', 'some', 'lots', 'tons'] | None = None[source]¶
How much the user has tipped recently.
Possible values:
"none"(no recent tips, no tokens — grey username),"few"(few or no recent tips, has tokens — light blue),"some"(some recent tips — dark blue),"lots"(lots — purple),"tons"(tons — dark purple).Note
The value
"none"is truthy. Compare explicitly withrecent_tips is None(field absent) versusrecent_tips == "none"(present but no tips).