Skip to main content

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

Metadata

Release files for stockmedia-sdk 1.0.5

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

Source distribution (sdist)

Source distribution for stockmedia-sdk 1.0.5
File Size Uploaded Provenance Actions
stockmedia_sdk-1.0.5.tar.gz 22.1 kB Without provenance Details for stockmedia_sdk-1.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for stockmedia-sdk 1.0.5
File Interpreter ABI Platform Actions
stockmedia_sdk-1.0.5-py3-none-any.whl Python 3 none any Details for stockmedia_sdk-1.0.5-py3-none-any.whl

Total release size: 44.7 kB

Release files / stockmedia_sdk-1.0.5.tar.gz

Download URL stockmedia_sdk-1.0.5.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f19505fd48e60b04573c834c75a16b69bb2f4c68c34ca3b8a43307c5bd7653d5
BLAKE2b-256 checksum
How to use checksums
d60f5e7a0fbd6e484283d6845de16564199185bac08e3fe4b8b5a0ca75045600
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / stockmedia_sdk-1.0.5-py3-none-any.whl

Download URL stockmedia_sdk-1.0.5-py3-none-any.whl
Size 22.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18108eae60e183aa0ae571c66d826f522979b8b4d0b0aba7731aeb7eaf04c594
BLAKE2b-256 checksum
How to use checksums
df22ef52abcc6cbe878e6bddc4c2e76fceaba01b40466b8b4eef85ad53d1a142
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for stockmedia-sdk 1.0.5

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

1.0.5 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