Skip to main content

Async Object-oriented Python SDK for the Pexels API.

Project description

Async Object-oriented Python SDK for the Pexels API.

OverviewQuick StartExamplesBugs and Feature RequestsPyPI

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.

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

pypexel-0.0.1.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypexel-0.0.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file pypexel-0.0.1.tar.gz.

File metadata

  • Download URL: pypexel-0.0.1.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pypexel-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f34cfeebe7865216afef86f136d1a08e140f1018757a25f5b77e7bde6f2e8c73
MD5 d77c492b889ed7df3120c7757e294777
BLAKE2b-256 b847cfb6d9ba6dbc4751268c86902ed1a9d41d262bbe194e9926c3336f1a402d

See more details on using hashes here.

File details

Details for the file pypexel-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pypexel-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pypexel-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 91f6497fc3a43522a2421d6ca10c384dc1e18f9b154c11c1625827097682793b
MD5 e2c7a93d950db364e9766afe5cdd00c1
BLAKE2b-256 81e6ba7d6046a6b3bea98733a72e8e1cae5d10c6fceb777ff0f74edfdc53f98f

See more details on using hashes here.

Supported by

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