The pyyoutube.Client class is the primary entry point for interacting with the YouTube API. You can initialize it in three ways depending on your required permissions:
- Public Data: Use an
api_key for read-only access to public information. - Authorized User Data: Use an existing
access_token to perform actions on behalf of a user (e.g., uploading videos). - OAuth2 Flow: Provide
client_id and client_secret to initiate a full authorization flow.
You can also initialize the client using a client_secret_path pointing to a JSON file. Note that only web and certain installed client types are supported. The client will automatically use the first entry in the redirect_uris field as the DEFAULT_REDIRECT_URI.
from pyyoutube import Client
# For public data
cli = Client(api_key="your api key")
# For authorized actions with an existing token
cli = Client(access_token="Access Token with permissions")
# Using a client secret file
cli = Client(client_secret_path="path/to/client_secret.json")