Download MP3s from YouTube with Python

Use YouTube Video Downloader to download MP3s from YouTube with Python. Want to add YouTube audio downloads to your own Python project? Just pass your video URLs to the Actor with the Apify API client and get MP3 files back in bulk.

Easy setup to get MP3s programmatically in Python

Sign up on Apify01

Create a free Apify account (no credit card needed) and find YouTube Video Downloader in Apify Store.

Sign up for free
Initialize the API using your token02

Once you have an account, add your API token. You’ll find it on the Integrations page in Apify Console.

Get your token in Console
Define input and copy it in JSON03

Open YouTube Video Downloader in Apify Console, add the YouTube video URLs you want as MP3s, and set the format to MP3. Then copy the input as JSON from the Input tab and paste it into your code.

Integrate Apify into your codebase04

Call YouTube Video Downloader from your Python project with the Apify Python client or the API endpoints. Run the sample code below and your MP3 files land in Apify Storage, or in your own S3, Google Cloud Storage, or Azure bucket ↓.

Monitor your YouTube Video Downloader runs05

Open your Apify Console dashboard and watch YouTube Video Downloader runs execute in real time. You can also download the run logs, set up schedules so runs repeat on their own, and use webhooks to trigger the next step in your pipeline as soon as a download finishes.

Go to dashboard

Get your Python project up and running

Start your Python project by executing this code snippet in your go-to environment.

1from apify_client import ApifyClient
2
3# Initialize the ApifyClient with your Apify API token
4# Replace '<YOUR_API_TOKEN>' with your token.
5client = ApifyClient("<YOUR_API_TOKEN>")
6
7# Prepare the Actor input
8run_input = { "videos": [{ "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ" }] }
9
10# Run the Actor and wait for it to finish
11run = client.actor("streamers/youtube-video-downloader").call(run_input=run_input)
12
13# Fetch and print Actor results from the run's dataset (if there are any)
14print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
15for item in client.dataset(run.default_dataset_id).iterate_items():
16 print(item)
17
18# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start
Free $5 usage every month

Enjoy $5 of free platform usage every month to explore and kickstart your projects.

No credit card required

Get started on Apify instantly without the hassle of entering your credit card information.

Supportive community on Discord

Join our Discord community to ask questions, share ideas, and connect with developers.

Frequently asked questions

You give YouTube Video Downloader a list of YouTube video URLs and pick an output format. It fetches each video, extracts the audio track, converts it to MP3 or another format you choose, and saves the file to Apify Storage or your own cloud storage bucket. You can start all of that from Python with the Apify API client.

Yes. Every Actor on Apify has a REST API, and the Apify Python client wraps it. Pass your video URLs as input, start the run, then read the output from the run's dataset or key-value store. The sample code above is a working starting point.

MP3 is the usual choice, and you can also pick AAC, FLAC, M4A, OGG, OPUS, or WAV. Video formats are available too - MP4, AVI, MKV, MOV, and WebM - with quality settings from 144p up to 2160p.

Actors are serverless cloud programs that run on the Apify platform and do computing jobs. They’re called Actors because, like human actors, they perform actions based on a script. They can perform anything from simple actions (such as filling out a web form or sending an email) to complex operations (such as crawling an entire website or removing duplicates from a large dataset). Actor runs can be as short or as long as necessary. They could last seconds, hours, or even run infinitely.

Ready to get started?

Create your free Apify account to download YouTube MP3s now.