Skip to main content

langchain-pexafy

LangChain and LangGraph tools for Pexafy Stock Photos: semantic search over millions of free-to-use photos (Unsplash, Pexels, Pixabay and more). 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.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 langchain-pexafy 0.1.5
File Size Uploaded Provenance Actions
langchain_pexafy-0.1.5.tar.gz 14.8 kB With provenance Details for langchain_pexafy-0.1.5.tar.gz

Built distribution (wheel)

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

Total release size: 24.7 kB

Release files / langchain_pexafy-0.1.5.tar.gz

Download URL langchain_pexafy-0.1.5.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1153e1e0cd84a921890cca2c61fa6b98c6a90ef0c6e972c0026ec5093565f194
BLAKE2b-256 checksum
How to use checksums
58e189366ab5a6eaf72c6d13859004030033e014adbf0de6421a6b285555278b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 17, 2026.

Transparency log

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

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

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 Nov 17, 2026.

Transparency log

Security for langchain-pexafy 0.1.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for langchain_pexafy-0.1.5.tar.gz

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 Nov 17, 2026.

Transparency log

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.

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