TikTokLive


NameTikTokLive JSON
Version 6.2.0 PyPI version JSON
download
home_pagehttps://github.com/isaackogan/TikTokLive
SummaryTikTok Live Python Client
upload_time2024-10-21 15:54:17
maintainerNone
docs_urlNone
authorIsaac Kogan
requires_pythonNone
licenseMIT
keywords tiktok tiktok live python3 api unofficial
VCS
bugtrack_url
requirements async-timeout jinja2 python-dotenv
Travis-CI No Travis.
coveralls test coverage No coveralls.
            TikTokLive API
==================
This is an unofficial API wrapper for TikTok LIVE written in Python. With this API you can connect to any TikTok livestream and fetch all data available to users in a stream using just a creator's `@username`.

[![LinkedIn](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white&style=flat-square)](https://www.linkedin.com/in/isaackogan/)
[![LinkedIn](https://www.eulerstream.com/api/pips/patrons?v=002)](https://www.eulerstream.com/)
![Connections](https://tiktok.eulerstream.com/analytics/pips/1)
![Downloads](https://pepy.tech/badge/tiktoklive)
![Stars](https://img.shields.io/github/stars/isaackogan/TikTokLive?style=flat&color=0274b5)
![Forks](https://img.shields.io/github/forks/isaackogan/TikTokLive?style=flat&color=0274b5)
![Issues](https://img.shields.io/github/issues/isaackogan/TikTokLive)

<!-- [![HitCount](https://hits.dwyl.com/isaackogan/TikTokLive.svg?style=flat)](http://hits.dwyl.com/isaackogan/TikTokLive) -->

This API is designed to **retrieve** information from TikTok. It **cannot** be used to **post/upload** LIVE content or comments, to simulate user interaction, or otherwise generate fake traffic. This API does **not** count towards viewers
in a stream. It has **no support** for any **user-authenticated routes**.

## Enterprise Solutions

<table>
<tr>
    <td><br/><img width="180px" style="border-radius: 10px" src="https://raw.githubusercontent.com/isaackogan/TikTokLive/master/.github/SquareLogo.png"><br/><br/></td>
    <td>
        <a href="https://www.eulerstream.com">
            <strong>Euler Stream</strong> is a paid TikTok LIVE service providing managed TikTok LIVE WebSocket connections, increased access, TikTok LIVE alerts, JWT authentication and more.
        </a>
    </td>
</tr>
</table>

## Table of Contents

- [Getting Started](#getting-started)
    - [Parameters](#parameters)
    - [Methods](#methods)
    - [Properties](#properties)
    - [WebDefaults](#webdefaults)
- [Documentation](https://isaackogan.github.io/TikTokLive/)
- [Other Languages](#other-languages)
- [Community](#community)
- [Examples](https://github.com/isaackogan/TikTokLive/tree/master/examples)
- [Licensing](#license)
- [Contributors](#contributors)

## Community

Join the [TikTokLive discord](https://discord.gg/e2XwPNTBBr) and visit
the [`#py-support`](https://discord.gg/uja6SajDxd)
channel for questions, contributions and ideas.

## Getting Started

1. Install the module via pip from the [PyPi](https://pypi.org/project/TikTokLive/) repository

```shell script
pip install TikTokLive
```

2. Create your first chat connection

```python
from TikTokLive import TikTokLiveClient
from TikTokLive.events import ConnectEvent, CommentEvent

# Create the client
client: TikTokLiveClient = TikTokLiveClient(unique_id="@isaackogz")


# Listen to an event with a decorator!
@client.on(ConnectEvent)
async def on_connect(event: ConnectEvent):
    print(f"Connected to @{event.unique_id} (Room ID: {client.room_id}")


# Or, add it manually via "client.add_listener()"
async def on_comment(event: CommentEvent) -> None:
    print(f"{event.user.nickname} -> {event.comment}")


client.add_listener(CommentEvent, on_comment)

if __name__ == '__main__':
    # Run the client and block the main thread
    # await client.start() to run non-blocking
    client.run()
```

For more quickstart examples, see the [examples folder](https://github.com/isaackogan/TikTokLive/tree/master/examples)
provided in the source tree.

## Other Languages

TikTokLive is available in several alternate programming languages:

- **Node.JS:** [https://github.com/zerodytrash/TikTok-Live-Connector](https://github.com/zerodytrash/TikTok-Live-Connector)
- **Java:** [https://github.com/jwdeveloper/TikTok-Live-Java](https://github.com/jwdeveloper/TikTok-Live-Java)
- **C#/Unity:** [https://github.com/frankvHoof93/TikTokLiveSharp](https://github.com/frankvHoof93/TikTokLiveSharp)
- **Go:** [https://github.com/steampoweredtaco/gotiktoklive](https://github.com/steampoweredtaco/gotiktoklive)
- **Rust:** [https://github.com/jwdeveloper/TikTokLiveRust](https://github.com/jwdeveloper/TikTokLiveRust)

## Parameters

| Param Name | Required | Default | Description                                                                                                                                                                                                               |
|------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| unique_id  | Yes      | N/A     | The unique username of the broadcaster. You can find this name in the URL of the user. For example, the `unique_id` for [`https://www.tiktok.com/@isaackogz`](https://www.tiktok.com/@isaackogz) would be `isaackogz`.    |
| web_proxy  | No       | `None`  | TikTokLive supports proxying HTTP requests. This parameter accepts an `httpx.Proxy`. Note that if you do use a proxy you may be subject to reduced connection limits at times of high load.                               |
| ws_proxy   | No       | `None`  | TikTokLive supports proxying the websocket connection. This parameter accepts an `httpx.Proxy`. Using this proxy will never be subject to reduced connection limits.                                                      |
| web_kwargs | No       | `{}`    | Under the scenes, the TikTokLive HTTP client uses the [`httpx`](https://github.com/encode/httpx) library. Arguments passed to `web_kwargs` will be forward the the underlying HTTP client.                                |
| ws_kwargs  | No       | `{}`    | Under the scenes, TikTokLive uses the [`websockets`](https://github.com/python-websockets/websockets) library to connect to TikTok. Arguments passed to `ws_kwargs` will be forwarded to the underlying WebSocket client. |

## Methods

A `TikTokLiveClient` object contains the following important methods:

| Method Name  | Notes   | Description                                                                                                                                                                     |
|--------------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| run          | N/A     | Connect to the livestream and block the main thread. This is best for small scripts.                                                                                            |
| add_listener | N/A     | Adds an *asynchronous* listener function (or, you can decorate a function with `@client.on(<event>)`) and takes two parameters, an event name and the payload, an AbstractEvent ||
| connect      | `async` | Connects to the tiktok live chat while blocking the current future. When the connection ends (e.g. livestream is over), the future is released.                                 |
| start        | `async` | Connects to the live chat without blocking the main thread. This returns an `asyncio.Task` object with the client loop.                                                         |
| disconnect   | `async` | Disconnects the client from the websocket gracefully, processing remaining events before ending the client loop.                                                                |

## Properties

A `TikTokLiveClient` object contains the following important properties:

| Attribute Name | Description                                                                                                                                                 |
|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
| room_id        | The Room ID of the livestream room the client is currently connected to.                                                                                    |
| web            | The TikTok HTTP client. This client has a lot of useful routes you should explore!                                                                          |
| connected      | Whether you are currently connected to the livestream.                                                                                                      |
| logger         | The internal logger used by TikTokLive. You can use `client.logger.setLevel(...)` method to enable client debug.                                            |
| room_info      | Room information that is retrieved from TikTok when you use a connection method (e.g. `client.connect`) with the keyword argument `fetch_room_info=True` .  |
| gift_info      | Extra gift information that is retrieved from TikTok when you use a connection method (e.g. `client.run`) with the keyword argument `fetch_gift_info=True`. |

## WebDefaults

TikTokLive has a series of global defaults used to create the HTTP client which you can customize. For info on how to set these parameters, see
the [web_defaults.py](https://github.com/isaackogan/TikTokLive/blob/master/examples/web_defaults.py) example.

| Parameter           | Type   | Description                                                                                            |
|---------------------|--------|--------------------------------------------------------------------------------------------------------|
| tiktok_app_url      | `str`  | The TikTok app URL (`https://www.tiktok.com`) used to scrape the room.                                 |
| tiktok_sign_url     | `str`  | The [signature server](https://www.eulerstream.com/) used to generate tokens to connect to TikTokLive. |
| tiktok_webcast_url  | `str`  | The TikTok livestream URL (`https://webcast.tiktok.com`) where livestreams can be accessed from.       |
| client_params       | `dict` | The URL parameters added on to TikTok requests from the HTTP client.                                   |
| client_ws_params    | `dict` | The URL parameters added to the URI when connecting to TikTok's Webcast WebSocket server.              |
| client_headers      | `dict` | The headers added on to TikTok requests from the HTTP client.                                          |
| tiktok_sign_api_key | `str`  | A global way of setting the `sign_api_key` parameter.                                                  |

## Events

Events can be listened to using a decorator or non-decorator method call. The following examples illustrate how you can listen to an event:

```python
@client.on(LikeEvent)
async def on_like(event: LikeEvent) -> None:
    ...


async def on_comment(event: CommentEvent) -> None:
    ...


client.add_listener(CommentEvent, on_comment)
```

There are two types of events, [`CustomEvent`](https://github.com/isaackogan/TikTokLive/blob/master/TikTokLive/events/custom_events.py)
events and [`ProtoEvent`](https://github.com/isaackogan/TikTokLive/blob/master/TikTokLive/events/proto_events.py) events.
Both belong to the TikTokLive `Event` type and can be listened to. The following events are available:

### Custom Events

- `ConnectEvent` - Triggered when the Webcast connection is initiated
- `DisconnectEvent` - Triggered when the Webcast connection closes (including the livestream ending)
- `LiveEndEvent` - Triggered when the livestream ends
- `LivePauseEvent` - Triggered when the livestream is paused
- `LiveUnpauseEvent` - Triggered when the livestream is unpaused
- `FollowEvent` - Triggered when a user in the livestream follows the streamer
- `ShareEvent` - Triggered when a user shares the livestream
- `WebsocketResponseEvent` - Triggered when any event is received (contains the event)
- `UnknownEvent` - An instance of `WebsocketResponseEvent` thrown whenever an event does not have an existing definition, useful for debugging

### Proto Events

If you know what an event does, [make a pull request](https://github.com/isaackogan/TikTokLive/pulls) and add the description.

- `GiftEvent` - Triggered when a gift is sent to the streamer
- `GoalUpdateEvent` - Triggered when the subscriber goal is updated
- `ControlEvent` - Triggered when a stream action occurs (e.g. Livestream start, end)
- `LikeEvent` - Triggered when the stream receives a like
- `SubscribeEvent` - Triggered when someone subscribes to the TikTok creator
- `PollEvent` - Triggered when the creator launches a new poll
- `CommentEvent` - Triggered when a comment is sent in the stream
- `RoomEvent` - Messages broadcasted to all users in the room (e.g. "Welcome to TikTok LIVE!")
- `EmoteChatEvent` - Triggered when a custom emote is sent in the chat
- `EnvelopeEvent` - Triggered every time someone sends a treasure chest
- `SocialEvent` - Triggered when a user shares the stream or follows the host
- `QuestionNewEvent` - Triggered every time someone asks a new question via the question feature.
- `LiveIntroEvent` - Triggered when a live intro message appears
- `LinkMicArmiesEvent` - Triggered when a TikTok battle user receives points
- `LinkMicBattleEvent` - Triggered when a TikTok battle is started
- `JoinEvent` - Triggered when a user joins the livestream
- `LinkMicFanTicketMethodEvent`
- `LinkMicMethodEvent`
- `BarrageEvent`
- `CaptionEvent`
- `ImDeleteEvent`
- `RoomUserSeqEvent` - Current viewer count information
- `RankUpdateEvent`
- `RankTextEvent`
- `HourlyRankEvent`
- `UnauthorizedMemberEvent`
- `MessageDetectEvent`
- `OecLiveShoppingEvent`
- `RoomPinEvent`
- `SystemEvent`
- `LinkEvent`
- `LinkLayerEvent`

### Special Events

### `GiftEvent`

Triggered every time a gift arrives. Extra information can be gleamed from the `available_gifts` client attribute.
> **NOTE:** Users have the capability to send gifts in a streak. This increases the `event.gift.repeat_count` value until the
> user terminates the streak. During this time new gift events are triggered again and again with an
> increased `event.gift.repeat_count` value. It should be noted that after the end of a streak, a final gift event is
> triggered, which signals the end of the streak with `event.repeat_end`:`1`. The following handlers show how you can deal with this in your code.

Using the low-level direct proto:

```python
@client.on(GiftEvent)
async def on_gift(event: GiftEvent):
    # If it's type 1 and the streak is over
    if event.gift.info.type == 1:
        if event.gift.is_repeating == 1:
            print(f"{event.user.unique_id} sent {event.repeat_count}x \"{event.gift.name}\"")

    # It's not type 1, which means it can't have a streak & is automatically over
    elif event.gift.info.type != 1:
        print(f"{event.user.unique_id} sent \"{event.gift.name}\"")
```

Using the TikTokLive extended proto:

```python
@client.on("gift")
async def on_gift(event: GiftEvent):
    # Streakable gift & streak is over
    if event.gift.streakable and not event.streaking:
        print(f"{event.user.unique_id} sent {event.repeat_count}x \"{event.gift.name}\"")

    # Non-streakable gift
    elif not event.gift.streakable:
        print(f"{event.user.unique_id} sent \"{event.gift.name}\"")
```

### `SubscribeEvent`

This event will only fire when a session ID (account login) is passed to the HTTP client *before* connecting to TikTok LIVE.
You can set the session ID with [`client.web.set_session_id(...)`](https://github.com/isaackogan/TikTokLive/blob/master/examples/logged_in.py).

## Checking If A User Is Live

It is considered inefficient to use the connect method to check if a user is live. It is better to use the dedicated `await client.is_live()` method.

There is a [complete example](https://github.com/isaackogan/TikTokLive/blob/master/examples/check_live.py) of how to do this in the [examples](https://github.com/isaackogan/TikTokLive/tree/master/examples) folder.

## Contributors

* **Isaac Kogan** - *Creator, Primary Maintainer, and Reverse-Engineering* - [isaackogan](https://github.com/isaackogan)
* **Zerody** - *Initial Reverse-Engineering Protobuf & Support* - [Zerody](https://github.com/zerodytrash/)
* **Davincible** - *Reverse-Engineering Stream Downloads*  - [davincible](https://github.com/davincible)

See also the full list of [contributors](https://github.com/isaackogan/TikTokLive/contributors) who have participated in
this project.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/isaackogan/TikTokLive",
    "name": "TikTokLive",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "tiktok, tiktok live, python3, api, unofficial",
    "author": "Isaac Kogan",
    "author_email": "info@isaackogan.com",
    "download_url": "https://files.pythonhosted.org/packages/7c/d1/454effd508d0a546b22a135e3dcd5da58d605893e52be415a509476bc5b5/tiktoklive-6.2.0.tar.gz",
    "platform": null,
    "description": "TikTokLive API\n==================\nThis is an unofficial API wrapper for TikTok LIVE written in Python. With this API you can connect to any TikTok livestream and fetch all data available to users in a stream using just a creator's `@username`.\n\n[![LinkedIn](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white&style=flat-square)](https://www.linkedin.com/in/isaackogan/)\n[![LinkedIn](https://www.eulerstream.com/api/pips/patrons?v=002)](https://www.eulerstream.com/)\n![Connections](https://tiktok.eulerstream.com/analytics/pips/1)\n![Downloads](https://pepy.tech/badge/tiktoklive)\n![Stars](https://img.shields.io/github/stars/isaackogan/TikTokLive?style=flat&color=0274b5)\n![Forks](https://img.shields.io/github/forks/isaackogan/TikTokLive?style=flat&color=0274b5)\n![Issues](https://img.shields.io/github/issues/isaackogan/TikTokLive)\n\n<!-- [![HitCount](https://hits.dwyl.com/isaackogan/TikTokLive.svg?style=flat)](http://hits.dwyl.com/isaackogan/TikTokLive) -->\n\nThis API is designed to **retrieve** information from TikTok. It **cannot** be used to **post/upload** LIVE content or comments, to simulate user interaction, or otherwise generate fake traffic. This API does **not** count towards viewers\nin a stream. It has **no support** for any **user-authenticated routes**.\n\n## Enterprise Solutions\n\n<table>\n<tr>\n    <td><br/><img width=\"180px\" style=\"border-radius: 10px\" src=\"https://raw.githubusercontent.com/isaackogan/TikTokLive/master/.github/SquareLogo.png\"><br/><br/></td>\n    <td>\n        <a href=\"https://www.eulerstream.com\">\n            <strong>Euler Stream</strong> is a paid TikTok LIVE service providing managed TikTok LIVE WebSocket connections, increased access, TikTok LIVE alerts, JWT authentication and more.\n        </a>\n    </td>\n</tr>\n</table>\n\n## Table of Contents\n\n- [Getting Started](#getting-started)\n    - [Parameters](#parameters)\n    - [Methods](#methods)\n    - [Properties](#properties)\n    - [WebDefaults](#webdefaults)\n- [Documentation](https://isaackogan.github.io/TikTokLive/)\n- [Other Languages](#other-languages)\n- [Community](#community)\n- [Examples](https://github.com/isaackogan/TikTokLive/tree/master/examples)\n- [Licensing](#license)\n- [Contributors](#contributors)\n\n## Community\n\nJoin the [TikTokLive discord](https://discord.gg/e2XwPNTBBr) and visit\nthe [`#py-support`](https://discord.gg/uja6SajDxd)\nchannel for questions, contributions and ideas.\n\n## Getting Started\n\n1. Install the module via pip from the [PyPi](https://pypi.org/project/TikTokLive/) repository\n\n```shell script\npip install TikTokLive\n```\n\n2. Create your first chat connection\n\n```python\nfrom TikTokLive import TikTokLiveClient\nfrom TikTokLive.events import ConnectEvent, CommentEvent\n\n# Create the client\nclient: TikTokLiveClient = TikTokLiveClient(unique_id=\"@isaackogz\")\n\n\n# Listen to an event with a decorator!\n@client.on(ConnectEvent)\nasync def on_connect(event: ConnectEvent):\n    print(f\"Connected to @{event.unique_id} (Room ID: {client.room_id}\")\n\n\n# Or, add it manually via \"client.add_listener()\"\nasync def on_comment(event: CommentEvent) -> None:\n    print(f\"{event.user.nickname} -> {event.comment}\")\n\n\nclient.add_listener(CommentEvent, on_comment)\n\nif __name__ == '__main__':\n    # Run the client and block the main thread\n    # await client.start() to run non-blocking\n    client.run()\n```\n\nFor more quickstart examples, see the [examples folder](https://github.com/isaackogan/TikTokLive/tree/master/examples)\nprovided in the source tree.\n\n## Other Languages\n\nTikTokLive is available in several alternate programming languages:\n\n- **Node.JS:** [https://github.com/zerodytrash/TikTok-Live-Connector](https://github.com/zerodytrash/TikTok-Live-Connector)\n- **Java:** [https://github.com/jwdeveloper/TikTok-Live-Java](https://github.com/jwdeveloper/TikTok-Live-Java)\n- **C#/Unity:** [https://github.com/frankvHoof93/TikTokLiveSharp](https://github.com/frankvHoof93/TikTokLiveSharp)\n- **Go:** [https://github.com/steampoweredtaco/gotiktoklive](https://github.com/steampoweredtaco/gotiktoklive)\n- **Rust:** [https://github.com/jwdeveloper/TikTokLiveRust](https://github.com/jwdeveloper/TikTokLiveRust)\n\n## Parameters\n\n| Param Name | Required | Default | Description                                                                                                                                                                                                               |\n|------------|----------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| unique_id  | Yes      | N/A     | The unique username of the broadcaster. You can find this name in the URL of the user. For example, the `unique_id` for [`https://www.tiktok.com/@isaackogz`](https://www.tiktok.com/@isaackogz) would be `isaackogz`.    |\n| web_proxy  | No       | `None`  | TikTokLive supports proxying HTTP requests. This parameter accepts an `httpx.Proxy`. Note that if you do use a proxy you may be subject to reduced connection limits at times of high load.                               |\n| ws_proxy   | No       | `None`  | TikTokLive supports proxying the websocket connection. This parameter accepts an `httpx.Proxy`. Using this proxy will never be subject to reduced connection limits.                                                      |\n| web_kwargs | No       | `{}`    | Under the scenes, the TikTokLive HTTP client uses the [`httpx`](https://github.com/encode/httpx) library. Arguments passed to `web_kwargs` will be forward the the underlying HTTP client.                                |\n| ws_kwargs  | No       | `{}`    | Under the scenes, TikTokLive uses the [`websockets`](https://github.com/python-websockets/websockets) library to connect to TikTok. Arguments passed to `ws_kwargs` will be forwarded to the underlying WebSocket client. |\n\n## Methods\n\nA `TikTokLiveClient` object contains the following important methods:\n\n| Method Name  | Notes   | Description                                                                                                                                                                     |\n|--------------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| run          | N/A     | Connect to the livestream and block the main thread. This is best for small scripts.                                                                                            |\n| add_listener | N/A     | Adds an *asynchronous* listener function (or, you can decorate a function with `@client.on(<event>)`) and takes two parameters, an event name and the payload, an AbstractEvent ||\n| connect      | `async` | Connects to the tiktok live chat while blocking the current future. When the connection ends (e.g. livestream is over), the future is released.                                 |\n| start        | `async` | Connects to the live chat without blocking the main thread. This returns an `asyncio.Task` object with the client loop.                                                         |\n| disconnect   | `async` | Disconnects the client from the websocket gracefully, processing remaining events before ending the client loop.                                                                |\n\n## Properties\n\nA `TikTokLiveClient` object contains the following important properties:\n\n| Attribute Name | Description                                                                                                                                                 |\n|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| room_id        | The Room ID of the livestream room the client is currently connected to.                                                                                    |\n| web            | The TikTok HTTP client. This client has a lot of useful routes you should explore!                                                                          |\n| connected      | Whether you are currently connected to the livestream.                                                                                                      |\n| logger         | The internal logger used by TikTokLive. You can use `client.logger.setLevel(...)` method to enable client debug.                                            |\n| room_info      | Room information that is retrieved from TikTok when you use a connection method (e.g. `client.connect`) with the keyword argument `fetch_room_info=True` .  |\n| gift_info      | Extra gift information that is retrieved from TikTok when you use a connection method (e.g. `client.run`) with the keyword argument `fetch_gift_info=True`. |\n\n## WebDefaults\n\nTikTokLive has a series of global defaults used to create the HTTP client which you can customize. For info on how to set these parameters, see\nthe [web_defaults.py](https://github.com/isaackogan/TikTokLive/blob/master/examples/web_defaults.py) example.\n\n| Parameter           | Type   | Description                                                                                            |\n|---------------------|--------|--------------------------------------------------------------------------------------------------------|\n| tiktok_app_url      | `str`  | The TikTok app URL (`https://www.tiktok.com`) used to scrape the room.                                 |\n| tiktok_sign_url     | `str`  | The [signature server](https://www.eulerstream.com/) used to generate tokens to connect to TikTokLive. |\n| tiktok_webcast_url  | `str`  | The TikTok livestream URL (`https://webcast.tiktok.com`) where livestreams can be accessed from.       |\n| client_params       | `dict` | The URL parameters added on to TikTok requests from the HTTP client.                                   |\n| client_ws_params    | `dict` | The URL parameters added to the URI when connecting to TikTok's Webcast WebSocket server.              |\n| client_headers      | `dict` | The headers added on to TikTok requests from the HTTP client.                                          |\n| tiktok_sign_api_key | `str`  | A global way of setting the `sign_api_key` parameter.                                                  |\n\n## Events\n\nEvents can be listened to using a decorator or non-decorator method call. The following examples illustrate how you can listen to an event:\n\n```python\n@client.on(LikeEvent)\nasync def on_like(event: LikeEvent) -> None:\n    ...\n\n\nasync def on_comment(event: CommentEvent) -> None:\n    ...\n\n\nclient.add_listener(CommentEvent, on_comment)\n```\n\nThere are two types of events, [`CustomEvent`](https://github.com/isaackogan/TikTokLive/blob/master/TikTokLive/events/custom_events.py)\nevents and [`ProtoEvent`](https://github.com/isaackogan/TikTokLive/blob/master/TikTokLive/events/proto_events.py) events.\nBoth belong to the TikTokLive `Event` type and can be listened to. The following events are available:\n\n### Custom Events\n\n- `ConnectEvent` - Triggered when the Webcast connection is initiated\n- `DisconnectEvent` - Triggered when the Webcast connection closes (including the livestream ending)\n- `LiveEndEvent` - Triggered when the livestream ends\n- `LivePauseEvent` - Triggered when the livestream is paused\n- `LiveUnpauseEvent` - Triggered when the livestream is unpaused\n- `FollowEvent` - Triggered when a user in the livestream follows the streamer\n- `ShareEvent` - Triggered when a user shares the livestream\n- `WebsocketResponseEvent` - Triggered when any event is received (contains the event)\n- `UnknownEvent` - An instance of `WebsocketResponseEvent` thrown whenever an event does not have an existing definition, useful for debugging\n\n### Proto Events\n\nIf you know what an event does, [make a pull request](https://github.com/isaackogan/TikTokLive/pulls) and add the description.\n\n- `GiftEvent` - Triggered when a gift is sent to the streamer\n- `GoalUpdateEvent` - Triggered when the subscriber goal is updated\n- `ControlEvent` - Triggered when a stream action occurs (e.g. Livestream start, end)\n- `LikeEvent` - Triggered when the stream receives a like\n- `SubscribeEvent` - Triggered when someone subscribes to the TikTok creator\n- `PollEvent` - Triggered when the creator launches a new poll\n- `CommentEvent` - Triggered when a comment is sent in the stream\n- `RoomEvent` - Messages broadcasted to all users in the room (e.g. \"Welcome to TikTok LIVE!\")\n- `EmoteChatEvent` - Triggered when a custom emote is sent in the chat\n- `EnvelopeEvent` - Triggered every time someone sends a treasure chest\n- `SocialEvent` - Triggered when a user shares the stream or follows the host\n- `QuestionNewEvent` - Triggered every time someone asks a new question via the question feature.\n- `LiveIntroEvent` - Triggered when a live intro message appears\n- `LinkMicArmiesEvent` - Triggered when a TikTok battle user receives points\n- `LinkMicBattleEvent` - Triggered when a TikTok battle is started\n- `JoinEvent` - Triggered when a user joins the livestream\n- `LinkMicFanTicketMethodEvent`\n- `LinkMicMethodEvent`\n- `BarrageEvent`\n- `CaptionEvent`\n- `ImDeleteEvent`\n- `RoomUserSeqEvent` - Current viewer count information\n- `RankUpdateEvent`\n- `RankTextEvent`\n- `HourlyRankEvent`\n- `UnauthorizedMemberEvent`\n- `MessageDetectEvent`\n- `OecLiveShoppingEvent`\n- `RoomPinEvent`\n- `SystemEvent`\n- `LinkEvent`\n- `LinkLayerEvent`\n\n### Special Events\n\n### `GiftEvent`\n\nTriggered every time a gift arrives. Extra information can be gleamed from the `available_gifts` client attribute.\n> **NOTE:** Users have the capability to send gifts in a streak. This increases the `event.gift.repeat_count` value until the\n> user terminates the streak. During this time new gift events are triggered again and again with an\n> increased `event.gift.repeat_count` value. It should be noted that after the end of a streak, a final gift event is\n> triggered, which signals the end of the streak with `event.repeat_end`:`1`. The following handlers show how you can deal with this in your code.\n\nUsing the low-level direct proto:\n\n```python\n@client.on(GiftEvent)\nasync def on_gift(event: GiftEvent):\n    # If it's type 1 and the streak is over\n    if event.gift.info.type == 1:\n        if event.gift.is_repeating == 1:\n            print(f\"{event.user.unique_id} sent {event.repeat_count}x \\\"{event.gift.name}\\\"\")\n\n    # It's not type 1, which means it can't have a streak & is automatically over\n    elif event.gift.info.type != 1:\n        print(f\"{event.user.unique_id} sent \\\"{event.gift.name}\\\"\")\n```\n\nUsing the TikTokLive extended proto:\n\n```python\n@client.on(\"gift\")\nasync def on_gift(event: GiftEvent):\n    # Streakable gift & streak is over\n    if event.gift.streakable and not event.streaking:\n        print(f\"{event.user.unique_id} sent {event.repeat_count}x \\\"{event.gift.name}\\\"\")\n\n    # Non-streakable gift\n    elif not event.gift.streakable:\n        print(f\"{event.user.unique_id} sent \\\"{event.gift.name}\\\"\")\n```\n\n### `SubscribeEvent`\n\nThis event will only fire when a session ID (account login) is passed to the HTTP client *before* connecting to TikTok LIVE.\nYou can set the session ID with [`client.web.set_session_id(...)`](https://github.com/isaackogan/TikTokLive/blob/master/examples/logged_in.py).\n\n## Checking If A User Is Live\n\nIt is considered inefficient to use the connect method to check if a user is live. It is better to use the dedicated `await client.is_live()` method.\n\nThere is a [complete example](https://github.com/isaackogan/TikTokLive/blob/master/examples/check_live.py) of how to do this in the [examples](https://github.com/isaackogan/TikTokLive/tree/master/examples) folder.\n\n## Contributors\n\n* **Isaac Kogan** - *Creator, Primary Maintainer, and Reverse-Engineering* - [isaackogan](https://github.com/isaackogan)\n* **Zerody** - *Initial Reverse-Engineering Protobuf & Support* - [Zerody](https://github.com/zerodytrash/)\n* **Davincible** - *Reverse-Engineering Stream Downloads*  - [davincible](https://github.com/davincible)\n\nSee also the full list of [contributors](https://github.com/isaackogan/TikTokLive/contributors) who have participated in\nthis project.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "TikTok Live Python Client",
    "version": "6.2.0",
    "project_urls": {
        "Download": "https://github.com/isaackogan/TikTokLive/releases/tag/v6.2.0",
        "Homepage": "https://github.com/isaackogan/TikTokLive"
    },
    "split_keywords": [
        "tiktok",
        " tiktok live",
        " python3",
        " api",
        " unofficial"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "567bf81ba972a72e7f17c28e40323f81fbb4bd456af8d297a41c09dbcded939c",
                "md5": "326e243a5d2209025d94deff1b8f33cb",
                "sha256": "5ee76123e8a1a673384945c302cd764ac829afac0883c9ac98de716303ccedbb"
            },
            "downloads": -1,
            "filename": "TikTokLive-6.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "326e243a5d2209025d94deff1b8f33cb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 55725,
            "upload_time": "2024-10-21T15:54:15",
            "upload_time_iso_8601": "2024-10-21T15:54:15.840121Z",
            "url": "https://files.pythonhosted.org/packages/56/7b/f81ba972a72e7f17c28e40323f81fbb4bd456af8d297a41c09dbcded939c/TikTokLive-6.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7cd1454effd508d0a546b22a135e3dcd5da58d605893e52be415a509476bc5b5",
                "md5": "cdc925b18a287482cb8fd632085f1f53",
                "sha256": "8423425ed84ac930131cc0f623e911b3d6b2a06fdfe520a9b23877f6bc825b36"
            },
            "downloads": -1,
            "filename": "tiktoklive-6.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "cdc925b18a287482cb8fd632085f1f53",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 51945,
            "upload_time": "2024-10-21T15:54:17",
            "upload_time_iso_8601": "2024-10-21T15:54:17.016781Z",
            "url": "https://files.pythonhosted.org/packages/7c/d1/454effd508d0a546b22a135e3dcd5da58d605893e52be415a509476bc5b5/tiktoklive-6.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-21 15:54:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "isaackogan",
    "github_project": "TikTokLive",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "async-timeout",
            "specs": [
                [
                    ">=",
                    "4.0.3"
                ]
            ]
        },
        {
            "name": "jinja2",
            "specs": []
        },
        {
            "name": "python-dotenv",
            "specs": []
        }
    ],
    "lcname": "tiktoklive"
}
        
Elapsed time: 0.47425s