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.2.0.tar.gz (15.6 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.2.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: langchain_youtube-0.2.0.tar.gz
  • Upload date:
  • Size: 15.6 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.2.0.tar.gz
Algorithm Hash digest
SHA256 36d91aa9500f1adb2a5680f2a8d82343cc1f5677876e58090c43e6c7ba232497
MD5 5cb6c9f72bc1d95e9e4c9d063d46d481
BLAKE2b-256 8bec7be64c597af20e2a56edb51a9aba66773fbe072a32980de8fefbaf790b6b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_youtube-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b6e08edc0938d76116f9df02879643df50ec6f6024d50e7009be904340b75f5
MD5 5b3f1ea171b624ac6e95ecf3d031d3db
BLAKE2b-256 c665db69c37990d10e4dba4c37be84f425dc52097ae043fa3a9bec91ee3203b0

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.1

2 files

This release

0.2.0 This release

2 files

0.1.0

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