Skip to main content

A Python wrapper around for YouTube Data API.

Project description

Python YouTube

A Python wrapper around for YouTube Data API V3.

https://github.com/sns-sdks/python-youtube/workflows/Test/badge.svg Documentation Status https://codecov.io/gh/sns-sdks/python-youtube/branch/master/graph/badge.svg https://img.shields.io/pypi/v/python-youtube.svg

THANKS

Inspired by Python-Twitter.

Thanks a lot for Python-Twitter Developers.

Introduction

Library provides an easy way to use YouTube Data API V3.

Recently, we are working on the new structure for the library. Read docs to get more detail.

Documentation

You can view the latest python-youtube documentation at: https://sns-sdks.github.io/python-youtube/.

Also view the full YouTube DATA API docs at: https://developers.google.com/youtube/v3/docs/.

Installing

You can install this lib from PyPI:

pip install --upgrade python-youtube
# ✨🍰✨

Using

Now, the library covers all resource methods, including insert,``update`` and so on.

Currently, we recommend using pyyoutube.Client to operate DATA API. It has more features.

Work with Client

You can just initialize with an api key:

>>> from pyyoutube import Client
>>> client = Client(api_key="your api key")

If you want to get some authorization data. you need to initialize with an access token:

>>> from pyyoutube import Client
>>> 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 flow:

>>> from pyyoutube import Client
>>> 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',
...
}

To get more usage to see our client docs, or client examples

Work with API

We still support the old way for the sake of compatibility with older users.

You can just initialize with an api key:

>>> from pyyoutube import Api
>>> api = Api(api_key="your api key")

If you want to get some authorization data. you need to initialize with an access token:

>>> from pyyoutube import Api
>>> 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:

>>> from pyyoutube import Api
>>> 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',
    ...
   }

To get more usage to see our api docs, or api examples

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

python_youtube-0.9.7.tar.gz (71.8 kB view details)

Uploaded Source

Built Distribution

python_youtube-0.9.7-py3-none-any.whl (82.2 kB view details)

Uploaded Python 3

File details

Details for the file python_youtube-0.9.7.tar.gz.

File metadata

  • Download URL: python_youtube-0.9.7.tar.gz
  • Upload date:
  • Size: 71.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.0 Linux/6.5.0-1025-azure

File hashes

Hashes for python_youtube-0.9.7.tar.gz
Algorithm Hash digest
SHA256 bd88611e7e58ad4261d8c9ad0e22253706cafa25edb5784bafe0ccbde2821317
MD5 c2c8b8f4b6ff7778a5ff858bf0466831
BLAKE2b-256 5f3c58013cda4695d90ee3093265f109c46e3943bea7b63151095ce2e11a319d

See more details on using hashes here.

File details

Details for the file python_youtube-0.9.7-py3-none-any.whl.

File metadata

  • Download URL: python_youtube-0.9.7-py3-none-any.whl
  • Upload date:
  • Size: 82.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.0 Linux/6.5.0-1025-azure

File hashes

Hashes for python_youtube-0.9.7-py3-none-any.whl
Algorithm Hash digest
SHA256 00fcf0ff773af829460dba527dfc2eb7ffd0547ddfe24f3dbe8ad3c788c8febb
MD5 7121f6733fa6b67a0e3d0c716638b9ce
BLAKE2b-256 243b5d753d187d69cda75061dd3695bae65a68bda44f341e914ea08674eb9288

See more details on using hashes here.

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