SlyYTDAPI

No-boilerplate, async and typed YouTube Data API access.


Keywords
youtube
License
Other
Install
pip install SlyYTDAPI==0.3.1

Documentation

sly logo Sly YouTube Data API for Python

🚧 This library is an early work in progress! Breaking changes may be frequent.

🐍 For Python 3.10+

No-boilerplate, async and typed YouTube Data API access. 😋

pip install slyytdapi

This library does not have full coverage. All methods are read-only. Currently, the following topics are supported:

  • Videos
  • Channels
  • Comment threads
  • Video search
  • Channel members (requires approval from YouTube)

For collecting statistics about your own channel using the YouTube analytics API, see YTAAPI.


Example usage:

import asyncio
from SlyYTDAPI import *

async def main():
    # don't forget to keep your secrets secret!
    yt = YouTubeData(open('api_key.txt').read())

    my_video = await yt.video('dQw4w9WgXcQ')
    print(F"Check this out!\n{my_video.link()}")

    # keep it simple
    _ = await my_video.comments(limit=10) # list[Comment]

    # or opt in to generators
    print('\n---\n'.join([
        F"{c.author_name} > {c.body}"
        async for c in my_video.comments(limit=10)
    ]))
    
asyncio.run(main())

Example CLI usage for getting authorized:

# WINDOWS
py -m SlyYTDAPI grant
# MacOS or Linux
python3 -m SlyYTDAPI grant

Granting credentials requires a Google Cloud Console account and JSON file. Please see https://docs.dunkyl.net/SlyAPI-Python/tutorial/oauth2.html for more information.