Skip to main content

Async YouTube Music search and stream extraction library.

Project description

YouTubeMusic

Async YouTube Music search and stream extraction library for Python.

Designed for developers who need fast YouTube search, metadata extraction, playlist parsing, and direct stream URLs — without mandatory API keys.


Features

  • Fully async architecture
  • YouTube search (scraping-based)
  • Optional YouTube Data API search
  • Audio stream extraction (powered by yt-dlp)
  • Video + audio stream support
  • Playlist & Mix support
  • Built-in CLI
  • No forced external services
  • Production-ready design
  • No console output on import

Installation

pip install YouTubeMusic

Quick Start

Basic Search

import asyncio
from YouTubeMusic.Search import Search

async def main():
    results = await Search("Kesariya", limit=1)

    if results and results.get("main_results"):
        item = results["main_results"][0]
        print(item)

asyncio.run(main())

Get Audio Stream URL

import asyncio
from YouTubeMusic.Stream import get_stream
cookies_path = ""

async def main():
    url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
    stream_url = await get_stream(url, cookies_path)
    print(stream_url)

asyncio.run(main())

Search Using YouTube Data API (Optional)

If you want to use official YouTube API:

Set environment variable:

export YOUTUBE_API_KEYS="key1,key2,key3"

Then:

import asyncio
from YouTubeMusic.YtSearch import Search as YtSearch

async def main():
    results = await YtSearch("Kesariya", limit=1)
    print(results)

asyncio.run(main())

If no API key is configured, it safely returns an empty list.


Get Playlist Songs

import asyncio
from YouTubeMusic.Playlist import get_playlist_songs

async def main():
    songs = await get_playlist_songs(
        "https://www.youtube.com/playlist?list=PLxxxxxxxx"
    )
    print(len(songs))

asyncio.run(main())

Extract Video + Audio URLs

import asyncio
from YouTubeMusic.Video_Stream import get_video_audio_urls
cookies_path = ""
async def main():
    video_url, audio_url = await get_video_audio_urls(
        "https://www.youtube.com/watch?v=dQw4w9WgXcQ", cookies_path
    )
    print(video_url)
    print(audio_url)

asyncio.run(main())

CLI Usage

After installation:

Basic Search

ytmusic "Kesariya"

Extract Audio Stream (requires cookies file)

ytmusic "Kesariya" --stream --cookies cookies.txt

Show Package Info

ytmusic --info

Special Thanks

Special thanks to the yt-dlp project for providing reliable and powerful media extraction capabilities used internally for stream URL handling.

yt-dlp is an open-source project maintained by its contributors. Learn more at: https://github.com/yt-dlp/yt-dlp

p

Why Use YouTubeMusic?

  • No mandatory YouTube API usage
  • Fully async and scalable
  • Lightweight and modular
  • Suitable for Telegram bots, web apps, and automation
  • Clean public API
  • No forced logging
  • Production-safe design

Requirements

  • Python 3.8+
  • httpx (with http2)
  • orjson
  • yt-dlp

Project Structure

YouTubeMusic/
    Search.py
    YtSearch.py
    Stream.py
    Video_Stream.py
    Playlist.py
    Models.py
    Utils.py
    cli.py

License

MIT License


Repository

https://github.com/YouTubeMusicAPI/YouTubeMusic


Author

Abhishek Thakur

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

youtubemusic-2026.2.28.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

youtubemusic-2026.2.28-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file youtubemusic-2026.2.28.tar.gz.

File metadata

  • Download URL: youtubemusic-2026.2.28.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for youtubemusic-2026.2.28.tar.gz
Algorithm Hash digest
SHA256 d27f1d623a6f5fa0971b4615afad63f1ab2c881eb4a0f29df048656cf1a7c87a
MD5 e482d3339c7e13f8014f478b152dac17
BLAKE2b-256 ff2fca32050f76a00daa27902c0c77440b21b2913439a6fbec316f4820644a17

See more details on using hashes here.

File details

Details for the file youtubemusic-2026.2.28-py3-none-any.whl.

File metadata

File hashes

Hashes for youtubemusic-2026.2.28-py3-none-any.whl
Algorithm Hash digest
SHA256 7f424de03b1bf6651fa5d6a928cc6259faa52583a19d2bb88596572f6c13bf53
MD5 5af5f7ccbd36bd5749b55b63b211f5e7
BLAKE2b-256 80744e3da7e26ef9d6253c9bd1bcb7ab74e6a4d0d0b95b8a5f21e0d9ccfd08ec

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