Skip to main content

A Python wrapper around for YouTube Data API.

Project description

Python YouTube

A Python wrapper for the 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 to Python-Twitter Developers.

Introduction

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.

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

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

We recommend using the pyyoutube.Client to operate DATA API. It is more modern and feature rich than pyyoutube.Api.

Work with Client

You can initialize with an api key:

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

To access additional data that requires authorization, 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:

>>> 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',
...
}

See the client docs, or client examples, for additional usage

Work with API

For compatibility with older code, we continue to support the old way.

You can just initialize with an api key:

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

To access additional data that requires authorization, 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',
    ...
   }

See the api docs, or api examples, for additional usage.

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.8.tar.gz (69.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_youtube-0.9.8-py3-none-any.whl (82.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_youtube-0.9.8.tar.gz
  • Upload date:
  • Size: 69.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.11.0 Linux/6.11.0-1018-azure

File hashes

Hashes for python_youtube-0.9.8.tar.gz
Algorithm Hash digest
SHA256 b6c679fbda07ecb114a95576c470a9f43f367ab71c61dc4b030dbfa2ea0826eb
MD5 b435face439e9a1e25960a39ad5d5872
BLAKE2b-256 c8d4856cd88fc64b40992cc5af4e247d347ee9605fdea3bf21f7c936e5411cb2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_youtube-0.9.8-py3-none-any.whl
  • Upload date:
  • Size: 82.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.11.0 Linux/6.11.0-1018-azure

File hashes

Hashes for python_youtube-0.9.8-py3-none-any.whl
Algorithm Hash digest
SHA256 de45a56cc588fb8c5b19a0d4d9425edef2959f59cf9793892da25b3d5afb270f
MD5 deedb5a729387650c2daf25137ec36ee
BLAKE2b-256 36f6fd915b163fa18f95e420025fcc29acf74769c2f72f855e119edaf4ff1589

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page