Skip to main content

Use Pexels API v1 with Python

Project description

Using Pexels API v1 with Python

Use pexels_api to search photos from Pexels.

Dependencies:

Installation:

pip install pexels-api

Usage:

The following code shows you how to import the package and make a simple query to Pexels API v1. See more examples or the documentation.

# Import API class from pexels_api package
from pexels_api import API

# Type your Pexels API
PEXELS_API_KEY = 'YOUR-PEXELS-API-KEY'
# Create API object
api = API(PEXELS_API_KEY)
# Search five 'kitten' photos
api.search('kitten', page=1, results_per_page=5)
# Get photo entries
photos = api.get_entries()
# Loop the five photos
for photo in photos:
  # Print photographer
  print('Photographer: ', photo.photographer)
  # Print url
  print('Photo url: ', photo.url)
  # Print original size url
  print('Photo original size: ', photo.original)

Examples:

Documentation:

Class: API

API(PEXELS_API_KEY)

Creates an instance of a API object.

Parameter Required Type Description
PEXELS_API_KEY Yes String Your Pexels API key
Returns:

An instance of a API object.

Methods:

search(query, photos_per_page=15, page=1)

Given a query requests data using Pexels API v1.

Parameter Required Type Description
query Yes String The topic to search
photos_per_page No. (Default value: 15) Integer Number of photos per page 1 minimum 80 maximum
page No. (Default value: 1) Integer Specify the page to search
Returns:

A dictionary containing json data of the results of the query in the specified page, None if the request fails.

popular(photos_per_page=15, page=1)

Requests popular data using Pexels API v1.

Parameter Required Type Description
photos_per_page No. (Default value: 15) Integer Number of photos per page 1 minimum 80 maximum
page No. (Default value: 1) Integer Specify the page to search
Returns:

A dictionary containing json data of the results of Pexels popular page in the specified page, None if the request fails.

curated(photos_per_page=15, page=1)

Requests curated data using Pexels API v1.

Parameter Required Type Description
photos_per_page No. (Default value: 15) Integer Number of photos per page 1 minimum 80 maximum
page No. (Default value: 1) Integer Specify the page to search
Returns:

A dictionary containing json data of the results of Pexels curated page in the specified page, None if the request fails.

search_next_page()

Search the next page if available.

Returns:

A dictionary containing json data of the next page, None if page not found.

search_previous_page()

Search the previous page if available.

Returns:

A dictionary containing json data of the previous page, None if page not found.

get_entries()

Creates an instance of a Photo object for each photo in the current page.

Returns:

A list of Photo objects.

Properties:

By default the API properties are None. When seacrh(), popular() or curated() is performed the API properties are updated.

Property Type Description
request Object (requests) Current request, None if request fails
json Dictionary A dictionary with the data of the current page
page Integer Number of the page
total_results Integer Number of total results. (None in popular and curated page)
page_results Integer Number of results in the current page
has_next_page Boolean True if there is a next page else False
has_previous_page Boolean True if there is a previous page else False
next_page String Url to the next page. (None if there is no next page)
prev_page String Url to the previous page. (None if there is no previous page)

Class: Photo

Photo(json_photo)

Parameter Required Type Description
json_photo Yes Dictionary A dictionary containing json data of the photo of which you want the properties
Returns:

An instance of a Photo object.

Properties:

Property Type Description
id Integer Unique Pexels identifier
width Integer Width of the original photo
height Integer Height of the original photo
photographer String Photo's photographer
url String Photo's photographer
description String Photo's description
original String Photo's original size url
compressed String Photo's compressed size url
large2x String Photo's large2x size url
large String Photo's large size url
medium String Photo's medium size url
small String Photo's small size url
portrait String Photo's portrait size url
landscape String Photo's landscape size url
tiny String Photo's tiny size url
extension String Photo's extension

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pexels_api_with_video_searches-1.0.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file pexels_api_with_video_searches-1.0.1.tar.gz.

File metadata

File hashes

Hashes for pexels_api_with_video_searches-1.0.1.tar.gz
Algorithm Hash digest
SHA256 14124496b3450f5bf0a7c5cd0cf6b2ff73949f8cbd7d88033be6548d0eb3f850
MD5 b24370818186d47a4ad2d0b79944784a
BLAKE2b-256 e379ae15557635da9bb17af6d627eb1dd25dc247f156a2fad755831bdce32ccf

See more details on using hashes here.

File details

Details for the file pexels_api_with_video_searches-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pexels_api_with_video_searches-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5604f6f4760740520676c0e15641b8395076ace9b7b4fbf354fab8da3aa47ff3
MD5 5216e5ace484347476815e121f485e80
BLAKE2b-256 88f11a6e8b35a356df18ea27721f32fcb516b70c1564dcfed582f87cbe748f72

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page