Skip to main content

Async Object-oriented Python SDK for the Pexels API.

Overview • Quick Start • Examples • Bugs and Feature Requests • PyPI

GitHub release (latest SemVer) PyPI - Version GitHub issues Build Status Checked with mypy
PyPI - Downloads PyPI - Python Version codecov

Overview

This SDK is designed to interact with the Pexels API in a more object-oriented way. It provides asynchronous methods to interact with the API. The SDK is designed to be as simple as possible to use, while still providing a lot of flexibility and uses Pydantic models to validate the data.
Used dependencies:

  • httpx for asynchronous API
  • pydantic for models

Supported Python versions:

  • 3.11
  • 3.12

Quick Start

After installing the SDK, you can create a new instance of the API. When creating a new instance, you can either use environment variables or pass the credentials directly. It's strongly recommended to use environment variables to store the API credentials.

Installation

pip install pypexel

Create a new instance of the API

It's recommended to use an environment variable to store the API credentials:

import os

os.environ["PEXELS_API_KEY"] = "your-api-key"

To work asynchronously:

import pypexel as pex

# Using environment variables:
api = pex.AsyncApi.from_env()

# Or using the credentials directly:
api = pex.AsyncApi("your-api-key")

Examples

You'll find detailed docs with usage examples for both APIs and for used models in the corresponding package directories:

In this section, you'll find some examples of how to use the SDK. You can also check out the demo.py file in the root directory for more examples.

Search for photos

import asyncio
import os
import pypexel as pex

os.environ["PEXELS_API_KEY"] = "your-api-key"

api = pex.AsyncApi.from_env()

async def main():
    # Search for photos with the query "nature"
    photos = await api.photos.search("nature", limit=10)
    
    # Print the first photo's URL
    if photos:
        print(photos[0].src.original)
    else:
        print("No photos found.")

asyncio.run(main())

Search for videos

import asyncio
import os
import pypexel as pex

os.environ["PEXELS_API_KEY"] = "your-api-key"
api = pex.AsyncApi.from_env()

async def main():
    # Search for videos with the query "nature"
    videos = await api.videos.search("nature", limit=10)
    
    # Print the first video URL
    if videos:
        print(videos[0].video_files[0].link)
    else:
        print("No videos found.")

asyncio.run(main())

Bugs and Feature Requests

If you find a bug or have a feature request, please open an issue on the GitHub repository.
You're also welcome to contribute to the project by opening a pull request.

Metadata

Release files for pypexel 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pypexel 0.0.2
File Size Uploaded Provenance Actions
pypexel-0.0.2.tar.gz 11.0 kB Without provenance Details for pypexel-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pypexel 0.0.2
File Interpreter ABI Platform Actions
pypexel-0.0.2-py3-none-any.whl Python 3 none any Details for pypexel-0.0.2-py3-none-any.whl

Total release size: 23.1 kB

Release files / pypexel-0.0.2.tar.gz

Download URL pypexel-0.0.2.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7b74b52b7475b30f532a9fb1a96117d03285f0f4c40b9451778ac0d143c39251
BLAKE2b-256 checksum
How to use checksums
9e7ebfe32993a3e2931da7f43c1d9185fc6675de88bb4dcccaddaa4aa2afce0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / pypexel-0.0.2-py3-none-any.whl

Download URL pypexel-0.0.2-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cac89096b140a625d465ff541c771b2c88b2599373b3fc2e77b03319b218c477
BLAKE2b-256 checksum
How to use checksums
1fc92dd72303aaba67eb3df1e5de42b7eaec265d230aa5f09d3dbfab2f3e68aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for pypexel 0.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page