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.

For LangChain.js, see js/ (npm install langchain-pexafy).

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.4

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.4
File Size Uploaded
langchain_pexafy-0.1.4.tar.gz 14.7 kB Details

Built distribution (wheel)

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

Total release size: 24.6 kB

Release files / langchain_pexafy-0.1.4.tar.gz

Download URL langchain_pexafy-0.1.4.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8ab33f013a1003bda84052944fce4a01339ee180532cc7367a4b20e02496d4b1
BLAKE2b-256 checksum
How to use checksums
3824cf37f498c53cd579e171e0ba774e06ea7af78fd40a63713c97e713b348fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

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

Download URL langchain_pexafy-0.1.4-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dbadfb434bd0d5f013003b9982cb0e13f9b3fdc32620eddbf4edf1ecb6f2ad9e
BLAKE2b-256 checksum
How to use checksums
bec9bb7f0d281fa0e2d599e401423c6dfc842343b8c26e6ada2969023d0e195e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

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