Skip to main content

YTAI: Python YouTube SDK, CLI, and MCP server without user-supplied API keys

Project description

YTAI: Python YouTube SDK, CLI and MCP Server

YTAI - Python YouTube SDK, CLI and MCP Server

YTAI is a Python SDK, command-line interface, and MCP server for YouTube search, metadata, transcripts, comments, channels, and media downloads without a user-supplied YouTube Data API key.

It uses YouTube's public InnerTube interface through curl_cffi browser impersonation, dynamically refreshes web-client configuration, and caches public responses locally with SQLite and orjson.

YTAI is an independent project. It is not affiliated with or endorsed by YouTube or Google. Use it in accordance with applicable terms, copyright law, and local regulations.

Contents

Features

  • Search videos, channels, and playlists with filters and pagination
  • Retrieve metadata, likes, captions, related videos, and comments
  • Fetch timestamped transcripts with language selection and XML fallback
  • Inspect channels, recent uploads, and popular videos
  • Download full video with audio, video-only, audio-only, or a time range
  • Resume interrupted downloads with ranged transfers and per-chunk retries
  • Cache responses in SQLite with operation-specific TTLs
  • Use the Python SDK, Rich-powered ytai CLI, nine read-only MCP tools, or the FastAPI service

Installation

Requirements:

  • Python 3.10 or newer
  • No separate FFmpeg installation is required for downloads; YTAI bundles FFmpeg through imageio-ffmpeg

Clone and install the project:

git clone https://github.com/vibheksoni/youtube-ai.git
cd youtube-ai
python -m pip install -e .

Install development dependencies when running tests:

python -m pip install -e ".[dev]"

FFmpeg is bundled automatically for Windows, macOS, and Linux when you install YTAI. If you prefer a system build, it is used when ffmpeg is on PATH. To pin an explicit binary, set YTAI_FFMPEG_PATH to its full path:

$env:YTAI_FFMPEG_PATH = "C:\tools\ffmpeg\bin\ffmpeg.exe"

YTAI_API_KEY is an optional offline fallback when live configuration cannot be fetched. It is read from the environment and is never stored in the repository.

For environment setup and first-run guidance, continue with Getting Started.

Quick start

Use YouTubeClient as a context manager so its HTTP session is closed cleanly:

from youtube_ai import YouTubeClient

with YouTubeClient() as client:
    results = client.search("python tutorial", limit=5, filter_type="video")
    for item in results["results"]:
        print(item["title"], item["url"])

    video = client.get_video("dQw4w9WgXcQ")
    print(video["details"]["title"])
    print(video["details"]["likes"])

    transcript = client.get_transcript("dQw4w9WgXcQ", language_codes=("en",))
    for segment in transcript["snippets"][:5]:
        print(f"{segment['start']:.1f}s: {segment['text']}")

Common CLI commands:

ytai search "python tutorial" --limit 10 --filter video
ytai video dQw4w9WgXcQ
ytai transcript dQw4w9WgXcQ --lang en
ytai comments dQw4w9WgXcQ --limit 20

See the Python API reference and CLI reference for complete signatures and commands.

Downloads

Inspect available qualities, codecs, stream sizes, and modes before downloading:

ytai download-options dQw4w9WgXcQ

Download a full video with audio:

ytai download dQw4w9WgXcQ --quality 720p --output ./downloads

Video-only, audio-only, and clipping are opt-in:

ytai download dQw4w9WgXcQ --quality 1080p --video-only
ytai download dQw4w9WgXcQ --audio-only
ytai download dQw4w9WgXcQ --quality 360p --start 30 --end 90

The SDK also exposes VideoQuality, DownloadMode, get_download_options(), and download_video(). See the download API and download example.

MCP server

Start the FastMCP server:

python mcp/server.py

It exposes nine read-only tools for search, video data, transcripts, streaming formats, comments, channels, and popular videos. Media downloading is intentionally available through the SDK and CLI only.

See MCP Server Setup for client configuration and tool parameters.

FastAPI server

Start the versioned HTTP API:

ytai-api

Swagger UI is available at http://127.0.0.1:8000/docs. The API covers search, video data, transcripts, comments, formats, download options, channels, and popular videos. See the FastAPI Server Guide for routes, curl examples, configuration, validation, and deployment guidance.

Documentation

  • Getting Started: prerequisites, installation, and first workflows
  • API Reference: public classes, functions, enums, and return shapes
  • CLI Reference: every ytai command and option
  • MCP Server: server setup, tools, parameters, and errors
  • FastAPI Server: HTTP routes, OpenAPI docs, configuration, and examples
  • Examples: runnable search, metadata, transcript, comment, channel, download, and MCP scripts

Testing

The end-to-end suite calls the real YouTube InnerTube and Google Video boundaries. It covers search, transcripts, comments, channels, MCP tools, CLI commands, download modes, clipping, resumable ranges, and ffmpeg output streams.

pytest tests/test_e2e.py -v

Limitations

  • Private, members-only, and most age-restricted content is unavailable without authentication.
  • InnerTube endpoints and renderer structures can change without notice.
  • Channel uploads currently return the first available page.
  • Adaptive full-video downloads and clipping use the bundled FFmpeg executable (or YTAI_FFMPEG_PATH when configured).
  • Playlist contents are not currently fetched.

Credits

YTAI acknowledges these public projects as references for protocol details, format mappings, and implementation ideas:

License

MIT, as declared in pyproject.toml.

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_ai-0.2.1.tar.gz (49.9 kB view details)

Uploaded Source

Built Distribution

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

youtube_ai-0.2.1-py3-none-any.whl (43.8 kB view details)

Uploaded Python 3

File details

Details for the file youtube_ai-0.2.1.tar.gz.

File metadata

  • Download URL: youtube_ai-0.2.1.tar.gz
  • Upload date:
  • Size: 49.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.6

File hashes

Hashes for youtube_ai-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e883bcece530f2f5b3b2a27c457f89e05122c4483b99167124a9a01291a9b084
MD5 c4ede91ee28be504284efc610d3c10a7
BLAKE2b-256 25f890aff1f8a89accb60105afa06a9c4bab85d233e192f1f6fa42fe134222f9

See more details on using hashes here.

File details

Details for the file youtube_ai-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: youtube_ai-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 43.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.6

File hashes

Hashes for youtube_ai-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 190aa0ddb0bbc6b1eed5eb16e8417780a74f490491afabd3b16b4db58c96c69b
MD5 499d874741cbb261e1a893c920eb1bfb
BLAKE2b-256 cabcc6e08f6b4ca3d070931562195d04b64d57df07765ee975e07389d2ae1841

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