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.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_pexafy-0.1.3.tar.gz | 14.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_pexafy-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.6 kB
Release files / langchain_pexafy-0.1.3.tar.gz
| Download URL | langchain_pexafy-0.1.3.tar.gz |
|---|---|
| Size | 14.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fff05130efbea448bc6442ac733560478592056f017cefa43db901f54b2d7d5a
|
|
BLAKE2b-256 checksum How to use checksums |
5a3472ffb2d3edcdd8a1b4ff76a78a3441fecde375e6dc1faf50cb89124aa3f6
|
| 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 7, 2026.
Transparency logRelease files / langchain_pexafy-0.1.3-py3-none-any.whl
| Download URL | langchain_pexafy-0.1.3-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cdcab20a0f4a037faf22c8fb7b45d9922a57215eb72270753571a80a24bcbe02
|
|
BLAKE2b-256 checksum How to use checksums |
5a315bb7c2e8cc101bfd14641455f53bf83bbdfc0c076681088e6637d39f9052
|
| 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 7, 2026.
Transparency log