Skip to main content

Python SDKs for free stock media APIs — Pexels, Pixabay, and more.

Project description

stockmedia-sdk

Python SDKs for free stock media APIs — Pexels + Pixabay, cleanly wrapped.

from stockmedia_sdk import PexelsClient, PixabayClient

pexels = PexelsClient(api_key="...")
pixabay = PixabayClient(api_key="...")

Features

  • Pexels: Photos, Videos, Collections
  • Pixabay: Images, Videos with all quality variants
  • Full type annotations with frozen dataclass models
  • Enum-based parameter validation
  • Auto-pagination helpers (*_all() methods)
  • Rate limit tracking from response headers
  • Typed exception hierarchy
  • Retry logic for transient failures
  • Context manager support
  • Zero heavy dependencies (only requests)

Installation

pip install stockmedia-sdk

Pexels

from stockmedia_sdk import PexelsClient
# or: from stockmedia_sdk.pexels import PexelsClient

client = PexelsClient(api_key="YOUR_API_KEY")

# Search photos
result = client.search_photos("nature", per_page=10)
for photo in result.results:
    print(photo.photographer, photo.src.large)

# Get a single photo
photo = client.get_photo(2014422)

# Auto-paginate through all results
for page in client.search_photos_all("sunset", max_pages=3):
    for photo in page:
        print(photo.url)

Client Options

client = PexelsClient(
    api_key="YOUR_API_KEY",
    timeout=30,                # Request timeout (seconds)
    max_retries=2,             # Auto-retry on 5xx/429
    auto_rate_limit_wait=False # Sleep+retry when rate-limited
)

Search Filters

from stockmedia_sdk import Orientation, Size, Color, Locale

client.search_photos(
    "ocean",
    orientation=Orientation.LANDSCAPE,
    size=Size.LARGE,
    color=Color.BLUE,
    locale=Locale.ZH_CN,
)

Error Handling

from stockmedia_sdk import (
    PexelsError, PexelsAuthenticationError,
    PexelsRateLimitError, PexelsNotFoundError,
)

try:
    photo = client.get_photo(999999999)
except PexelsNotFoundError:
    print("Photo not found")
except PexelsRateLimitError as e:
    print(f"Rate limited, retry after {e.retry_after}s")

API Reference

Photos Videos Collections
search_photos(q, ...) search_videos(q, ...) featured_collections(...)
search_photos_all(q, ...) search_videos_all(q, ...) featured_collections_all(...)
curated_photos(...) popular_videos(...) get_collection_media(id, ...)
curated_photos_all(...) popular_videos_all(...) get_collection_media_all(id, ...)
get_photo(id) get_video(id)

Rate limit: 200 req/hour, 20k req/month. Track via client.rate_limit_info.


Pixabay

from stockmedia_sdk import PixabayClient
# or: from stockmedia_sdk.pixabay import PixabayClient

client = PixabayClient(api_key="YOUR_API_KEY")

# Search images
result = client.search_images("yellow flowers", image_type="photo", per_page=20)
for img in result.hits:
    print(img.webformat_url)

# Search videos
result = client.search_videos("ocean", per_page=10)
for video in result.hits:
    print(video.videos.medium.url)

# Auto-paginate
for page in client.search_images_all("sunset", max_pages=3):
    for img in page:
        print(img.large_image_url)

Search Filters

from stockmedia_sdk import ImageType, Orientation, Category, Color, Language, Order

client.search_images(
    "ocean",
    image_type=ImageType.PHOTO,
    orientation=Orientation.HORIZONTAL,
    category=Category.NATURE,
    colors=[Color.BLUE, Color.GREEN],
    order=Order.LATEST,
    lang=Language.ZH,
    min_width=1920, min_height=1080,
    editors_choice=True, safesearch=True,
)

Error Handling

from stockmedia_sdk import (
    PixabayError, PixabayAuthenticationError,
    PixabayRateLimitError, PixabayNotFoundError,
)

API Reference

Images Videos
search_images(q, ...) search_videos(q, ...)
search_images_all(q, ...) search_videos_all(q, ...)
get_image(id) get_video(id)

Rate limit: 100 req/60s. Max 500 results per query. Track via client.rate_limit_info.

Image URL Sizes

Replace _640 in webformat_url or use convenience properties:

img.webformat_url    # max 640px
img.webformat_180    # 180px tall
img.webformat_340    # 340px tall
img.webformat_960    # 960 x 720 px
img.large_image_url  # max 1280px

Data Models

Pexels Pixabay
Photo Image
PhotoSource Video
Video / VideoFile / VideoPicture VideoQuality / VideoSizeSet
Collection PixabayResponse[T]
PagedResponse[T] RateLimitInfo
RateLimitInfo

All models are frozen dataclasses with from_dict() classmethods.

License

MIT

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

stockmedia_sdk-1.0.5.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

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

stockmedia_sdk-1.0.5-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file stockmedia_sdk-1.0.5.tar.gz.

File metadata

  • Download URL: stockmedia_sdk-1.0.5.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for stockmedia_sdk-1.0.5.tar.gz
Algorithm Hash digest
SHA256 f19505fd48e60b04573c834c75a16b69bb2f4c68c34ca3b8a43307c5bd7653d5
MD5 a9b1b269a6674e91d46a93dca2ab3052
BLAKE2b-256 d60f5e7a0fbd6e484283d6845de16564199185bac08e3fe4b8b5a0ca75045600

See more details on using hashes here.

File details

Details for the file stockmedia_sdk-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: stockmedia_sdk-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for stockmedia_sdk-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 18108eae60e183aa0ae571c66d826f522979b8b4d0b0aba7731aeb7eaf04c594
MD5 6c869de3f1666c11ed75b897f75d1625
BLAKE2b-256 df22ef52abcc6cbe878e6bddc4c2e76fceaba01b40466b8b4eef85ad53d1a142

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