Pexels API Python Wrapper
Disclaimer
This project is an independent, community-maintained Python wrapper for the Pexels API. It is not affiliated with, endorsed by, or maintained by Pexels.
An elegant, developer-friendly Python client library for interacting seamlessly with the Pexels REST API.
Unlike naive wrappers, this package uses Pydantic v2 to perform robust client-side validation on your parameters before hitting the network—saving you latency, bandwidth, and unhandled remote API errors.
Features
- Pydantic-powered Validation: Caught invalid page bounds, dimensions, orientations, or hexadecimal colors locally before triggering HTTP requests.
- Clean Interface: Consistent method signatures exposing Photo, Video, and Curated/Featured Collection endpoints.
- Fail-Safe Response Analysis: Safe management of common HTTP statuses (
400,401,404) with programmatic reporting. - Transparent Rate Limiting: Automatic tracking and console reporting of monthly quotas (
X-Ratelimit-*) parsed exclusively from successful hits.
Installation
Install the package via pip:
pip install pexels-sdk
Quick Start
1. Initializing the Client
Obtain an API key from the Pexels API Documentation portal.
from pexels import Client
# Note: Pexels uses raw keys. The client automatically manages
# the header authorization for you without a "Bearer" prefix.
client = Client(api_key="YOUR_PEXELS_API_KEY")
Photo Endpoints
Search Photos
Search for photos using a required query and optional filters such as orientation, size, color, locale, page, and per_page.
search_results = client.search_photos(
query="nature",
orientation="landscape",
size="large",
page=1,
per_page=10
)
for photo in search_results["photos"]:
print(photo["photographer"])
print(photo["src"]["original"])
Curated Photos
Retrieve curated photos from the Pexels curated feed.
curated = client.curated_photos(page=1, per_page=10)
for photo in curated["photos"]:
print(photo["photographer"])
Get a Single Photo
Fetch a specific photo by its unique ID.
photo = client.get_a_photo(photo_id=2014422)
print(photo)
Video Endpoints
Search Videos
Search for videos using keyword-based filtering and supported video parameters.
videos = client.search_for_videos(
query="mountains",
orientation="landscape",
size="large",
page=1,
per_page=10
)
for video in videos["videos"]:
print(video["user"]["name"])
Popular Videos
Retrieve popular videos with optional dimension and duration filters.
popular = client.popular_videos(
min_width=1280,
min_height=720,
min_duration=5,
max_duration=30,
page=1,
per_page=10
)
for video in popular["videos"]:
print(video["id"])
Get a Single Video
Fetch a specific video by its unique ID.
video = client.get_a_video(video_id=123456)
print(video)
Collection Endpoints Featured Collections
Get a list of featured collections.
featured = client.featured_collections(page=1, per_page=10)
for collection in featured["collections"]:
print(collection["title"])
My Collections
Retrieve the authenticated user’s collections.
collections = client.my_collections(page=1, per_page=10)
for collection in collections["collections"]:
print(collection["title"])
Collection Media
Get the media items inside a specific collection.
media = client.collection_media(
collection_id=12345,
collection_type="photos",
sort="asc",
page=1,
per_page=10
)
print(media)
Validation
This package uses Pydantic v2 to validate input parameters before sending any HTTP request.
Invalid values are rejected locally, which helps reduce unnecessary network traffic and prevents avoidable API errors.
Examples of validation-covered parameters include:
page bounds
image dimensions
orientations
colors in hexadecimal format
video duration filters
from pydantic import ValidationError
try:
client.search_photos(query="city", page=-1)
except ValidationError as e:
print(f"Validation error: {e}")
Error Handling
The client includes a ResponseAnalyzer layer that inspects API responses and handles common HTTP statuses such as:
400 Bad Request
401 Unauthorized
404 Not Found
This gives you a cleaner and more predictable error-handling flow.
from pexels.exceptions import PexelsAPIError
try:
client.search_photos(query="ocean")
except PexelsAPIError as e:
print(f"API Error ({e.status_code}): {e.message}")
Rate Limiting
The client also tracks rate-limit information returned by Pexels headers such as:
X-Ratelimit-Limit
X-Ratelimit-Remaining
X-Ratelimit-Reset
This makes quota usage more transparent during development and production use.
client.search_photos(query="architecture")
print(client.rate_limit_remaining)
Project Highlights
Pydantic-powered validation before API calls
Clean endpoint coverage for photos, videos, and collections
Safe response analysis for common HTTP failures
Transparent quota awareness via rate-limit headers
Simple authorization flow using raw Pexels API keys
Contributing
Contributions are welcome and appreciated.
Fork the Project
Create your Feature Branch:
git checkout -b feature/AmazingFeature
Commit your Changes:
git commit -m "Add some AmazingFeature"
Push to the Branch:
git push origin feature/AmazingFeature
License
Distributed under the MIT License. See the LICENSE file for more information.
Metadata
Release files for pexels-sdk 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pexels_sdk-1.1.2.tar.gz | 14.1 kB | With provenance | Details for pexels_sdk-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pexels_sdk-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for pexels_sdk-1.1.2-py3-none-any.whl |
Total release size: 29.2 kB
Release files / pexels_sdk-1.1.2.tar.gz
| Download URL | pexels_sdk-1.1.2.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76ae2354eb595471afbcc88fba8a234e8d7a11f3b3e23ad4c6788c2ad18c704d
|
|
BLAKE2b-256 checksum How to use checksums |
3d04fda5c6dbdbdd0267798c477302faa6ee8e2e9980782651cd2a67876339b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.
Transparency logRelease files / pexels_sdk-1.1.2-py3-none-any.whl
| Download URL | pexels_sdk-1.1.2-py3-none-any.whl |
|---|---|
| Size | 15.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c899b6a978f7f05df4ac3b4dd0e6a696cf0a2bd70ccff8b463937655463510c
|
|
BLAKE2b-256 checksum How to use checksums |
72c3a33561a3c062b06fbf8c1ba81df8757708633b47d835c8f3c72092057da0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.
Transparency logSecurity for pexels-sdk 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pexels_sdk-1.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.