- Notifications
You must be signed in to change notification settings - Fork51
A simple Python wrapper for YouTube Data API ✨ 🍰 ✨ .
License
sns-sdks/python-youtube
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Python YouTube
A Python wrapper for the YouTube Data API V3.
Inspired byPython-Twitter.
Thanks a lot to Python-Twitter Developers.
This library provides an easy way to use the YouTube Data API V3.
We have recently been working on the new structure for the library.Read docs to get more detail.
You can view the latestpython-youtube documentation at:https://sns-sdks.github.io/python-youtube/.
Also view the fullYouTube DATA API docs at:https://developers.google.com/youtube/v3/docs/.
You can install this lib from PyPI:
pip install --upgrade python-youtube# ✨🍰✨The library covers all resource methods, includinginsert,``update``, and so on.
We recommend using thepyyoutube.Client to operate DATA API. It is more modern and feature rich thanpyyoutube.Api.
You can initialize with an api key:
>>>frompyyoutubeimportClient>>>client=Client(api_key="your api key")
To access additional data that requires authorization, you need to initialize with an access token:
>>>frompyyoutubeimportClient>>>client=Client(access_token='your access token')
You can read the docs to see how to get an access token.
Or you can ask for user to do OAuth:
>>>frompyyoutubeimportClient>>>client=Client(client_id="client key",client_secret="client secret")>>>client.get_authorize_url()('https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=id&redirect_uri=https%3A%2F%2Flocalhost%2F&scope=scope&state=PyYouTube&access_type=offline&prompt=select_account','PyYouTube')>>>client.generate_access_token(authorization_response="link for response")AccessToken(access_token='token',expires_in=3599,token_type='Bearer')
Now you can use the instance to get data from YouTube.
Get channel detail:
>>> cli.channels.list(channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw")ChannelListResponse(kind='youtube#channelListResponse')>>> cli.channels.list(channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw",return_json=True){'kind': 'youtube#channelListResponse', 'etag': 'eHSYpB_FqHX8vJiGi_sLCu0jkmE',...}
See theclient docs, orclient examples, for additional usage
For compatibility with older code, we continue to support the old way.
You can just initialize with an api key:
>>>frompyyoutubeimportApi>>>api=Api(api_key="your api key")
To access additional data that requires authorization, you need to initialize with an access token:
>>>frompyyoutubeimportApi>>>api=Api(access_token='your access token')
You can read the docs to see how to get an access token.
Or you can ask for user to do OAuth flow:
>>>frompyyoutubeimportApi>>>api=Api(client_id="client key",client_secret="client secret")# Get authorization url>>>api.get_authorization_url()('https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=id&redirect_uri=https%3A%2F%2Flocalhost%2F&scope=scope&state=PyYouTube&access_type=offline&prompt=select_account','PyYouTube')# user to do# copy the response url>>>api.generate_access_token(authorization_response="link for response")AccessToken(access_token='token',expires_in=3599,token_type='Bearer')
Now you can use the instance to get data from YouTube.
Get channel detail:
>>>channel_by_id=api.get_channel_info(channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw")>>>channel_by_id.items[Channel(kind='youtube#channel',id='UC_x5XG1OV2P6uZZ5FSM9Ttw')]>>>channel_by_id.items[0].to_dict(){'kind':'youtube#channel','etag':'"j6xRRd8dTPVVptg711_CSPADRfg/AW8QEqbNRoIJv9KuzCIg0CG6aJA"','id':'UC_x5XG1OV2P6uZZ5FSM9Ttw','snippet': {'title':'Google Developers','description':'The Google Developers channel features talks from events, educational series, best practices, tips, and the latest updates across our products and platforms.','customUrl':'googlecode','publishedAt':'2007-08-23T00:34:43.000Z','thumbnails': {'default': {'url':'https://yt3.ggpht.com/a/AGF-l78iFtAxyRZcUBzG91kbKMES19z-zGW5KT20_g=s88-c-k-c0xffffffff-no-rj-mo','width':88,'height':88},'medium': {'url':'https://yt3.ggpht.com/a/AGF-l78iFtAxyRZcUBzG91kbKMES19z-zGW5KT20_g=s240-c-k-c0xffffffff-no-rj-mo','width':240,'height':240},'high': {'url':'https://yt3.ggpht.com/a/AGF-l78iFtAxyRZcUBzG91kbKMES19z-zGW5KT20_g=s800-c-k-c0xffffffff-no-rj-mo','width':800,'height':800},'standard':None,'maxres':None},'defaultLanguage':None,'localized': {'title':'Google Developers','description':'The Google Developers channel features talks from events, educational series, best practices, tips, and the latest updates across our products and platforms.'},'country':'US'}, ... }# Get json response from youtube>>>api.get_channel_info(channel_id="UC_x5XG1OV2P6uZZ5FSM9Ttw",return_json=True) {'kind':'youtube#channelListResponse','etag':'17FOkdjp-_FPTiIJXdawBS4jWtc', ... }
See theapi docs, orapi examples, for additional usage.
About
A simple Python wrapper for YouTube Data API ✨ 🍰 ✨ .
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.