{"id":10293,"library":"tiktokapi","title":"TikTok-Api Python Wrapper","description":"TikTok-Api is an unofficial, asynchronous Python 3 wrapper for interacting with the TikTok API. It leverages Playwright for headless browser automation to bypass bot detection and fetch data. Currently at version 7.3.3, it has a frequent release cadence, often with minor updates, but also introduces significant changes to handle TikTok's evolving anti-bot measures.","status":"active","version":"7.3.3","language":"en","source_language":"en","source_url":"https://github.com/davidteather/tiktok-api","tags":["tiktok","api","wrapper","social media","data scraping","playwright","async"],"install":[{"cmd":"pip install tiktokapi","lang":"bash","label":"Install core library"},{"cmd":"playwright install","lang":"bash","label":"Install Playwright browsers (required)"}],"dependencies":[{"reason":"Required for browser automation to interact with TikTok.","package":"playwright","optional":false},{"reason":"Optional, but highly recommended for advanced proxy management and rotation (introduced in v7.2.0+).","package":"proxyproviders","optional":true}],"imports":[{"symbol":"TikTokApi","correct":"from TikTokApi import TikTokApi"}],"quickstart":{"code":"import asyncio\nfrom TikTokApi import TikTokApi\nimport os\n\nasync def main():\n    # It is highly recommended to provide an ms_token for stability and to bypass some bot detections.\n    # You can get this from your browser's cookies when logged into TikTok.\n    ms_token = os.environ.get(\"TIKTOK_MS_TOKEN\", \"your_ms_token_here\")\n\n    # For development/debugging, you might need to set headless=False to see the browser.\n    # You might also need to install Playwright browsers: `playwright install`.\n    async with TikTokApi(ms_token=ms_token, headless=True) as api:\n        # Create sessions. For more robust usage, consider num_sessions > 1 and proxy_providers.\n        await api.create_sessions(num_sessions=1, sleep_after_for_retry=False)\n\n        print(\"Fetching trending videos...\")\n        async for video in api.trending.videos(count=5):\n            print(f\"Video ID: {video.id}\")\n            print(f\"Author: {video.author.nickname} (@{video.author.unique_id})\")\n            print(f\"Description: {video.desc[:70]}...\")\n            print(f\"Play URL: {video.video.play_addr.uri}\")\n            print(\"-\" * 30)\n            if video.stats:\n                print(f\"  Likes: {video.stats.digg_count}, Comments: {video.stats.comment_count}\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())","lang":"python","description":"This quickstart demonstrates how to fetch trending TikTok videos. It highlights the use of `ms_token` for authentication/stability and the asynchronous nature of the library. Remember to run `playwright install` first."},"warnings":[{"fix":"Update your code to expect and process `Playlist` objects instead of raw dictionaries when calling `user().info`.","message":"The return type of `user().info` changed from an `Iterator[dict]` to an `Iterator[Playlist]` object.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Use a valid `ms_token` (from your browser cookies), configure proxies (especially with `proxyproviders` for v7.2.0+), set `headless=False` during development/debugging, and consider using custom `browser_args` to mimic a real user.","message":"TikTok actively employs bot detection mechanisms. You may receive empty results or encounter `TikTokException` if detected.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure all `TikTokApi` calls are `await`ed and your main script uses `asyncio.run()` or is part of an existing event loop.","message":"The library is exclusively asynchronous, requiring `async/await` syntax and running within an `asyncio` event loop.","severity":"gotcha","affected_versions":"all"},{"fix":"Run `playwright install` in your terminal to download and configure the required browser engines (Chromium, Firefox, WebKit).","message":"After `pip install tiktokapi`, you must also install the necessary Playwright browser binaries.","severity":"gotcha","affected_versions":"all"},{"fix":"Obtain an `ms_token` from your browser's TikTok cookies and pass it to the `TikTokApi` constructor (e.g., `TikTokApi(ms_token='your_token')`).","message":"While the library can sometimes function without it, providing a valid `ms_token` significantly improves stability and success rates, especially for logged-in user data or to bypass frequent bot detection.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install playwright` to install the package.","cause":"The `playwright` package, which is a core dependency, was not installed.","error":"ModuleNotFoundError: No module named 'playwright'"},{"fix":"Run `playwright install` in your terminal to download the required browsers.","cause":"The Playwright package is installed, but the necessary browser binaries (e.g., Chromium) have not been downloaded.","error":"playwright._impl._api_types.Error: No browser was found at specified location"},{"fix":"Wrap your asynchronous `TikTokApi` calls within an `async def` function and execute it using `asyncio.run(your_async_function())`.","cause":"You are attempting to run asynchronous code outside of a properly managed `asyncio` event loop, or the loop has been prematurely closed.","error":"RuntimeError: Event loop is closed"},{"fix":"Ensure you are using a valid, recent `ms_token`. Try `headless=False` for debugging. Consider using proxies and setting `num_sessions` to 1 initially for stability. Check your internet connection.","cause":"TikTok's bot detection likely prevented the browser session from being established, or an invalid/expired `ms_token` was provided.","error":"TikTokApi.exceptions.TikTokException: Failed to create a session"},{"fix":"Implement robust anti-bot strategies: use a valid `ms_token`, integrate with `proxyproviders` (v7.2.0+), try different `browser_args`, and consider adding delays between requests. Reducing `count` in data fetching methods might also help.","cause":"This is often a symptom of TikTok's bot detection or aggressive rate limiting.","error":"Received empty lists or unexpected lack of data from API calls (e.g., `api.trending.videos()` returns nothing)."}]}