An asynchronous python API wrapper for the YouTube Data API. Note, this repository and package is now archived. There are no guarantees the code and information is up to date.
- Full coverage of all functionality in the YouTube Data API reference guide.
- Naming convention that matches official documentation.
- Option to enable debugging feature.
- Utilizes
async
andawait
python syntax.
pip install aioyoutube.py
- Access the Google API console with a google account.
- Create a project in the Google API console.
- Enable project access to the YouTube Data API.
- Create your credentials and generate an API key.
- If applicable, register and generate OAuth 2.0 credentials.
import os
import sys
import asyncio
from aioyoutube import YouTubeClient
from dotenv import load_dotenv
# load secret
load_dotenv()
YOUTUBE_API_KEY = os.getenv('YOUTUBE_API_KEY')
# returns links to the terms entered as arguments to the program
# ex search.py surfing violin
async def search(terms: list):
client = YouTubeClient.from_connect(key=YOUTUBE_API_KEY)
tasks = []
for term in terms:
tasks.append(client.search(search=term))
results = await asyncio.gather(*tasks)
for result in results:
for item in result.json['items']:
print('https://www.youtube.com/watch?v=' + item['id']['videoId'])
await client.close()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(search(sys.argv[1:]))
This library requires the aiohttp
library which is distrubuted under the Apache 2.0 license.
aioyoutube.py
is offered under the MIT License.