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

pip install -U langchain langchain-anthropic  # for this example; any LangChain chat model works
export ANTHROPIC_API_KEY="sk-ant-..."
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.2

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.2
File Size Uploaded
langchain_pexafy-0.1.2.tar.gz 13.3 kB Details

Built distribution (wheel)

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

Total release size: 23.2 kB

Release files / langchain_pexafy-0.1.2.tar.gz

Download URL langchain_pexafy-0.1.2.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
69af7857433aecb6ea81f92c3b2466f429aea5085b3dd5566732e72e04d87a0e
BLAKE2b-256 checksum
How to use checksums
8b0f0b4002e84e19e4a46656e01d7a899d49b42674d1e6b35a07c7d82a009ff1
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.2-py3-none-any.whl

Download URL langchain_pexafy-0.1.2-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f6231d54515febcc99216b399a1cb825ef5ac9ee70e838972867ba321f2e659
BLAKE2b-256 checksum
How to use checksums
341bae20e41cb2da5ffcb55b7ef9438ec548b39f4e2a502c92b32b1f9117b862
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

This release

0.1.2 This release

2 release files

0.1.1

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