# Using Pexels API v1 with Python
Use *[pexels_api][2]* to search photos from [Pexels][0].
## Dependencies:
- [requests][1]
## 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][14] or the [documentation][15].
```python
# 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:
- *[search.py:][3]*
Specify a query to search photos.
- *[popular.py:][4]*
Search popular photos.
- *[curated.py:][5]*
Search curated photos.
## Documentation:
- [Class: API][6]
- [Methods][7]
- [Properties][8]
- [Class: Photo][9]
- [Properties][10]
## Class: API
#### `API(PEXELS_API_KEY)`
Creates an instance of a *[API][6]* object.
|Parameter|Required|Type|Description|
|:-|:-|:-|:-|
|PEXELS_API_KEY |Yes|String|Your Pexels API key|
##### Returns:
An instance of a *[API][6]* 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][9]* object for each photo in the current page.
##### Returns:
A list of *[Photo][9]* objects.
### Properties:
By default the *[API][6]* properties are `None`. When *[seacrh()][11]*, *[popular()][12]* or *[curated()][13]* is performed the *[API][6]* properties are updated.
|Property|Type|Description|
|:-|:-|:-|
|request|Object ([requests][1])|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][9]* 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|
<!-- References -->
[0]: https://pexels.com "Pexels website"
[1]: https://2.python-requests.org/en/master/ "Documentation: requests"
<!-- Documentation -->
[2]: /pexels_api "pexels_api package"
[3]: /examples/search.py "Using pexels_api to search photos"
[4]: /examples/popular.py "Using pexels_api to search popular photos"
[5]: /examples/curated.py "Using pexels_api to search curated photos"
[6]: #class-api "Class: API"
[7]: #methods "API: methods"
[8]: #properties "API: properties"
[9]: #class-photo "Class: Photo"
[10]: #properties-1 "Photo: properties"
[11]: #searchquery-photos_per_page15-page1 "API method: search"
[12]: #popularphotos_per_page15-page1 "API method: popular"
[13]: #curatedphotos_per_page15-page1 "API method: curated"
[14]: #examples "Examples: pexels_api"
[15]: #documentation "Documentation: pexels_api"
Raw data
{
"_id": null,
"home_page": "https://github.com/Voltaic314/pexels-api-custom-voltaic",
"name": "pexels-api-with-video-searches",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "pexels api images photos videos",
"author": "Logan Maupin",
"author_email": "lmaupin@arizona.edu",
"download_url": "https://files.pythonhosted.org/packages/e3/79/ae15557635da9bb17af6d627eb1dd25dc247f156a2fad755831bdce32ccf/pexels_api_with_video_searches-1.0.1.tar.gz",
"platform": null,
"description": "# Using Pexels API v1 with Python\r\nUse *[pexels_api][2]* to search photos from [Pexels][0].\r\n## Dependencies:\r\n- [requests][1]\r\n\r\n## Installation:\r\n`pip install pexels-api`\r\n\r\n## Usage:\r\nThe following code shows you how to import the package and make a simple query to Pexels API v1. See more [examples][14] or the [documentation][15].\r\n\r\n```python\r\n# Import API class from pexels_api package\r\nfrom pexels_api import API\r\n\r\n# Type your Pexels API\r\nPEXELS_API_KEY = 'YOUR-PEXELS-API-KEY'\r\n# Create API object\r\napi = API(PEXELS_API_KEY)\r\n# Search five 'kitten' photos\r\napi.search('kitten', page=1, results_per_page=5)\r\n# Get photo entries\r\nphotos = api.get_entries()\r\n# Loop the five photos\r\nfor photo in photos:\r\n # Print photographer\r\n print('Photographer: ', photo.photographer)\r\n # Print url\r\n print('Photo url: ', photo.url)\r\n # Print original size url\r\n print('Photo original size: ', photo.original)\r\n```\r\n## Examples:\r\n- *[search.py:][3]* \r\nSpecify a query to search photos.\r\n- *[popular.py:][4]* \r\nSearch popular photos.\r\n- *[curated.py:][5]* \r\nSearch curated photos.\r\n\r\n## Documentation:\r\n- [Class: API][6]\r\n - [Methods][7]\r\n - [Properties][8]\r\n- [Class: Photo][9]\r\n - [Properties][10]\r\n\r\n## Class: API\r\n#### `API(PEXELS_API_KEY)` \r\nCreates an instance of a *[API][6]* object.\r\n\r\n|Parameter|Required|Type|Description|\r\n|:-|:-|:-|:-|\r\n|PEXELS_API_KEY |Yes|String|Your Pexels API key|\r\n##### Returns:\r\nAn instance of a *[API][6]* object.\r\n### Methods:\r\n#### `search(query, photos_per_page=15, page=1)` \r\nGiven a query requests data using Pexels API v1.\r\n\r\n|Parameter|Required|Type|Description|\r\n|:-|:-|:-|:-|\r\n|query |Yes|String|The topic to search|\r\n|photos_per_page|No. *(Default value: 15)*|Integer|Number of photos per page 1 minimum 80 maximum|\r\n|page |No. *(Default value: 1)*|Integer|Specify the page to search|\r\n##### Returns:\r\nA dictionary containing json data of the results of the query in the specified page, `None` if the request fails. \r\n\r\n#### `popular(photos_per_page=15, page=1)` \r\nRequests popular data using Pexels API v1.\r\n\r\n|Parameter|Required|Type|Description|\r\n|:-|:-|:-|:-|\r\n|photos_per_page|No. *(Default value: 15)*|Integer|Number of photos per page 1 minimum 80 maximum|\r\n|page |No. *(Default value: 1)*|Integer|Specify the page to search|\r\n##### Returns:\r\nA dictionary containing json data of the results of Pexels popular page in the specified page, `None` if the request fails. \r\n#### `curated(photos_per_page=15, page=1)` \r\nRequests curated data using Pexels API v1.\r\n\r\n|Parameter|Required|Type|Description|\r\n|:-|:-|:-|:-|\r\n|photos_per_page|No. *(Default value: 15)*|Integer|Number of photos per page 1 minimum 80 maximum|\r\n|page |No. *(Default value: 1)*|Integer|Specify the page to search|\r\n##### Returns:\r\nA dictionary containing json data of the results of Pexels curated page in the specified page, `None` if the request fails. \r\n#### `search_next_page()`\r\nSearch the next page if available. \r\n##### Returns:\r\nA dictionary containing json data of the next page, `None` if page not found.\r\n#### `search_previous_page()`\r\nSearch the previous page if available. \r\n##### Returns:\r\nA dictionary containing json data of the previous page, `None` if page not found.\r\n#### `get_entries()`\r\nCreates an instance of a *[Photo][9]* object for each photo in the current page. \r\n##### Returns:\r\nA list of *[Photo][9]* objects.\r\n### Properties:\r\nBy default the *[API][6]* properties are `None`. When *[seacrh()][11]*, *[popular()][12]* or *[curated()][13]* is performed the *[API][6]* properties are updated. \r\n\r\n|Property|Type|Description|\r\n|:-|:-|:-|\r\n|request|Object ([requests][1])|Current request, `None` if request fails|\r\n|json|Dictionary|A dictionary with the data of the current page| \r\n|page|Integer|Number of the page| \r\n|total_results|Integer|Number of total results. (`None` in *popular* and *curated* page)|\r\n|page_results|Integer|Number of results in the current page| \r\n|has_next_page|Boolean|`True` if there is a next page else `False`|\r\n|has_previous_page|Boolean|`True` if there is a previous page else `False`|\r\n|next_page|String|Url to the next page. (`None` if there is no next page)|\r\n|prev_page|String|Url to the previous page. (`None` if there is no previous page)|\r\n\r\n## Class: Photo\r\n#### `Photo(json_photo)`\r\n| Parameter | Required |Type | Description |\r\n| :------------ | :- |:---- | :------------- |\r\n|json_photo |Yes|Dictionary|A dictionary containing json data of the photo of which you want the properties|\r\n\r\n##### Returns:\r\nAn instance of a *[Photo][9]* object.\r\n### Properties:\r\n|Property|Type|Description|\r\n|:-|:-|:-|\r\n|id|Integer|Unique Pexels identifier|\r\n|width|Integer|Width of the original photo|\r\n|height|Integer|Height of the original photo|\r\n|photographer|String|Photo's photographer|\r\n|url|String|Photo's photographer|\r\n|description|String|Photo's description|\r\n|original|String|Photo's original size url|\r\n|compressed|String|Photo's compressed size url|\r\n|large2x|String|Photo's large2x size url|\r\n|large|String|Photo's large size url|\r\n|medium|String|Photo's medium size url|\r\n|small|String|Photo's small size url|\r\n|portrait|String|Photo's portrait size url|\r\n|landscape|String|Photo's landscape size url|\r\n|tiny|String|Photo's tiny size url|\r\n|extension|String|Photo's extension|\r\n\r\n<!-- References -->\r\n[0]: https://pexels.com \"Pexels website\"\r\n[1]: https://2.python-requests.org/en/master/ \"Documentation: requests\"\r\n<!-- Documentation -->\r\n[2]: /pexels_api \"pexels_api package\"\r\n[3]: /examples/search.py \"Using pexels_api to search photos\"\r\n[4]: /examples/popular.py \"Using pexels_api to search popular photos\"\r\n[5]: /examples/curated.py \"Using pexels_api to search curated photos\"\r\n[6]: #class-api \"Class: API\"\r\n[7]: #methods \"API: methods\"\r\n[8]: #properties \"API: properties\"\r\n[9]: #class-photo \"Class: Photo\"\r\n[10]: #properties-1 \"Photo: properties\"\r\n[11]: #searchquery-photos_per_page15-page1 \"API method: search\"\r\n[12]: #popularphotos_per_page15-page1 \"API method: popular\"\r\n[13]: #curatedphotos_per_page15-page1 \"API method: curated\"\r\n[14]: #examples \"Examples: pexels_api\"\r\n[15]: #documentation \"Documentation: pexels_api\"\r\n",
"bugtrack_url": null,
"license": "",
"summary": "Use Pexels API v1 with Python",
"version": "1.0.1",
"split_keywords": [
"pexels",
"api",
"images",
"photos",
"videos"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "5216e5ace484347476815e121f485e80",
"sha256": "5604f6f4760740520676c0e15641b8395076ace9b7b4fbf354fab8da3aa47ff3"
},
"downloads": -1,
"filename": "pexels_api_with_video_searches-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5216e5ace484347476815e121f485e80",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7303,
"upload_time": "2022-12-20T03:34:50",
"upload_time_iso_8601": "2022-12-20T03:34:50.719055Z",
"url": "https://files.pythonhosted.org/packages/88/f1/1a6e8b35a356df18ea27721f32fcb516b70c1564dcfed582f87cbe748f72/pexels_api_with_video_searches-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "b24370818186d47a4ad2d0b79944784a",
"sha256": "14124496b3450f5bf0a7c5cd0cf6b2ff73949f8cbd7d88033be6548d0eb3f850"
},
"downloads": -1,
"filename": "pexels_api_with_video_searches-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "b24370818186d47a4ad2d0b79944784a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6297,
"upload_time": "2022-12-20T03:34:52",
"upload_time_iso_8601": "2022-12-20T03:34:52.589879Z",
"url": "https://files.pythonhosted.org/packages/e3/79/ae15557635da9bb17af6d627eb1dd25dc247f156a2fad755831bdce32ccf/pexels_api_with_video_searches-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-20 03:34:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Voltaic314",
"github_project": "pexels-api-custom-voltaic",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pexels-api-with-video-searches"
}