Skip to main content

langchain-pexafy

LangChain and LangGraph tools for Pexafy: semantic search over 9M+ free stock photos (Unsplash, Pexels, Pixabay and six more sources). Each photo comes back with its URL, alt text, licence and credit line.

Install

pip install -U langchain-pexafy
export PEXAFY_API_KEY="pexafy_..."

Free key, no card: pexafy.com/dashboard/api-keys/create (5,000 requests a month).

Use

from langchain.agents import create_agent
from langchain_pexafy import PexafyToolkit

agent = create_agent("anthropic:claude-haiku-4-5", tools=PexafyToolkit().get_tools())

result = agent.invoke({"messages": [
    {"role": "user", "content": "Find a header photo for a post about remote work, with its credit line."}
]})
print(result["messages"][-1].content)

create_agent runs on LangGraph. The tools also work with ToolNode and any model's bind_tools(), sync or async.

Tools

Class Tool name Arguments
PexafySearchPhotos pexafy_search_photos query, optional orientation, count
PexafyFindSimilarPhotos pexafy_find_similar_photos photo_id, optional count
PexafyGetPhoto pexafy_get_photo photo_id

PexafyToolkit().get_tools() returns all three. Options on each: api_key, max_results (photos per search when the model gives no count; default 6, max 20).

Output

The tool message is a JSON list, one record per photo:

{
  "rank": 1,
  "photo_id": "019e1ea7-2e82-7a34-a451-4c6c7c8250f4",
  "alt_text": "Red bicycle parked against white wall with front wheel facing left and back wheel right",
  "url": "https://images.unsplash.com/photo-1520538254843-27a40bae5e3a?w=1280",
  "thumbnail_url": "https://images.unsplash.com/photo-1520538254843-27a40bae5e3a?w=400",
  "width": 4896,
  "height": 3264,
  "orientation": "landscape",
  "dominant_color": "#CAB8B4",
  "photographer": "Mitchel Lensink",
  "source": "Unsplash",
  "source_page_url": "https://unsplash.com/photos/red-bicycle-near-white-wall-Hx_dY7Xeszo",
  "license": "free",
  "credit": "Photo by Mitchel Lensink on Unsplash (https://pexafy.com/legal/licenses/#unsplash)"
}

ToolMessage.artifact holds the full API records (every image size).

Errors

  • Spent quota, unknown photo_id, server error: returned to the model as a tool error.
  • Per-minute rate limit: retried automatically.
  • Invalid key: raises pexafy.AuthenticationError.

Licence

MIT. On the free plan, show the credit line next to each photo you publish.

Metadata

Release files for langchain-pexafy 0.1.1

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

Source distribution (sdist)

Source distribution for langchain-pexafy 0.1.1
File Size Uploaded
langchain_pexafy-0.1.1.tar.gz 13.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-pexafy 0.1.1
File Interpreter ABI Platform
langchain_pexafy-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.0 kB

Release files / langchain_pexafy-0.1.1.tar.gz

Download URL langchain_pexafy-0.1.1.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ecf2dbedb68ff9b09dc81a847d9e695bc8d9f2929304f7d92c4316adbd29fef2
BLAKE2b-256 checksum
How to use checksums
217cba6a1abaae11368e34591f5292ea0449f37e4465cca8a1a5c6f207c666d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / langchain_pexafy-0.1.1-py3-none-any.whl

Download URL langchain_pexafy-0.1.1-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
903f65178d6e70aa230dee51f74c7b7e1f770926de074ffec9a1f392d8ebce76
BLAKE2b-256 checksum
How to use checksums
c3b6bc384b929b674880c496171acd1280f367dd2ce51eedc147d405e5e0bef0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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