Back to articles
Async Video Metadata Pipeline with Python asyncio and aiohttp

Async Video Metadata Pipeline with Python asyncio and aiohttp

via Dev.to Pythonahmet gedik

Async Video Metadata Pipeline with Python asyncio and aiohttp Fetching trending video metadata from 9 regions sequentially takes about 18 seconds. Switching to asyncio with aiohttp drops that to under 3 seconds. Here's the async pipeline I built for TopVideoHub . Why asyncio for YouTube API Calls YouTube Data API calls are I/O-bound — your code spends most of its time waiting for HTTP responses. That's the perfect use case for asyncio : while one coroutine waits for Japan's trending data, another fetches Korea's, another Taiwan's. No OS threads needed. The Core Fetch Coroutine import asyncio import aiohttp import logging from dataclasses import dataclass from typing import Optional logger = logging . getLogger ( __name__ ) REGIONS = [ " JP " , " KR " , " TW " , " SG " , " VN " , " TH " , " HK " , " US " , " GB " ] YOUTUBE_BASE = " https://www.googleapis.com/youtube/v3 " @dataclass class VideoMetadata : video_id : str title : str channel_title : str region : str view_count : int thumbna

Continue reading on Dev.to Python

Opens in a new tab

Read Full Article
6 views

Related Articles