Friday, January 30, 2026
HomeLanguagesPafy – Creating a Pafy Object

Pafy – Creating a Pafy Object

In this article we will see how we can create a pafy object. Pafy is a python library to download YouTube content and retrieve metadata. Pafy object is the object which contains all the information about the given video. The video should exist on youtube as it get the information of those videos which are present on the youtube. YouTube is an American online video-sharing platform headquartered in San Bruno, California.

In order to do this we use pafy.new method

Syntax : pafy.new(video)

Argument : It takes youtube video url or 11 character video id

Return : It returns pafy object

Below is the implementation




# importing pafy
import pafy 
    
# url of video 
url = "https://www.youtube.com / watch?v = vG2PNdI8axo"
    
# getting video
video = pafy.new(url) 
  
# printing video object
print(video)


Output :

Title: DSA Self Paced Course |neveropen
Author:neveropen
ID: vG2PNdI8axo
Duration: 00:01:06
Rating: 4.6894979
Views: 75431
Thumbnail: http://i.ytimg.com/vi/vG2PNdI8axo/default.jpg

Another example




# importing pafy
import pafy 
    
# id of video 
i_d = "vG2PNdI8axo"
    
# getting video through id
video = pafy.new(url) 
  
print(video)


Output :

Title: DSA Self Paced Course |neveropen
Author:neveropen
ID: vG2PNdI8axo
Duration: 00:01:06
Rating: 4.6894979
Views: 75431
Thumbnail: http://i.ytimg.com/vi/vG2PNdI8axo/default.jpg
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32478 POSTS0 COMMENTS
Milvus
122 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12065 POSTS0 COMMENTS
Shaida Kate Naidoo
6987 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6917 POSTS0 COMMENTS