Skip to main content

Official Python SDK for OKSLOP - AI stock photos

Project description

okslop

OKSLOP — Python SDK

The official Python client for OKSLOP — free, AI-generated stock photos for any project.

OKSLOP gives you instant access to a library of AI-generated images — search by keyword, filter by style, or generate exactly what you need from a text prompt. Use them in blogs, apps, docs, landing pages, social content, or anywhere you need a visual. No attribution required, no licensing fees, no hassle.

Browse photos and AI creators at okslop.com. Get your free API key to start building.

Homepage okslop.com
Documentation okslop.com/developers
PyPI pypi.org/project/okslop
TypeScript SDK npmjs.com/package/okslop

Installation

pip install okslop

Quick Start

from okslop import OKSLOP

# Initialize (works without API key, optional for higher limits)
client = OKSLOP()

# Or with API key
client = OKSLOP(api_key="your-api-key")

# Search for photos
result = client.photos.search(query="cozy coffee shop morning light", per_page=10)
for photo in result.results:
    print(f"{photo.id}: {photo.alt_description}")

# Get a specific photo
photo = client.photos.get("abc123")
print(photo.urls.full)

# Download to file
client.photos.download_file("abc123", "photo.webp")

# Get random photos
photos = client.photos.random(count=5)

# Generate a new image (requires API key)
result = client.embed(
    prompt="minimalist desk setup with plants",
    contributor="modern-minimal"
)

API Reference

OKSLOP(api_key=None, base_url=None)

Initialize the client.

  • api_key (optional): Your API key for higher rate limits
  • base_url (optional): Override API base URL (default: https://api.okslop.com/api/v1)

Photos

client.photos.search(query, page=None, per_page=None, orientation=None, sort=None, contributor=None)

Search for photos by semantic query.

Returns: SearchResult with .results list of Photo

client.photos.get(id)

Get a single photo by ID.

Returns: Photo

client.photos.list(page=None, per_page=None, sort=None)

List photos.

Returns: PaginatedPhotos

client.photos.random(count=None, query=None, orientation=None)

Get random photos.

Returns: List[Photo]

client.photos.download(id)

Get download URL for a photo.

Returns: dict with url

client.photos.download_file(id, path, size="full")

Download a photo to disk.

  • size: "thumb" (400px), "small" (800px), "full" (2000px), or "raw"

Returns: Path

Categories

client.categories.list()

List all categories.

Returns: List[Category]

client.categories.get(slug)

Get a category by slug.

Returns: Category

client.categories.photos(slug, page=None, per_page=None)

Get photos in a category.

Returns: PaginatedPhotos

Collections

client.collections.list(page=None, per_page=None)

List collections.

Returns: List[Collection]

client.collections.get(slug)

Get a collection by slug.

Returns: Collection

client.collections.photos(slug, page=None, per_page=None)

Get photos in a collection.

Returns: PaginatedPhotos

Embed (Image Generation)

client.embed(prompt, contributor, orientation=None, seed=None, instant=None)

Generate a new image from a prompt. Requires API key.

Returns: EmbedResult

client.embed_batch(requests)

Generate multiple images. Requires API key.

Returns: List[EmbedResult]

Photo Object

photo.id               # Unique ID
photo.description      # Description
photo.alt_description  # Alt text
photo.width            # Width in pixels
photo.height           # Height in pixels
photo.color            # Dominant color hex
photo.urls.thumb       # 400px URL
photo.urls.small       # 800px URL
photo.urls.regular     # 1080px URL
photo.urls.full        # 2000px URL
photo.urls.raw         # Original resolution
photo.user.name        # Contributor name
photo.user.username    # Contributor username
photo.downloads        # Download count
photo.views            # View count
photo.likes            # Like count

Async Support

from okslop import AsyncOKSLOP

async def main():
    async with AsyncOKSLOP() as client:
        result = await client.photos.search(query="mountains")
        for photo in result.results:
            print(photo.id)

import asyncio
asyncio.run(main())

CLI

For CLI usage, use the npx CLI (requires Node.js):

npx okslop search "coffee shop" --limit 5
npx okslop download abc123 --output photo.webp

Development

Models are generated from packages/sdk-spec/okslop-spec.json (extracted from TypeScript SDK).

# Generate models from spec
pnpm generate

# Or directly
python3 scripts/generate.py

This generates:

  • src/okslop/models.py — Pydantic models
  • src/okslop/_methods.py — Method specs

Building

pnpm build   # generate + build wheel

Publishing to PyPI

./scripts/publish.sh         # publish to PyPI
./scripts/publish.sh --test  # publish to TestPyPI first

Requires TWINE_API_TOKEN env var or ~/.pypirc credentials.

Links

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

okslop-0.0.2.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

okslop-0.0.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file okslop-0.0.2.tar.gz.

File metadata

  • Download URL: okslop-0.0.2.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.7

File hashes

Hashes for okslop-0.0.2.tar.gz
Algorithm Hash digest
SHA256 869136599244d53e910004d83c52b4d7c1fe401f3fb8a11bfdc38b0e20324543
MD5 69f83069ca09604392c9530aebeafe43
BLAKE2b-256 b9cfab6a247c93aa0f79f1226d2ae196634786251f90296e773b08e834131609

See more details on using hashes here.

File details

Details for the file okslop-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: okslop-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.7

File hashes

Hashes for okslop-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c70d6853e95acfdb7a0c3d5b0f1a99263911a83276d03c780292b16f341c6cc6
MD5 f1effc3d86c7e64002067333609f30e6
BLAKE2b-256 02374e28d130f3fb0b542913dcf6dbeef3853ec1ed444571e4aba0804efe9603

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