Pytube – A Python Based, Command Line Tool To Download Youtube Videos

By | 20/09/2013

Sometime back we discussed a command line based tool youtube-dl that can be used to download youtube videos through command line. In this article, we will discuss another command line tool (a python script) to download youtube videos — PYTUBE.


NOTEAll the examples presented in this article are tested on bash shell in Ubuntu 13.04

A Brief Tutorial

Pytube is a python script that can be used to download youtube videos through command line. This tool can be used to itsĀ  potential when user runs individual python commands (from the script) one by one. It obviously requires python to be installed on your system.

When you go through the file that comes along with the source code, you will find a complete example that helps you understand how to use this script.

Here is a snapshot of that example :







Read and understand all the print commands carefully as this is where you can decide the details of the video being downloaded. After going through the these steps listed in file, I tried to run the same example again. Here are some snapshots related to that :

First enter in the python environment :


After this, I tried commands one by one :


So you can see that everything was fine until I executed the following command :


So, I referred the example details (shown earlier) and realised that the get() function would require another argument i.e, resolution. I tried 320 and this command worked fine but the download command gave the following error :


So, I changed the resolution in get() function to 720 and tried the download command again.


And as you can see, the video started downloading. You can check the downloaded file in the current working directory, once the command returns.


So, you can see the file named Dancing Scene from Pulp Fiction.mp4 is present in the current directory.

I checked the downloaded file using vlc player and it worked fine.


So this way, you can use this nice little python script to download youtube videos easily.


Here are some important links related to pytube script :

  • Home Page
  • Use the commands — easy_install pytube or pip pytube – to download this utility. Its source can be downloaded from this Download Link

The download file would be a zip file. You can extract the file from zip file using unzip command, enter into the main directory (pytube-master in my case) and run all the script commands from there.


  • Provides all the details so that user can choose the video configuration before downloading it.
  • It is a small script, which means that you can easily understand how it functions.


  • Requires python environment and a bit of python understanding to run the script and debug the problems.
  • The main example is broken — could get difficult for first time users to get started with it.


If you are a command line lover and are into habit of archiving your favourite videos by downloading them from youtube then this utility is for you. Its capability to let the user decide the video configuration is its biggest plus. Try it, it does what it promises.

10 thoughts on “Pytube – A Python Based, Command Line Tool To Download Youtube Videos

  1. Sum Yung Gai

    So, it looks like you’ve got to tweak the config file for each YouTube video that you want to download. Definitely not a n00bie-friendly way to do it, but it is effective. I’m glad to see more than one tool out there to do this, because there are a lot of good tutorials on YT that I find useful. As time goes on, I’m sure the author will continue to improve the program. Good on Mr. Ficano for writing it in the first place.


    1. Himanshu Post author

      Thanks for dropping by. Yes, I agree, its the end user who benefits the most when there are more than one options available.

  2. Jeff Smith

    I believe youtube-dl is designed to be a command-line tool, but pytube is designed
    to be a library. Both are built on python, but youtube-dl does not expect any
    knowledge of it. Something like pytube would probably be most useful for scripting
    or for adding a youtube-download feature to some high-level application so that
    the person dealing with pytube directly would be someone familiar with python.

    1. Himanshu Post author

      I agree. youtube-dl is for someone who is not interested in getting into details of what is happening inside while pytube gives a chance to peep in and even develop your own utility for same purpose.

  3. John Smith

    Could you possibly make it a bit more harder on you and on your others?
    Why screenshots instead of text?
    You think people will type all that again?
    Your examples, I can understand but even instructions to download?

    I don’t think that is how things are done everywhere else.

  4. en0

    pytube is great. It works most of the time and the comments stating that it is not for your average user i would agree with. I choose pytube because i can hook it into other tools like scapy.

  5. sardik

    Is there a way to download part of the youtube video ? Out of 50 min video, dowload only 5th min to 10th min.


Leave a Reply

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