Skip to main content

Python asynchronous wrapper to get youtube data.

Project description

ytpy

CodeFactor Downloads pypi-version contributions welcome Discord Badge

Python wrapper to extract youtube data. 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
  • aiohttp

Install

pip install --upgrade ytpy

Basic Usage

Search Video by Keywords without api key.

params:

  • q, string. Search key. default: empty string.
  • max_results

Example Search method (Without api key)

from ytpy import YoutubeClient
import asyncio
import aiohttp

async def main(loop):
    session = aiohttp.ClientSession()

    client = YoutubeClient(session)
    
    response = await client.search('chico love letter')
    print(response)

    await session.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))

Search Video by Keywords with YoutubeApiV3Client

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

import os
import asyncio
import aiohttp
from ytpy import YoutubeApiV3Client

async def main(loop):
    session = aiohttp.ClientSession()
    
    # Pass the aiohttp client session
    ayt = YoutubeApiV3Client(session, dev_key=os.environ["DEVELOPER_KEY"])
    
    # test search
    results = await ayt.search(q="d&e lost", 
                               search_type="video",
                               max_results=1)
    print(results)

    await session.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
loop.close()

Examples

Check examples for the full code example

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests/examples as appropriate.

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-2021.1.31.tar.gz (6.7 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