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 :-

About Diwas Pandey

Highly motivated, strong drive with excellent interpersonal, communication, and team-building skills. Motivated to learn, grow and excel in Data Science, Artificial Intelligence, SEO & Digital Marketing

View all posts by Diwas Pandey →

26 Comments on “Download Youtube Video using python”

  1. I’ve been browsing online more than 2 hours today, yet I never found any interesting article like yours.
    It is pretty worth enough for me. In my view, if all
    site owners and bloggers made good content as you did, the internet
    will be a lot more useful than ever before.

  2. Thanks a bunch for sharing this with all of us you actually know what you’re talking about!
    Bookmarked. Kindly also talk over with my site =).

    We could have a link alternate contract among us

Leave a Reply

Your email address will not be published.