Download high-quality photos and videos from Pexels.com with a simple CLI.
# Using uv (recommended)
uv tool install pexel-downloader
# Or using pip
pip install pexel-downloaderCreate a free account at pexels.com to get an API key, then run:
pexel-downloader config --api-key YOUR_API_KEYOr just run pexel-downloader config and you'll be prompted to enter it.
# Download 10 images of nature (uses your configured defaults)
pexel-downloader download nature 10
# Download 5 videos of ocean
pexel-downloader download ocean 5 videoThat's it! Files are saved to your configured download directory (default: downloads/) and the full path is shown after each download.
- Python 3.10+
- Pexels account for an API key: pexels.com
uv is a fast Python package manager.
Linux / macOS:
curl -LsSf https://astral.sh/uv/install.sh | shWindows (PowerShell):
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"Using pip (any platform):
pip install uvAs a CLI tool [recommend]:
uv tool install pexel-downloaderAs a library in your project:
uv add pexel-downloaderRun without installing:
uvx pexel-downloader download nature 5 imageRun pexel-downloader config to configure all settings at once. You'll be prompted for:
- API key — your Pexels API key
- Download directory — where files are saved (default:
downloads) - Content type —
imageorvideo(default:image) - Size — download size (default:
medium)
pexel-downloader configpexel-downloader config --api-key YOUR_API_KEY
pexel-downloader config --download-dir ~/Pictures/pexels
pexel-downloader config --content-type video
pexel-downloader config --size largeThe configuration is stored at:
- Linux:
~/.config/pexel-downloader/config.json - macOS:
~/Library/Application Support/pexel-downloader/config.json - Windows:
C:\Users\<user>\AppData\Roaming\pexel-downloader\config.json
You can also use the PEXEL_API_KEY environment variable (takes priority over the config file):
Linux / macOS:
export PEXEL_API_KEY="your_api_key"Windows (Command Prompt):
set PEXEL_API_KEY=your_api_keyWindows (PowerShell):
$env:PEXEL_API_KEY = "your_api_key"pexel-downloader download QUERY NUM [CONTENT_TYPE] [OPTIONS]CONTENT_TYPE is optional — if omitted, uses your configured default (image by default).
# Download 10 images of "nature" (uses default content type and size)
pexel-downloader download nature 10
# Download 5 videos of "ocean" starting from page 2
pexel-downloader download ocean 5 video --start-page 2
# Specify output directory and size
pexel-downloader download cats 20 image --size large -o ./my_images
# Show help
pexel-downloader --help
pexel-downloader download --help| Option | Short | Default | Description |
|---|---|---|---|
--size |
from config or medium |
Size of the image or video | |
--save-directory |
-o |
from config or downloads |
Directory to save files |
--start-page |
-p |
1 |
Page number to start from |
Images: original, large2x, large, medium, small, portrait, landscape, tiny
Videos: large, medium, small
import os
from pexel_downloader import PexelDownloader
api_key = os.environ.get("PEXEL_API_KEY")
downloader = PexelDownloader(api_key=api_key)
# Download images
downloader.download_images(query="beaches", num_images=100, save_directory="./images")
# Download videos
downloader.download_videos(query="nature", num_videos=5, save_directory="./videos", size="medium")
# Search without downloading
results = downloader.search_images(query="sunset", per_page=10)
print(results["photos"])
# Clone the repo
git clone https://github.com/Gabriellgpc/pexel-downloader.git
cd pexel-downloader
# Install dependencies (including dev)
uv sync --group dev
# Run tests
uv run pytest tests/ -v
# Run the CLI locally
uv run pexel-downloader --helpMIT License. See LICENSE for details.
