Skip to main content

Fetches new YouTube channel playlist content from RSS with automatic fallback to the YouTube API.

Project description

youtube-notify

youtube-notify is a small Python library for fetching recent content from a YouTube channel. It prefers the channel RSS feed first and falls back to the YouTube Data API when RSS does not return content. The library returns typed Content models with channel metadata, timestamps, thumbnails, and descriptions.

Features

  • RSS-first content retrieval with YouTube API fallback
  • Optional YouTube API key and OAuth helpers
  • Pydantic models for downstream validation and serialization
  • Async-friendly public APIs
  • Mocked integration tests for deterministic CI runs

Installation

This repository uses a src/ layout and installs as the youtube_notify package.

git clone https://github.com/jnstockley/youtube-notify.git
cd youtube-notify
uv sync

If you are using another virtual environment tool, install the project from pyproject.toml so the package is available as youtube_notify.

Setup

  1. Clone the repository.
  2. Create and activate a Python 3.14 environment.
  3. Install dependencies with uv sync or your preferred environment manager.
  4. Set PYTHONPATH=src when running the library directly from the repository.
  5. If you want to use the YouTube API fallback, provide an API key or OAuth credentials in your own application code.

Usage

The main entry point is youtube_notify.get_content(channel_id, youtube=None). It tries RSS first and only uses the YouTube API client if RSS returns no content.

Basic usage

import asyncio

from youtube_notify import get_content


async def main() -> None:
    content = await get_content("UCxxxxxxxxxxxxxxxxxxxxxx")
    for item in content:
        print(item.title)


asyncio.run(main())

Using a YouTube API key

If you already have a YouTube Data API key, build a client with youtube_notify.youtube.auth.api_key.authenticate() and pass it to youtube_notify.get_content().

import asyncio

from youtube_notify import get_content
from youtube_notify.youtube.auth.api_key import authenticate


async def main() -> None:
    youtube = authenticate("YOUR_YOUTUBE_API_KEY")
    content = await get_content("UCxxxxxxxxxxxxxxxxxxxxxx", youtube)
    for item in content:
        print(item.title)


asyncio.run(main())

Using OAuth credentials

If you need OAuth-based access, the OAuth helper can build credentials and refresh them before creating the client.

from youtube_notify.youtube.auth.oauth import authenticate, device_code_flow


creds = device_code_flow("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
youtube = authenticate(creds)

Required Environment Variables

The library itself does not require API credentials from environment variables. The only runtime environment settings used by the code are for logging:

  • LOG_LEVEL: optional, defaults to INFO
  • LOG_DIR: optional, defaults to ../logs

The repository also includes sample.env with example values for a wrapper application:

  • YOUTUBE_API_KEY
  • GOOGLE_CLIENT_ID
  • GOOGLE_CLIENT_SECRET

Those are not read automatically by the library; they are intended for your own application or deployment scripts.

If your application uses the YouTube API path through youtube_notify.youtube.get_content() or passes a client into youtube_notify.get_content(), you must provide one of the following sets of credentials in your application layer:

  • YOUTUBE_API_KEY
  • GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET

Development

Common local commands:

uv run pytest
uv run pytest -m integration
uv run ruff check
uv run ruff format --check

The integration test suite is mocked and does not make live network calls.

Project Structure

  • src/youtube_notify/content_fetcher.py: top-level RSS-first content fetcher
  • src/youtube_notify/rss/rss.py: RSS feed fetching and parsing
  • src/youtube_notify/youtube/youtube.py: YouTube API fetching and parsing
  • src/youtube_notify/youtube/auth/: API key and OAuth helpers
  • src/youtube_notify/models.py: Pydantic models used across the library

Operational Notes

  • The library writes logs to LOG_DIR/app.log.
  • If you run the code in a container or read-only environment, set LOG_DIR to a writable path.
  • The public APIs are asynchronous, so call them from asyncio code or wrap them with asyncio.run().

Contributing

Contributions are expected to keep the repository green.

Before opening a pull request:

  • All tests must pass.
  • Code coverage for updated code should be at least 90%.
  • The existing linting steps must pass.
  • Any public behavior change should include matching tests.

Recommended validation commands:

uv run pytest
uv run pytest --cov src --cov-branch --cov-report=term-missing
uv run ruff check
uv run ruff format --check

License

This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.

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

youtube_notify-20260701004043.dev0.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

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

youtube_notify-20260701004043.dev0-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

Details for the file youtube_notify-20260701004043.dev0.tar.gz.

File metadata

File hashes

Hashes for youtube_notify-20260701004043.dev0.tar.gz
Algorithm Hash digest
SHA256 f76a9eac42ec99579a76d8183f07c7ac49196b997c7a2f7ceab5a9b489f51bbf
MD5 c3b72e669e33e4241fe8a0cccda8cb10
BLAKE2b-256 3c3b2b95b0f381a98e5817ea452b4dc964c8723eea54e1de03fc53f7a8706952

See more details on using hashes here.

Provenance

The following attestation bundles were made for youtube_notify-20260701004043.dev0.tar.gz:

Publisher: ci-cd.yml on jnstockley/youtube-notify

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file youtube_notify-20260701004043.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for youtube_notify-20260701004043.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 5108476754ab988d7b614e387fc385bb2d8d8c647113636e92860767cde87065
MD5 3a451e3d76488b845fc6b9de2a8e301f
BLAKE2b-256 5bffcf9a0649eb9dc63408f7feb63622b8af07953ef6c6ccf3b517573aac5887

See more details on using hashes here.

Provenance

The following attestation bundles were made for youtube_notify-20260701004043.dev0-py3-none-any.whl:

Publisher: ci-cd.yml on jnstockley/youtube-notify

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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