Download Youtube Video using python

Download Youtube Video using python

Hello everyone ! In this post we will help you to download any youtube video using python code.  Using Python, this task is very easy. Few lines of code will download the video from YouTube for you. At first we need to install pafy and youtube-dl packages using pip.


In this article, we will see how to extract details about Youtube videos and download them in different formats using the pafy module. Run the following code in your terminal to install pafy.

pip install pafy

Run the command to install youtube-dl packages

pip install youtube-dl

First of all, we need to import pafy library :

import pafy

After that, copy the URL of the YouTube video and paste it :


Further, pass url in one of pafy function, that is YouTube :

Lets get the best reolution of video


To download the video in specified location, we need to provide the link of the locaton to store the video.

filename ="/home/diwas/Desktop/") 

Congartulations, the video has been successfully downloaded in the ‘Desktop’ folder. However, it may take some time to download. Lets check the full code.

Full code

import pafy
#enter the url of the video you want to download
url="" # link of video url you want to download
##get best resolution of the video
###best resolution in required format[give your req format in "preftype"]
best = video.getbest(preftype="mp4")

#if you want to specify a particular path for the video
filename ="/home/diwas/Desktop/") # change the location as per your need .

## credit :-

7 Comments on “Download Youtube Video using python”

Leave a Reply

Your email address will not be published. Required fields are marked *