A modern, Async-ready Unsplash API client for Python.
Project description
Unsplash Python SDK
[!WARNING] This is an unofficial SDK and is currently under active development.
A modern, type-safe Python client for the Unsplash API. Built with Pydantic v2 for robust data validation and httpx for high-performance sync and async support.
✨ Features
- Type Safe: Fully typed response models using Pydantic v2.
- Async Native: First-class
async/awaitsupport withAsyncUnsplashClient. - Modern: Built on
httpx(HTTP/2 support, connection pooling). - Developer Friendly: IDE auto-completion, detailed error messages, and fully documented resources.
- Resource Oriented: Clean API design mirroring the Unsplash documentation (Photos, Users, Collections, Search).
🛠️ Installation
Install usage pip:
pip install unsplash-pydantic
Or using Poetry:
poetry add unsplash-pydantic
🚀 Quick Start
Synchronous Client
Perfect for scripts and standard applications.
import os
from unsplash import UnsplashClient
# Initialize the client
client = UnsplashClient(access_key=os.getenv("UNSPLASH_ACCESS_KEY"))
# Get a random photo of nature
photo = client.photos.random(query="nature", orientation="landscape")
# Access typed fields
print(f"Photo by: {photo.user.name}")
print(f"Description: {photo.description}")
print(f"Download URL: {photo.urls.full}")
# Search for photos
results = client.search.photos("mountains", page=1, per_page=10)
print(f"Found {results.total} photos")
Asynchronous Client
Ideal for high-concurrency applications (FastAPI, etc).
import asyncio
import os
from unsplash import AsyncUnsplashClient
async def main():
async with AsyncUnsplashClient(access_key=os.getenv("UNSPLASH_ACCESS_KEY")) as client:
# Fetch user profile asynchronously
user = await client.users.get("ousplash")
print(f"{user.name} has {user.total_photos} photos")
# Get their latest photos
photos = await client.users.photos(user.username, per_page=5)
for photo in photos:
print(f"- {photo.id}: {photo.urls.regular}")
if __name__ == "__main__":
asyncio.run(main())
📚 Core Concepts
Error Handling
All specific errors catch a base UnsplashError. Common HTTP errors (401, 404, 429) are mapped to specific exceptions.
from unsplash import UnsplashClient, UnsplashError, RateLimitError
try:
client.photos.get("invalid-id")
except RateLimitError as e:
print(f"Rate limited! Limit: {e.limit}, Remaining: {e.remaining}")
except UnsplashError as e:
print(f"API Error: {e.message}")
Unsplash Guidelines
This SDK helps you follow Unsplash API Guidelines:
- Attribution: The
Photomodel includes theuserobject withnameandlinksto properly credit photographers. - Download Tracking: Use
client.photos.track_download(id)orclient.photos.download(id)to trigger the download event required by the API. - Hotlinking:
photo.urlsprovides hotlinkable URLs directly.
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
This library is not officially affiliated with Unsplash.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unsplash_pydantic-0.2.0.tar.gz.
File metadata
- Download URL: unsplash_pydantic-0.2.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55f6127eec4bca6358db5fb92e8ec834ad166f192d64cb6e9a8a40f0909ba63f
|
|
| MD5 |
658979e4afcb1eb0cb4f29a4a8ac0af0
|
|
| BLAKE2b-256 |
7b3aaafbc660896d83d5590e34503067dfd7100fa180db0306d831853f64d16d
|
Provenance
The following attestation bundles were made for unsplash_pydantic-0.2.0.tar.gz:
Publisher:
publish.yml on shihweilo/unsplash-pydantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unsplash_pydantic-0.2.0.tar.gz -
Subject digest:
55f6127eec4bca6358db5fb92e8ec834ad166f192d64cb6e9a8a40f0909ba63f - Sigstore transparency entry: 768714732
- Sigstore integration time:
-
Permalink:
shihweilo/unsplash-pydantic@eb9e304bed899daf52b0112c85a4ca0d83bbb80f -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/shihweilo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@eb9e304bed899daf52b0112c85a4ca0d83bbb80f -
Trigger Event:
release
-
Statement type:
File details
Details for the file unsplash_pydantic-0.2.0-py3-none-any.whl.
File metadata
- Download URL: unsplash_pydantic-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f61e67e9753d2a9a778f87007430ba12db4797572fc35e77fcef7b90f949e997
|
|
| MD5 |
67d9d22c01a72aa8bb7b15484978bd1e
|
|
| BLAKE2b-256 |
9252139ee357cee9d31704eaa1e7366abdcf467cae912405220d782f58fef74d
|
Provenance
The following attestation bundles were made for unsplash_pydantic-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on shihweilo/unsplash-pydantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unsplash_pydantic-0.2.0-py3-none-any.whl -
Subject digest:
f61e67e9753d2a9a778f87007430ba12db4797572fc35e77fcef7b90f949e997 - Sigstore transparency entry: 768714738
- Sigstore integration time:
-
Permalink:
shihweilo/unsplash-pydantic@eb9e304bed899daf52b0112c85a4ca0d83bbb80f -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/shihweilo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@eb9e304bed899daf52b0112c85a4ca0d83bbb80f -
Trigger Event:
release
-
Statement type: