Python Youtube Data API V3 Example to Search Videos and Save it as JSON File For FREE
111 views
Jun 3, 2025
Buy the full source code of application here:
View Video Transcript
0:00
uh hello guys uh welcome to this video
0:02
So in this video I will show you a uh
0:04
Python package which actually returns
0:07
you the YouTube videos in a JSON
0:10
response So if you wanted to actually
0:14
search YouTube videos this will be a
0:15
great package for you So it actually
0:19
searches the YouTube here based upon a
0:22
specific keyword Here you will see I
0:23
have written coding section and it will
0:24
return the videos in the form of JSON
0:28
Let's see that
0:31
So you can basically change this keyword
0:34
Let's suppose I say free media tools Let
0:36
me search my YouTube videos And as I run
0:39
this Python script what you will
0:42
see the search results are being saved
0:45
as at YouTube search results So it will
0:47
create this file here YouTube search
0:50
results And you will actually see three
0:53
videos will be returned to you This uh
0:56
data is coming from YouTube data API You
0:59
see the video ID you see the title of
1:01
the video you see the actual thumbnail
1:03
and the title of the video Same goes
1:06
with the second video You get all this
1:08
information using this free package of
1:10
Python And for this you don't require
1:12
any sort of API key As you can see we
1:14
haven't used the YouTube data API API
1:18
key So you can use it for unlimited
1:20
number of time and to actually query the
1:23
YouTube data API So let me show you the
1:26
module here If you go to
1:28
the just search for this
1:33
package So this is actually a python
1:36
package The command is very simple pip
1:39
install py- YouTube So just go to your
1:42
command line and just execute this
1:44
command pip install py YouTube and just
1:48
install this package This will take
1:50
hardly 5 seconds to install And as you
1:52
can see in the documentation they have
1:54
given how to use this So now let me show
1:57
you how to use it So first of all at the
2:00
very top we first of all require this
2:02
package py YouTube and from this we need
2:05
to
2:06
import the search package which will
2:09
actually search a particular YouTube
2:11
video and also we will be storing it as
2:14
a JSON response We will also be
2:16
importing the built-in JSON module and
2:19
then we will initialize the search uh
2:22
method and here you will specify
2:24
whatever keyword that you want to search
2:27
Let's suppose I want to search videos
2:29
about Python programming and then we can
2:31
even pass a limit as well right here how
2:34
many videos you want to return So here
2:36
we can also pass the limit So I'll say
2:38
that I want to see at five videos about
2:43
Python programming from YouTube and we
2:45
will simply say dot videos So this is
2:48
actually the function And now if I print
2:51
this right here this will actually
2:53
return me the JSON response If I execute
2:55
this Python script here you will see
2:57
that all this JSON response is returned
3:00
to us array of object Each object is
3:02
containing about the title thumbnail
3:04
everything is about containing the video
3:07
So now we can store this response which
3:10
is coming to a JSON file here For this
3:12
we will simply say with open and we say
3:16
output dojson So we'll store
3:18
this in the right
3:22
mode and then we can even provide a
3:31
encoding and we can simply dump this uh
3:35
in a JSON file here like this You'll see
3:38
that JSON dump videos
3:41
So then we can simply show a simple
3:44
notification that your data has been
3:46
saved to this file So now what happens
3:49
here if you see if you execute the
3:52
script right here python app py you will
3:54
see it will
3:56
create this
4:00
uh YouTube search results.json file and
4:04
you will see it will contain videos
4:06
about Python It actually comes with the
4:08
ID of the video then the title Then we
4:11
have also get the thumbnail Again you
4:13
will see you can open this thumbnail You
4:16
can see it is showing a live preview
4:18
This is a first video This is a second
4:21
video We have the third
4:24
video So in this way guys you can query
4:27
the YouTube data API with this free py
4:30
python module You don't require any sort
4:32
of API key and you install this module
4:35
and simply use it And here you can
4:37
change it Let's suppose PHP I change
4:40
this limit to 10 videos So now what
4:42
happens if you see if I again run
4:47
this So now if you see now it is saying
4:50
the PHP So you can
4:52
see in this easy way you can construct
4:55
any sort of YouTube searching video kind
4:58
of an application or build an API
5:00
because it is giving you the JSON
5:02
response like this You can build any
5:04
sort of application It can be mobile web
5:06
application with this JSON data which is
5:09
coming right here It's completely free
5:11
We haven't used any API key for this So
5:14
this is a free package You can install
5:16
it and use it And thank you very much
5:18
for watching this video And also check
5:21
out my website which is
5:22
freemediatools.com
5:24
uh which contains thousands of tools
#Computers & Electronics
#Programming
#Video Sharing
#Web Services