TikTokLive.client.web package
Subpackages
- TikTokLive.client.web.routes package
- Submodules
- TikTokLive.client.web.routes.fetch_gift_list module
- TikTokLive.client.web.routes.fetch_image_data module
- TikTokLive.client.web.routes.fetch_is_live module
- TikTokLive.client.web.routes.fetch_room_id_api module
- TikTokLive.client.web.routes.fetch_room_id_live_html module
- TikTokLive.client.web.routes.fetch_room_info module
- TikTokLive.client.web.routes.fetch_signed_websocket module
- TikTokLive.client.web.routes.fetch_video_data module
- TikTokLive.client.web.routes.send_room_chat module
- TikTokLive.client.web.routes.send_room_gift module
- TikTokLive.client.web.routes.send_room_like module
- Module contents
Submodules
TikTokLive.client.web.web_base module
- class TikTokLive.client.web.web_base.ClientRoute(web: TikTokHTTPClient)
Bases:
ABC
A callable API route for TikTok
- class TikTokLive.client.web.web_base.TikTokHTTPClient(web_proxy: Proxy | None = None, httpx_kwargs: dict | None = None, curl_cffi_kwargs: dict | None = None, signer_kwargs: dict | None = None)
Bases:
object
HTTP client for interacting with the various APIs
- async build_request(url: str | URL, method: str, httpx_client: AsyncClient | None = None, extra_params: Dict | None = None, extra_headers: Dict | None = None, base_params: bool = True, base_headers: bool = True, sign_url: bool = False, sign_url_method: str | None = None, **kwargs) Request
BUILD a request to call the httpx client
- Parameters:
url – The URL to request
sign_url – Whether to sign the URL before requesting
method – The HTTP method to use
extra_params – Extra parameters to append to the globals
extra_headers – Extra headers to append to the globals
httpx_client – An optional override for the httpx.AsyncClient client
kwargs – Optional keywords for the httpx.AsyncClient.get method
sign_url_method – The HTTP method to sign with
base_params – Whether to include the base params
base_headers – Whether to include the base headers
- Returns:
An httpx.Response object
- build_url(url: str | URL, extra_params: dict | None = None, base_params: bool = True) URL
- async close() None
Close the HTTP client gracefully
- Returns:
None
- property curl_cffi_client: AsyncSession
Get the underlying curl_cffi.requests.AsyncSession instance
- Returns:
The curl_cffi.requests.AsyncSession instance
- classmethod generate_device_id() int
Generate a spoofed device ID for the TikTok API call
- Returns:
Device ID number
- async get(url: str, extra_params: Dict | None = None, extra_headers: Dict | None = None, http_client: AsyncClient | AsyncSession | None = None, http_backend: Literal['httpx', 'curl_cffi'] = 'httpx', base_params: bool = True, base_headers: bool = True, sign_url: bool = False, **kwargs) Response
- property httpx_client: AsyncClient
Get the underlying httpx.AsyncClient instance
- Returns:
The httpx.AsyncClient instance
- async post(url: str, extra_params: Dict | None = None, extra_headers: Dict | None = None, http_client: AsyncClient | AsyncSession | None = None, http_backend: Literal['httpx', 'curl_cffi'] = 'httpx', base_params: bool = True, base_headers: bool = True, sign_url: bool = False, **kwargs) Response
- async request(url: str, method: str, http_client: AsyncClient | AsyncSession | None = None, http_backend: Literal['httpx', 'curl_cffi'] = 'httpx', extra_params: Dict | None = None, extra_headers: Dict | None = None, base_params: bool = True, base_headers: bool = True, sign_url: bool = False, **kwargs) Response | Response
Request a response from the underlying httpx.AsyncClient client.
- Parameters:
url – The URL to request
sign_url – Whether to sign the URL before requesting
method – The HTTP method to use
http_backend – The backend to use for the request
extra_params – Extra parameters to append to the globals
extra_headers – Extra headers to append to the globals
http_client – An optional override for the httpx.AsyncClient client
kwargs – Optional keywords for the httpx.AsyncClient.get method
base_params – Whether to include the base params
base_headers – Whether to include the base headers
- Returns:
An httpx.Response object
- set_session_id(session_id: str) None
Set the session id cookies for the HTTP client and Websocket connection
- Parameters:
session_id – The (must be valid) session ID
- Returns:
None
- property signer: TikTokSigner
Get the TikTok signer for the HTTP client
- Returns:
The TikTok signer
TikTokLive.client.web.web_client module
- class TikTokLive.client.web.web_client.TikTokWebClient(**kwargs)
Bases:
TikTokHTTPClient
Wrapper for the HTTP client to add web routes
- property fetch_image: FetchImageDataRoute
Return the image data route
- Returns:
The image data route
- property fetch_video: FetchVideoDataRoute
Return the video data route
- Returns:
The video data route
TikTokLive.client.web.web_presets module
- class TikTokLive.client.web.web_presets.DevicePreset
Bases:
TypedDict
- browser_name: str
- browser_platform: str
- browser_version: str
- os: str
- user_agent: str
- class TikTokLive.client.web.web_presets.LocationPreset
Bases:
TypedDict
en style ISO code
- country: str
America/Toronto style TZ name
- lang: str
en-US style ISO code
- lang_country: str
US style ISO code
- tz_name: str
- class TikTokLive.client.web.web_presets.ScreenPreset
Bases:
TypedDict
- screen_height: int
- screen_width: int
- TikTokLive.client.web.web_presets.user_agent_to_device_preset(user_agent: str) DevicePreset
Convert a user agent string to a DevicePreset
- Parameters:
user_agent – The user agent string
TikTokLive.client.web.web_settings module
- TikTokLive.client.web.web_settings.CLIENT_NAME: str = 'ttlive-python'
Whether the curl cffi library is installed
TikTokLive.client.web.web_signer module
API Url for euler sign services
- class TikTokLive.client.web.web_signer.SignData
Bases:
TypedDict
Data for signed URLs
- browserName: str
- browserVersion: str
- signedUrl: str
- userAgent: str
- class TikTokLive.client.web.web_signer.SignResponse
Bases:
TypedDict
Response wrapper from signature server
- code: int
- message: str
- class TikTokLive.client.web.web_signer.TikTokSigner(sign_api_key: str | None = None, sign_api_base: str | None = None)
Bases:
object
Utility to sign any TikTok request using Euler Stream
- property sign_api_key: str | None
API key for signing requests
- async webcast_sign(url: str | URL, method: str) SignResponse
Fetch a signed URL for any /webcast/* route using the Sign Server
- Parameters:
url – The URL to sign
method – The HTTP method to sign with
- Returns:
The signature response