Call the hosted Twitch Scraper Actor from Python using the official apify-client. All code here is client-side — it calls the Actor on the Apify platform.
pip install apify-clientimport os
from apify_client import ApifyClient
client = ApifyClient(os.environ["APIFY_TOKEN"]) # your Apify API token# Sweep the top games for live streams (high volume)
run = client.actor("logiover/twitch-scraper").call(run_input={
"mode": "topStreams",
"gameFanout": 30,
"gameSort": "VIEWER_COUNT",
"maxResults": 500,
})
items = list(client.dataset(run["defaultDatasetId"]).iterate_items())
print(f"Got {len(items)} rows")
print(items[0])run = client.actor("logiover/twitch-scraper").call(run_input={
"mode": "user",
"logins": ["shroud", "pokimane", "xqc", "ninja"],
})
for ch in client.dataset(run["defaultDatasetId"]).iterate_items():
print(f'{ch["displayName"]} — {ch.get("followers")} followers — live: {ch.get("isLive")}')run = client.actor("logiover/twitch-scraper").call(run_input={
"mode": "streamsByGame",
"games": ["VALORANT", "League of Legends", "Just Chatting"],
"maxResults": 1000,
})
streams = list(client.dataset(run["defaultDatasetId"]).iterate_items())
# Rank live streams by current viewers
top = sorted(streams, key=lambda s: s.get("viewersCount") or 0, reverse=True)[:10]
for s in top:
print(f'{s["displayName"]}: {s.get("viewersCount")} — {s.get("title")}')# Top games ranked by viewers
client.actor("logiover/twitch-scraper").call(run_input={
"mode": "topGames",
"gameSort": "VIEWER_COUNT",
"maxResults": 100,
})
# A channel's VODs, newest first
client.actor("logiover/twitch-scraper").call(run_input={
"mode": "videos",
"login": "shroud",
"videoSort": "TIME",
})
# A channel's top clips, last 7 days
client.actor("logiover/twitch-scraper").call(run_input={
"mode": "clips",
"login": "shroud",
"clipPeriod": "LAST_WEEK",
"clipSort": "VIEWS_DESC",
})
# Search channels by keyword
client.actor("logiover/twitch-scraper").call(run_input={
"mode": "search",
"query": "valorant",
"searchIndex": "CHANNEL",
})import pandas as pd
items = list(client.dataset(run["defaultDatasetId"]).iterate_items())
df = pd.DataFrame(items)
df.to_csv("twitch.csv", index=False)
print(df.head())page = client.dataset(run["defaultDatasetId"]).list_items(
fields=["_mode", "login", "displayName", "followers", "liveViewers", "twitchUrl"],
clean=True,
)
print(page.items).call(run_input=...)starts the run and waits for it to finish; use.start(run_input=...)for fire-and-forget.iterate_items()streams the whole dataset without loading it all into memory at once.- Every row carries a
_modefield so multiple modes can be merged into one dataset. - Docs: https://docs.apify.com/api/client/python/