Registry / devops / twitchapi

twitchapi

JSON →
library4.5.0pypypi✓ verified 84d ago

A Python 3.7+ implementation of the Twitch Helix API, EventSub and Chat. This library provides async and sync interfaces for Twitch API endpoints, including authentication, events, and chat bots. Current version 4.5.0 is stable but has significant breaking changes from v3. The project is actively maintained with regular releases.

pip install twitchapi
INSTALL
IMPORT
SIG · TWITCHAPI
T
twitchapi
devopspythonv4.5.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Twitch
from twitchAPI.twitch import Twitch
from twitchapi import Twitch
Direct import from twitchapi is deprecated; use submodule twitchAPI.twitch
TwitchClientCredentials
from twitchAPI.oauth import TwitchClientCredentials
from twitchAPI.auth import TwitchClientCredentials
OAuth classes moved to twitchAPI.oauth

Initialize Twitch client with app credentials and fetch a user

import asyncio from twitchAPI.twitch import Twitch from twitchAPI.oauth import TwitchClientCredentials import os async def main(): app_id = os.environ.get('TWITCH_APP_ID', '') app_secret = os.environ.get('TWITCH_APP_SECRET', '') if not app_id or not app_secret: print('Set TWITCH_APP_ID and TWITCH_APP_SECRET environment variables') return creds = TwitchClientCredentials(app_id, app_secret) twitch = Twitch(creds) user = await twitch.get_users(logins=['twitch']) print(user) if __name__ == '__main__': asyncio.run(main())
Debug
Known issues
breakingv4.0+ completely rewrote the API: classes and methods changed. Old v3 code will not work.
fix
Migrate to new class hierarchy: use Twitch from twitchAPI.twitch, TwitchClientCredentials from twitchAPI.oauth, etc.
affects: >=4.0.0
deprecatedSync TwitchClient and TwitchPubSub are deprecated in v4. Use async equivalents.
fix
Use Twitch and EventSub classes instead. For PubSub, use twitchAPI.pubsub.TwitchPubSub (still available but deprecated).
affects: >=4.0.0
gotchaAuthentication objects (TwitchClientCredentials, UserAuthenticator) must be reused; creating new ones every request will hit rate limits.
fix
Store TwitchClientCredentials and Twitch instance as singletons.
affects: all
gotchaApp access tokens expire after 60 days; you must refresh or re-authenticate.
fix
Use TwitchClientCredentials which handles token refresh automatically via the Twitch instance.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'twitchAPI'
Installed twitchapi (v3) but trying to import from twitchAPI (v4). v3 had module name 'twitchapi', v4 uses 'twitchAPI'.
fix
Upgrade to v4: pip install --upgrade twitchapi. Then import from twitchAPI.twitch import Twitch
AttributeError: module 'twitchAPI' has no attribute 'Twitch'
Wrong import path: trying to import Twitch directly from twitchAPI instead of twitchAPI.twitch.
fix
Use: from twitchAPI.twitch import Twitch
TypeError: object can't be used in 'await' expression
Using sync class TwitchClient (deprecated) in an async context.
fix
Use async Twitch class: from twitchAPI.twitch import Twitch. Replace TwitchClient with Twitch.
Upgrade
Version history
4.5.0latest on PyPI · released May 23, 2025
Audit
Dependencies
aiohttpoptionalRequired for async HTTP requests (optional but recommended)
requestsoptionalUsed for sync HTTP calls (fallback if aiohttp not installed)
Agent activity
27 hits · last 30 days
node
24
OpenAI (training)
1
Resources
twitchapi — pip install twitchapi · libregistry