API objects¶
Here is a list of all API objects.
-
class phub.core.Client(email: str =
None, password: str =None, *, language: 'en' | 'cn' | 'de' | 'fr' | 'it' | 'pt' | 'pl' | 'rt' | 'nl' | 'cz' | 'jp' ='en', delay: int | float =0, login: bool =True, bypass_geo_blocking: bool =False, change_title_language: bool =True, use_webmaster_api: bool =True)¶ Represents a client capable of handling requests with Pornhub.
- property _granted_token : str¶
Get a granted token for the account. Used internally for making API calls.
- Raises:¶
AssertionError – If the client is not logged in
-
call(func: str, method: str =
'GET', data: dict =None, headers: dict =None, timeout: float =30, throw: bool =True, silent: bool =False) Response¶ Used internally to send a request or an API call.
- Parameters:¶
- func : str¶
URL or PH function to fetch or call.
- method : str¶
Request method (GET, POST, PUT, …).
- data : dict¶
Optional data to send to the server.
- headers : dict¶
Additional request headers.
- timeout : float¶
Request maximum response time.
- throw : bool¶
Whether to raise an error when a request explicitly fails.
- silent : bool¶
Whether to supress this call from logs.
- Returns:¶
The fetched response.
- Return type:¶
Response
- Raises:¶
ConnectionError – If the request was blocked by Pornhub.
HTTPError – If the request failed, for any reason.
-
login(force: bool =
False, throw: bool =True) bool¶ Attempt to log in.
- Parameters:¶
- Returns:¶
Whether the login was successful.
- Return type:¶
- Raises:¶
ClientAlreadyLogged – If
forcewas False and client was already logged.LoginFailed – If the login failed, for a reason passed in the error body.
- reset() None¶
Reset the client requests session. This is useful if you are keeping the client running for a long time and can help with Pornhub rate limit.
-
search(query: str, *, production: 'homemade' | 'professional' =
None, category: 'asian' | 'orgy' | 'amateur' | 'big-ass' | 'babe' | 'bbw' | 'big-dick' | 'big-tits' | 'blonde' | 'bondage' | 'brunette' | 'celebrity' | 'blowjob' | 'bukkake' | 'creampie' | 'cumshot' | 'ebony' | 'fetish' | 'fisting' | 'handjob' | 'hardcore' | 'masturbation' | 'toys' | 'public' | 'interracial' | 'latina' | 'lesbian' | 'mature' | 'milf' | 'pornstar' | 'reality' | 'funny' | 'striptease' | 'anal' | 'hentai' | 'teen' | 'hd-porn' | 'japanese-gay' | 'bareback-gay' | 'pov' | 'red-head' | 'vintage' | 'black-gay' | 'massage-gay' | 'euro-gay' | 'daddy-gay' | 'asian-gay' | 'twink' | 'latino-gay' | 'muscle-gay' | 'fetish-gay' | 'party' | 'solo-male-gay' | 'euro' | 'blowjob-gay' | 'compilation' | 'big-dick-gay' | 'small-tits' | 'pornstar-gay' | 'webcam' | 'group-gay' | 'gay' | 'interracial-gay' | 'threesome' | 'bear-gay' | 'rough-sex' | 'college' | 'squirt' | 'hunks-gay' | 'creampie-gay' | 'double-penetration' | 'popular-with-women' | 'bisexual-male' | 'vintage-gay' | 'massage' | 'gangbang' | 'role-play' | 'straight-guys-gay' | 'transgender' | 'public-gay' | 'reality-gay' | 'cartoon' | 'school' | 'babysitter' | 'casting' | 'smoking' | 'solo-male' | 'feet' | 'french' | 'german' | 'british' | 'italian' | 'arab' | 'russian' | 'czech' | 'indian' | 'brazilian' | 'korean' | 'vr' | '60fps' | 'vr-gay' | 'hd-porn-gay' | 'interactive' | 'japanese' | 'exclusive' | 'music' | 'pussy-licking' | 'ffm' | 'fmm' | 'verified-amateurs' | 'verified-models' | 'behind-the-scenes' | 'old-young' | 'parody' | 'pissing' | 'sfw' | 'described-video' | 'cosplay' | 'cuckold' | 'amateur-gay' | 'handjob-gay' | 'uncut-gay' | 'rough-sex-gay' | 'jock-gay' | 'mature-gay' | 'webcam-gay' | 'cumshot-gay' | 'casting-gay' | 'pov-gay' | 'compilation-gay' | 'chubby-gay' | 'military-gay' | 'feet-gay' | 'cartoon-gay' | 'step-fantasy' | 'verified-couples' | 'solo-female' | 'female-orgasm' | 'muscular-men' | 'romantic' | 'scissoring' | 'strap-on' | 'tattooed-men-gay' | 'tattooed-women' | 'trans-with-girl' | 'trans-with-guy' | 'fingering' | 'trans-male' | '360' | '180' | '2d' | '3d' | 'voyeur' | 'uncensored' | 'verified-amateurs-gay' | 'closed-captions' | 'closed-captions-gay' =None, exclude_category: 'asian' | 'orgy' | 'amateur' | 'big-ass' | 'babe' | 'bbw' | 'big-dick' | 'big-tits' | 'blonde' | 'bondage' | 'brunette' | 'celebrity' | 'blowjob' | 'bukkake' | 'creampie' | 'cumshot' | 'ebony' | 'fetish' | 'fisting' | 'handjob' | 'hardcore' | 'masturbation' | 'toys' | 'public' | 'interracial' | 'latina' | 'lesbian' | 'mature' | 'milf' | 'pornstar' | 'reality' | 'funny' | 'striptease' | 'anal' | 'hentai' | 'teen' | 'hd-porn' | 'japanese-gay' | 'bareback-gay' | 'pov' | 'red-head' | 'vintage' | 'black-gay' | 'massage-gay' | 'euro-gay' | 'daddy-gay' | 'asian-gay' | 'twink' | 'latino-gay' | 'muscle-gay' | 'fetish-gay' | 'party' | 'solo-male-gay' | 'euro' | 'blowjob-gay' | 'compilation' | 'big-dick-gay' | 'small-tits' | 'pornstar-gay' | 'webcam' | 'group-gay' | 'gay' | 'interracial-gay' | 'threesome' | 'bear-gay' | 'rough-sex' | 'college' | 'squirt' | 'hunks-gay' | 'creampie-gay' | 'double-penetration' | 'popular-with-women' | 'bisexual-male' | 'vintage-gay' | 'massage' | 'gangbang' | 'role-play' | 'straight-guys-gay' | 'transgender' | 'public-gay' | 'reality-gay' | 'cartoon' | 'school' | 'babysitter' | 'casting' | 'smoking' | 'solo-male' | 'feet' | 'french' | 'german' | 'british' | 'italian' | 'arab' | 'russian' | 'czech' | 'indian' | 'brazilian' | 'korean' | 'vr' | '60fps' | 'vr-gay' | 'hd-porn-gay' | 'interactive' | 'japanese' | 'exclusive' | 'music' | 'pussy-licking' | 'ffm' | 'fmm' | 'verified-amateurs' | 'verified-models' | 'behind-the-scenes' | 'old-young' | 'parody' | 'pissing' | 'sfw' | 'described-video' | 'cosplay' | 'cuckold' | 'amateur-gay' | 'handjob-gay' | 'uncut-gay' | 'rough-sex-gay' | 'jock-gay' | 'mature-gay' | 'webcam-gay' | 'cumshot-gay' | 'casting-gay' | 'pov-gay' | 'compilation-gay' | 'chubby-gay' | 'military-gay' | 'feet-gay' | 'cartoon-gay' | 'step-fantasy' | 'verified-couples' | 'solo-female' | 'female-orgasm' | 'muscular-men' | 'romantic' | 'scissoring' | 'strap-on' | 'tattooed-men-gay' | 'tattooed-women' | 'trans-with-girl' | 'trans-with-guy' | 'fingering' | 'trans-male' | '360' | '180' | '2d' | '3d' | 'voyeur' | 'uncensored' | 'verified-amateurs-gay' | 'closed-captions' | 'closed-captions-gay' | Iterable['asian' | 'orgy' | 'amateur' | 'big-ass' | 'babe' | 'bbw' | 'big-dick' | 'big-tits' | 'blonde' | 'bondage' | 'brunette' | 'celebrity' | 'blowjob' | 'bukkake' | 'creampie' | 'cumshot' | 'ebony' | 'fetish' | 'fisting' | 'handjob' | 'hardcore' | 'masturbation' | 'toys' | 'public' | 'interracial' | 'latina' | 'lesbian' | 'mature' | 'milf' | 'pornstar' | 'reality' | 'funny' | 'striptease' | 'anal' | 'hentai' | 'teen' | 'hd-porn' | 'japanese-gay' | 'bareback-gay' | 'pov' | 'red-head' | 'vintage' | 'black-gay' | 'massage-gay' | 'euro-gay' | 'daddy-gay' | 'asian-gay' | 'twink' | 'latino-gay' | 'muscle-gay' | 'fetish-gay' | 'party' | 'solo-male-gay' | 'euro' | 'blowjob-gay' | 'compilation' | 'big-dick-gay' | 'small-tits' | 'pornstar-gay' | 'webcam' | 'group-gay' | 'gay' | 'interracial-gay' | 'threesome' | 'bear-gay' | 'rough-sex' | 'college' | 'squirt' | 'hunks-gay' | 'creampie-gay' | 'double-penetration' | 'popular-with-women' | 'bisexual-male' | 'vintage-gay' | 'massage' | 'gangbang' | 'role-play' | 'straight-guys-gay' | 'transgender' | 'public-gay' | 'reality-gay' | 'cartoon' | 'school' | 'babysitter' | 'casting' | 'smoking' | 'solo-male' | 'feet' | 'french' | 'german' | 'british' | 'italian' | 'arab' | 'russian' | 'czech' | 'indian' | 'brazilian' | 'korean' | 'vr' | '60fps' | 'vr-gay' | 'hd-porn-gay' | 'interactive' | 'japanese' | 'exclusive' | 'music' | 'pussy-licking' | 'ffm' | 'fmm' | 'verified-amateurs' | 'verified-models' | 'behind-the-scenes' | 'old-young' | 'parody' | 'pissing' | 'sfw' | 'described-video' | 'cosplay' | 'cuckold' | 'amateur-gay' | 'handjob-gay' | 'uncut-gay' | 'rough-sex-gay' | 'jock-gay' | 'mature-gay' | 'webcam-gay' | 'cumshot-gay' | 'casting-gay' | 'pov-gay' | 'compilation-gay' | 'chubby-gay' | 'military-gay' | 'feet-gay' | 'cartoon-gay' | 'step-fantasy' | 'verified-couples' | 'solo-female' | 'female-orgasm' | 'muscular-men' | 'romantic' | 'scissoring' | 'strap-on' | 'tattooed-men-gay' | 'tattooed-women' | 'trans-with-girl' | 'trans-with-guy' | 'fingering' | 'trans-male' | '360' | '180' | '2d' | '3d' | 'voyeur' | 'uncensored' | 'verified-amateurs-gay' | 'closed-captions' | 'closed-captions-gay'] =None, hd: bool =None, sort: 'recent' | 'views' | 'rated' | 'longuest' =None, period: 'all' | 'day' | 'week' | 'month' | 'year' =None) Query¶ Performs searching on Pornhub.
- Parameters:¶
- query : str¶
The query to search.
- production : str¶
Production type.
- category : str¶
A category the video is in.
- exclude_category : str | list¶
One or more categories to exclude.
- hd : bool¶
Whether to search only HD videos.
- sort : str¶
Sorting type.
- period : str¶
When using sort, specify the search period.
- Returns:¶
Initialised query.
- Return type:¶
- Raises:¶
AssertioneError – If the query is empty.
AssertioneError – If one or more filters don’t match their literals.
-
search_hubtraffic(query: str, *, category: 'asian' | 'orgy' | 'amateur' | 'big-ass' | 'babe' | 'bbw' | 'big-dick' | 'big-tits' | 'blonde' | 'bondage' | 'brunette' | 'celebrity' | 'blowjob' | 'bukkake' | 'creampie' | 'cumshot' | 'ebony' | 'fetish' | 'fisting' | 'handjob' | 'hardcore' | 'masturbation' | 'toys' | 'public' | 'interracial' | 'latina' | 'lesbian' | 'mature' | 'milf' | 'pornstar' | 'reality' | 'funny' | 'striptease' | 'anal' | 'hentai' | 'teen' | 'hd-porn' | 'japanese-gay' | 'bareback-gay' | 'pov' | 'red-head' | 'vintage' | 'black-gay' | 'massage-gay' | 'euro-gay' | 'daddy-gay' | 'asian-gay' | 'twink' | 'latino-gay' | 'muscle-gay' | 'fetish-gay' | 'party' | 'solo-male-gay' | 'euro' | 'blowjob-gay' | 'compilation' | 'big-dick-gay' | 'small-tits' | 'pornstar-gay' | 'webcam' | 'group-gay' | 'gay' | 'interracial-gay' | 'threesome' | 'bear-gay' | 'rough-sex' | 'college' | 'squirt' | 'hunks-gay' | 'creampie-gay' | 'double-penetration' | 'popular-with-women' | 'bisexual-male' | 'vintage-gay' | 'massage' | 'gangbang' | 'role-play' | 'straight-guys-gay' | 'transgender' | 'public-gay' | 'reality-gay' | 'cartoon' | 'school' | 'babysitter' | 'casting' | 'smoking' | 'solo-male' | 'feet' | 'french' | 'german' | 'british' | 'italian' | 'arab' | 'russian' | 'czech' | 'indian' | 'brazilian' | 'korean' | 'vr' | '60fps' | 'vr-gay' | 'hd-porn-gay' | 'interactive' | 'japanese' | 'exclusive' | 'music' | 'pussy-licking' | 'ffm' | 'fmm' | 'verified-amateurs' | 'verified-models' | 'behind-the-scenes' | 'old-young' | 'parody' | 'pissing' | 'sfw' | 'described-video' | 'cosplay' | 'cuckold' | 'amateur-gay' | 'handjob-gay' | 'uncut-gay' | 'rough-sex-gay' | 'jock-gay' | 'mature-gay' | 'webcam-gay' | 'cumshot-gay' | 'casting-gay' | 'pov-gay' | 'compilation-gay' | 'chubby-gay' | 'military-gay' | 'feet-gay' | 'cartoon-gay' | 'step-fantasy' | 'verified-couples' | 'solo-female' | 'female-orgasm' | 'muscular-men' | 'romantic' | 'scissoring' | 'strap-on' | 'tattooed-men-gay' | 'tattooed-women' | 'trans-with-girl' | 'trans-with-guy' | 'fingering' | 'trans-male' | '360' | '180' | '2d' | '3d' | 'voyeur' | 'uncensored' | 'verified-amateurs-gay' | 'closed-captions' | 'closed-captions-gay' =
None, tags: str | list[str] =None, sort: 'recent' | 'views' | 'rated' | 'featured' =None, period: 'all' | 'week' | 'month' =None) Query¶ Perform searching on Pornhub using the HubTraffic API. It is condidered to be much faster but has less filters.
- Parameters:¶
- Returns:¶
Initialised query response.
- Return type:¶
- Raises:¶
AssertionError – If one or more filters don’t match their literals.
-
search_user(username: str =
None, country: str =None, city: str =None, min_age: int =None, max_age: int =None, gender: 'male' | 'female' | 'couple' | 'female couple' | 'trans female' | 'male couple' | 'trans male' | 'other' | 'non binary' =None, orientation: 'none' | 'male' | 'female' | 'all' =None, offers: 'custom videos' | 'fan club' =None, relation: 'single' | 'taken' | 'open' =None, sort: 'popular' | 'newest' =None, is_online: bool =None, is_model: bool =None, is_staff: bool =None, has_avatar: bool =None, has_videos: bool =None, has_photos: bool =None, has_playlists: bool =None) UserQuery¶ Search for users in the community.
- Parameters:¶
- username : str¶
Filters users with a name query.
- country : str¶
Filter users with a country.
- city : str¶
Filters users with a city.
- min_age : int¶
Filters users with a minimal age.
- max_age : int¶
Filters users with a maximal age.
- gender : gender¶
Filters users with a gender.
- orientation : orientation¶
Filters users with an orientation.
- offers : offers¶
Filters users with what content they do on their channel.
- relation : relation¶
Filters users with their relation.
- sort : sort_user¶
Response sort type.
- is_online : bool¶
Get only online or offline users.
- is_model : bool¶
Get only model users.
- is_staff : bool¶
Get only Pornhub staff members.
- has_avatar : bool¶
Get only users with a custom avatar.
- has_videos : bool¶
Get only users that have posted videos.
- has_photos : bool¶
Get only users that have posted photos.
- has_playlists : bool¶
Get only users that have posted playlists.
- Returns:¶
Initialised query.
- Return type:¶
UserQuery
- class phub.objects.Account(client: Client)¶
Represents a connected Ponhub account, capable of accessing account-only features. If the login fails, there will be None.
-
dictify(keys: 'all' | list[str] =
'all', recursive: bool =False) dict¶ Convert the object to a dictionary.
- property liked : queries.VideoQuery¶
Videos liked by the account.
- property recommended : queries.VideoQuery¶
Videos recommended to the account.
-
refresh(refresh_login: bool =
False) None¶ Delete the object’s cache to allow items refreshing.
- property watched : queries.VideoQuery¶
Account video history.
-
dictify(keys: 'all' | list[str] =
- class phub.objects.Like(up: int, down: int, ratings: float)¶
Represents video likes and their ratings.
-
class phub.objects.FeedItem(client: Client =
None, raw: str =None, type: str =None)¶ Represent an element of the user feed.
- property _soup : Soup¶
Item soup.
-
dictify(keys: 'all' | list[str] =
'all', recursive: bool =False) dict¶ Convert the object to a dictionary.
- property html : Soup¶
Item HTML content.
- class phub.objects.Feed(client: Client)¶
Represents the account feed.
- property feed : queries.FeedQuery¶
A feed query with no filters.
-
filter(section: literals.section =
None, user: User | str =None) queries.FeedQuery¶ Creates a Feed Query with specific filters.
-
class phub.objects.Image(client: Client, url: str, servers: list[dict] =
[], name: str ='image')¶ Represents an image hosted on Pornhub. (user avatar, video thumbnail, etc.)
-
class phub.objects.Query(client: Client, func: str, args: dict[str] =
{}, container_hint: consts.WrappedRegex | collections.abc.Callable =None, query_repr: str =None)¶ A Base query.
- property pages : Pages¶
Iterate through the query pages.
-
class phub.objects.User(client: Client, name: str, url: str, type: str =
None)¶ Represents a Pornhub user.
- property _supports_queries : _QuerySupportIndex¶
Checks query support.
-
dictify(keys: 'all' | list[str] =
'all', recursive: bool =False) dict¶ Convert the object to a dictionary.
- classmethod get(client: Client, user: str) User¶
Fetch a user knowing its name or URL. Note - Using only a username makes the fetch between 1 and 3 times slower, you might prefer to use a direct URL.
- property info : dict[str, str]¶
The user detailed infos.
[Experimental]
Warning: keys depend on the language.
- property uploads : queries.VideoQuery¶
Attempt to get the list of videos uploaded by this user.
- property videos : queries.VideoQuery¶
Get the list of videos published by this user.
-
class phub.objects.Video(client: Client, url: str, change_title_language: bool =
False)¶ Represents a Pornhub video.
- property _as_query : dict[str, str]¶
Simulate a query to gain access to more data. If the video object is yielded by a query, this property will be overriden by the query data.
- Warning - This will make a lot of requests and can fake
some properties (like watched).
- property categories : list['asian' | 'orgy' | 'amateur' | 'big-ass' | 'babe' | 'bbw' | 'big-dick' | 'big-tits' | 'blonde' | 'bondage' | 'brunette' | 'celebrity' | 'blowjob' | 'bukkake' | 'creampie' | 'cumshot' | 'ebony' | 'fetish' | 'fisting' | 'handjob' | 'hardcore' | 'masturbation' | 'toys' | 'public' | 'interracial' | 'latina' | 'lesbian' | 'mature' | 'milf' | 'pornstar' | 'reality' | 'funny' | 'striptease' | 'anal' | 'hentai' | 'teen' | 'hd-porn' | 'japanese-gay' | 'bareback-gay' | 'pov' | 'red-head' | 'vintage' | 'black-gay' | 'massage-gay' | 'euro-gay' | 'daddy-gay' | 'asian-gay' | 'twink' | 'latino-gay' | 'muscle-gay' | 'fetish-gay' | 'party' | 'solo-male-gay' | 'euro' | 'blowjob-gay' | 'compilation' | 'big-dick-gay' | 'small-tits' | 'pornstar-gay' | 'webcam' | 'group-gay' | 'gay' | 'interracial-gay' | 'threesome' | 'bear-gay' | 'rough-sex' | 'college' | 'squirt' | 'hunks-gay' | 'creampie-gay' | 'double-penetration' | 'popular-with-women' | 'bisexual-male' | 'vintage-gay' | 'massage' | 'gangbang' | 'role-play' | 'straight-guys-gay' | 'transgender' | 'public-gay' | 'reality-gay' | 'cartoon' | 'school' | 'babysitter' | 'casting' | 'smoking' | 'solo-male' | 'feet' | 'french' | 'german' | 'british' | 'italian' | 'arab' | 'russian' | 'czech' | 'indian' | 'brazilian' | 'korean' | 'vr' | '60fps' | 'vr-gay' | 'hd-porn-gay' | 'interactive' | 'japanese' | 'exclusive' | 'music' | 'pussy-licking' | 'ffm' | 'fmm' | 'verified-amateurs' | 'verified-models' | 'behind-the-scenes' | 'old-young' | 'parody' | 'pissing' | 'sfw' | 'described-video' | 'cosplay' | 'cuckold' | 'amateur-gay' | 'handjob-gay' | 'uncut-gay' | 'rough-sex-gay' | 'jock-gay' | 'mature-gay' | 'webcam-gay' | 'cumshot-gay' | 'casting-gay' | 'pov-gay' | 'compilation-gay' | 'chubby-gay' | 'military-gay' | 'feet-gay' | 'cartoon-gay' | 'step-fantasy' | 'verified-couples' | 'solo-female' | 'female-orgasm' | 'muscular-men' | 'romantic' | 'scissoring' | 'strap-on' | 'tattooed-men-gay' | 'tattooed-women' | 'trans-with-girl' | 'trans-with-guy' | 'fingering' | 'trans-male' | '360' | '180' | '2d' | '3d' | 'voyeur' | 'uncensored' | 'verified-amateurs-gay' | 'closed-captions' | 'closed-captions-gay']¶
The categories of the video.
-
dictify(keys: 'all' | list[str] =
'all', recursive: bool =False) dict¶ Convert the object to a dictionary.
- download(path: Union[str, os.PathLike], quality: Quality | str = 'best', *, downloader: Union[Callable, str] = <function default>, display: Callable[[int, int], None] = <function progress.<locals>.wrapper>, convert: bool = False) str¶
Download the video to a file.
- fetch(key: str) Any¶
Lazily fetch some data.
- key format:
data@<dkey> => Get key from API page@<pkey> => Scrape key from page <dkey>|<pkey> => Choose considering cache
Whether the video is part of free premium.
- property preview : Image¶
The preview ‘mediabook’ of the video. This is the lazy video displayed when hovering the video.