🎯 Smart Proxy Management with ProxyProviders
TikTok-Api now integrates with https://github.com/davidteather/proxyproviders for better proxy rotation and management per-session
Proxy Features:
- 🔄 Smart proxy rotation with algorithms: RoundRobin, Random, First, or custom
- 🌐 Native integration with ProxyProviders package (v0.2.1+)
- 📚 Support for popular providers: Webshare, BrightData, and more
🏭 Custom Session Factories
Full control over browser context and page initialization with custom factory functions.
Factory Features:
- browser_context_factory: Customize browser context creation (e.g., login flows, custom settings)
- page_factory: Customize page creation (e.g., captcha solving, additional stealth measures)
- Perfect for advanced use cases like authentication, captcha handling, or custom browser configurations
Factory Example:
async def my_page_factory(context, **kwargs):
page = await context.new_page()
# Custom initialization (e.g., solve captcha, inject cookies)
await page.goto("https://tiktok.com")
# ... custom logic ...
return page
await api.create_sessions(
num_sessions=3,
page_factory=my_page_factory
)
♻️ Session Stability Improvements
- Automatic session recovery: Sessions auto-recreate on failures (enabled by default via enable_session_recovery=True)
- Dead session cleanup: Prevents memory leaks from failed sessions
- Partial session creation: Use allow_partial_sessions=True to succeed even if some sessions fail (useful with unreliable proxies)
- Robust error handling: Better resilience for production environments
🔍 Search Improvements
- Added search_type=item parameter to search API for item-specific searches
🚀 Quick Example
from TikTokApi import TikTokApi
from proxyproviders import Webshare
from proxyproviders.algorithms import RoundRobin
provider = Webshare(api_key="your-api-key")
async with TikTokApi() as api:
await api.create_sessions(
num_sessions=5,
proxy_provider=provider,
proxy_algorithm=RoundRobin(),
ms_tokens=['token1', 'token2'],
enable_session_recovery=True, # Auto-recover failed sessions
allow_partial_sessions=True # Don't fail if some sessions fail
)
async for video in api.trending.videos(count=10):
print(video.id)
🔄 Migration Guide
Old way (deprecated):
await api.create_sessions(proxies=[{"server": "..."}, ...])
New way (recommended):
await api.create_sessions(
proxy_provider=provider,
proxy_algorithm=RoundRobin()
)
📝 Full Changelog
- Add ProxyProviders integration with algorithm support
- Add browser_context_factory and page_factory parameters for custom session initialization
- Add session auto-recovery with enable_session_recovery parameter
- Add dead session cleanup to prevent memory leaks
- Add partial session creation with allow_partial_sessions parameter
- Add search_type=item parameter to search API
- Add .DS_Store to .gitignore
- Reorganize page yielding factory documentation and tests
- Update dependencies: proxyproviders>=0.2.1
- Comprehensive test coverage with IP validation
⚠️ Deprecation Notice
The proxies parameter is now deprecated in favor of proxy_provider. It will be removed in v8.0.0.
🔗 Links