Skip to main content

Python asynchronous wrapper for youtube data api v3.

Project description

ytpy

CodeFactor contributions welcome Discord Badge

Python wrapper for youtube data api v3. Simple asynchronous wrapper to get youtube video or playlist data. The purpose of this project is to make it easier for developers to extract data from YouTube.

Requirements

Dependencies

  • urllib
  • asyncio
  • aiohttp

Install

  • Clone project
  • cd to project directory.
  • Run command pip install .

Run Test Code

  • On project root. run command: python ytpy/test/test_import.py

Asynchronous Youtube Service Object

Use AioYoutubeService object for asynchronous tasks. You can pass your api key on dev_key param when building the object or just set your api key on environment variable named DEVELOPER_KEY and AioYoutubeService object will get it for you.

import aiohttp

session = aiohttp.ClientSession()

# will get your api key from environment (named DEVELOPER_KEY).
ayt = AioYoutubeService(session)

# you can also pass it on dev_key param.
ayt = AioYoutubeService(session, dev_key='replace me')

session.close()

Basic Usage: Search Video by Search Key

https://developers.google.com/youtube/v3/docs/search

params:

  • q, string. Search key. default: empty string.
  • part, string. Valid parts: snippet, contentDetails, player, statistics, status. default: snippet.
  • type, string. Valid types: video, playlist, channel.

Example Search method

async def main():
  session = aiohttp.ClientSession()
  
  ayt = AioYoutubeService(session, dev_key='<replace-me>')
  
  # test search
  results = await ayt.search(q="kpop song", search_type="video", max_results=3)
  print(results['items'][0])
  
  session.close()

Example Asynchronous

Check examples/ folder for the full code example

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ytpy-20.9.2020.tar.gz (4.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page