Skip to main content

🎬 langchain-youtube

PyPI version CI Python 3.9+ License: MIT

LangChain retrievers for YouTube — search videos, fetch playlists, extract transcripts, and retrieve video metadata as LangChain Document objects.

Perfect for building RAG applications, video summarizers, and AI-powered YouTube tools.

✨ Features

Retriever What it does API Key Required?
YouTubeSearchRetriever Search videos by keyword ✅ Yes
YouTubePlaylistRetriever Fetch all videos from a playlist ✅ Yes
YouTubeTranscriptRetriever Extract video transcripts/captions ❌ No!
YouTubeVideoRetriever Get detailed video metadata ✅ Yes

📦 Installation

pip install langchain-youtube

🔑 Setup (for API key features)

  1. Go to the Google Cloud Console
  2. Create a project and enable the YouTube Data API v3
  3. Create an API key under Credentials

Note: The YouTubeTranscriptRetriever does NOT need an API key!

🚀 Quick Start

Search YouTube Videos

from langchain_youtube import YouTubeSearchRetriever

retriever = YouTubeSearchRetriever(
    api_key="YOUR_API_KEY",
    max_results=5,
    order="relevance",  # or "date", "viewCount", "rating"
)

docs = retriever.invoke("LangChain RAG tutorial")

for doc in docs:
    print(f"📹 {doc.metadata['url']}")
    print(f"   {doc.page_content[:100]}...")
    print(f"   👁 {doc.metadata['view_count']:,} views")

Extract Video Transcripts (No API Key!)

from langchain_youtube import YouTubeTranscriptRetriever

retriever = YouTubeTranscriptRetriever(
    languages=["en", "es"],  # Preferred languages
    chunk_size=3000,          # Split long transcripts for LLM context limits
)

docs = retriever.invoke("https://www.youtube.com/watch?v=VIDEO_ID")

for doc in docs:
    print(f"📝 Chunk {doc.metadata['chunk_index'] + 1}/{doc.metadata['total_chunks']}")
    print(doc.page_content[:200])

Fetch Playlist Videos

from langchain_youtube import YouTubePlaylistRetriever

retriever = YouTubePlaylistRetriever(
    api_key="YOUR_API_KEY",
    playlist_url="https://www.youtube.com/playlist?list=PLxxxxxx",
    max_results=100,
)

docs = retriever.invoke("fetch")  # Query is unused for playlists

for doc in docs:
    print(f"#{doc.metadata['position']}{doc.page_content[:80]}")

Get Video Metadata

from langchain_youtube import YouTubeVideoRetriever

retriever = YouTubeVideoRetriever(api_key="YOUR_API_KEY")

docs = retriever.invoke("https://www.youtube.com/watch?v=dQw4w9WgXcQ")

video = docs[0]
print(f"Title: {video.page_content}")
print(f"Views: {video.metadata['view_count']:,}")
print(f"Likes: {video.metadata['like_count']:,}")
print(f"Duration: {video.metadata['duration']}")

🔗 Use with LangChain Chains

from langchain_youtube import YouTubeTranscriptRetriever
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

# Set up retriever and LLM
retriever = YouTubeTranscriptRetriever(languages=["en"])
llm = ChatOpenAI(model="gpt-4o-mini")

prompt = ChatPromptTemplate.from_template(
    "Summarize this YouTube video transcript in 5 bullet points:\n\n{context}"
)

# Build a simple chain
chain = (
    {"context": retriever}
    | prompt
    | llm
    | StrOutputParser()
)

summary = chain.invoke("https://www.youtube.com/watch?v=VIDEO_ID")
print(summary)

🧪 Development

# Clone the repo
git clone https://github.com/urraf/langchain-youtube.git
cd langchain-youtube

# Install in dev mode
pip install -e ".[dev]"

# Run unit tests (no API key needed)
pytest tests/unit_tests/ -v

# Run integration tests (requires API key)
YOUTUBE_API_KEY=your_key pytest tests/integration_tests/ -v

# Lint
ruff check src/ tests/

📄 License

MIT — see LICENSE for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_youtube-0.1.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

langchain_youtube-0.1.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file langchain_youtube-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_youtube-0.1.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for langchain_youtube-0.1.0.tar.gz
Algorithm Hash digest
SHA256 23b5617a4acea7e0149ce0e983137f13e1c420072d4b0b6ac7bb7ca8fd2a0072
MD5 4a567fc204bf4fd23b9fe0ff2a20cdc7
BLAKE2b-256 ef0a9a89abc0efdc2960b13166347a07c96193604a96f2d6c5084ef76ffc0b91

See more details on using hashes here.

File details

Details for the file langchain_youtube-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_youtube-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2936008abf6afe33e8e8157047dd5aa65df8d3ec20783c6778f5d4c69ff8035e
MD5 b497b7717261836b6b4d65738b5c4a69
BLAKE2b-256 9427fab5e3876df0def3ce6fd39932604c4e39db39ff7230354ecbe7ef5680a4

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.1

2 files

0.2.0

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page