Package: pexels-api-with-video-searches
Using Pexels API v1 with PythonUsepexels_apito search photos fromPexels.Dependencies:requestsInstallation:pip install pexels-apiUsage:The following code shows you how to import the package and make a simple query to Pexels API v1. See moreexamplesor thedocumentation.# Import API class from pexels_api packagefrompexels_apiimportAPI# Type your Pexels APIPEXELS_API_KEY='YOUR-PEXELS-API-KEY'# Create API objectapi=API(PEXELS_API_KEY)# Search five 'kitten' photosapi.search('kitten',page=1,results_per_page=5)# Get photo entriesphotos=api.get_entries()# Loop the five photosforphotoinphotos:# Print photographerprint('Photographer: ',photo.photographer)# Print urlprint('Photo url: ',photo.url)# Print original size urlprint('Photo original size: ',photo.original)Examples:search.py:Specify a query to search photos.popular.py:Search popular photos.curated.py:Search curated photos.Documentation:Class: APIMethodsPropertiesClass: PhotoPropertiesClass: APIAPI(PEXELS_API_KEY)Creates an instance of aAPIobject.ParameterRequiredTypeDescriptionPEXELS_API_KEYYesStringYour Pexels API keyReturns:An instance of aAPIobject.Methods:search(query, photos_per_page=15, page=1)Given a query requests data using Pexels API v1.ParameterRequiredTypeDescriptionqueryYesStringThe topic to searchphotos_per_pageNo.(Default value: 15)IntegerNumber of photos per page 1 minimum 80 maximumpageNo.(Default value: 1)IntegerSpecify the page to searchReturns:A dictionary containing json data of the results of the query in the specified page,Noneif the request fails.popular(photos_per_page=15, page=1)Requests popular data using Pexels API v1.ParameterRequiredTypeDescriptionphotos_per_pageNo.(Default value: 15)IntegerNumber of photos per page 1 minimum 80 maximumpageNo.(Default value: 1)IntegerSpecify the page to searchReturns:A dictionary containing json data of the results of Pexels popular page in the specified page,Noneif the request fails.curated(photos_per_page=15, page=1)Requests curated data using Pexels API v1.ParameterRequiredTypeDescriptionphotos_per_pageNo.(Default value: 15)IntegerNumber of photos per page 1 minimum 80 maximumpageNo.(Default value: 1)IntegerSpecify the page to searchReturns:A dictionary containing json data of the results of Pexels curated page in the specified page,Noneif the request fails.search_next_page()Search the next page if available.Returns:A dictionary containing json data of the next page,Noneif page not found.search_previous_page()Search the previous page if available.Returns:A dictionary containing json data of the previous page,Noneif page not found.get_entries()Creates an instance of aPhotoobject for each photo in the current page.Returns:A list ofPhotoobjects.Properties:By default theAPIproperties areNone. Whenseacrh(),popular()orcurated()is performed theAPIproperties are updated.PropertyTypeDescriptionrequestObject (requests)Current request,Noneif request failsjsonDictionaryA dictionary with the data of the current pagepageIntegerNumber of the pagetotal_resultsIntegerNumber of total results. (Noneinpopularandcuratedpage)page_resultsIntegerNumber of results in the current pagehas_next_pageBooleanTrueif there is a next page elseFalsehas_previous_pageBooleanTrueif there is a previous page elseFalsenext_pageStringUrl to the next page. (Noneif there is no next page)prev_pageStringUrl to the previous page. (Noneif there is no previous page)Class: PhotoPhoto(json_photo)ParameterRequiredTypeDescriptionjson_photoYesDictionaryA dictionary containing json data of the photo of which you want the propertiesReturns:An instance of aPhotoobject.Properties:PropertyTypeDescriptionidIntegerUnique Pexels identifierwidthIntegerWidth of the original photoheightIntegerHeight of the original photophotographerStringPhoto's photographerurlStringPhoto's photographerdescriptionStringPhoto's descriptionoriginalStringPhoto's original size urlcompressedStringPhoto's compressed size urllarge2xStringPhoto's large2x size urllargeStringPhoto's large size urlmediumStringPhoto's medium size urlsmallStringPhoto's small size urlportraitStringPhoto's portrait size urllandscapeStringPhoto's landscape size urltinyStringPhoto's tiny size urlextensionStringPhoto's extension