| Crates.io | pixabay-sdk |
| lib.rs | pixabay-sdk |
| version | 1.0.2 |
| created_at | 2026-01-09 14:14:16.661424+00 |
| updated_at | 2026-01-09 14:45:15.330186+00 |
| description | A Rust wrapper for Pixabay API |
| homepage | https://github.com/tornado-product |
| repository | https://github.com/tornado-product/FusionMediaProvider.git |
| max_upload_size | |
| id | 2032153 |
| size | 98,261 |
A Rust wrapper for the Pixabay API with command-line interface.
This project consists of two main components:
Add the following to your Cargo.toml:
[dependencies]
pixabay-sdk = "xxx"
reqwest = { version = "0.12", features = ["json"] }
tokio = { version = "1", features = ["full"] }
dotenvy = "0.15"
git clone https://github.com/yourusername/pixabay.git
cd pixabay
cargo build --release
Create a .env file in the project root:
PIXABAY_API_KEY=your_api_key_here
You can get your API key from Pixabay API Documentation.
Here's a basic example of using the pixabay-sdk library:
use dotenvy::dotenv;
use pixabay_api::{Pixabay, SearchImageParams, ImageType, Order, Category};
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
let api_key = env::var("PIXABAY_API_KEY")?;
let client = Pixabay::new(api_key);
// Simple image search
let images = client.search_images("nature", Some(10), Some(1)).await?;
for image in images.hits {
println!("Image: {} - {}", image.id, image.tags);
}
// Advanced image search with parameters
let params = SearchImageParams::new()
.query("mountains")
.per_page(20)
.image_type(ImageType::Photo)
.orientation(Orientation::Horizontal)
.category(Category::Nature)
.min_width(1920)
.min_height(1080)
.editors_choice(true)
.safesearch(true)
.order(Order::Latest);
let images = client.search_images_advanced(params).await?;
println!("Found {} images", images.total_hits);
// Get a specific image by ID
let image = client.get_image(736885).await?;
println!("Image URL: {}", image.large_image_url);
// Search for videos
let videos = client.search_videos("ocean", Some(10), Some(1)).await?;
for video in videos.hits {
println!("Video: {} - {}", video.id, video.tags);
}
// Get a specific video by ID
let video = client.get_video(31377).await?;
println!("Video duration: {}s", video.duration);
Ok(())
}
# Basic search
cargo run --bin pixabay -- search-images --query "nature" --per-page 10
# Advanced search with filters
cargo run --bin pixabay -- search-images \
--query "mountains" \
--per-page 20 \
--image-type photo \
--orientation horizontal \
--category nature \
--min-width 1920 \
--min-height 1080 \
--order latest \
--editors-choice \
--safesearch
cargo run --bin pixabay -- get-image --id 736885
# Basic search
cargo run --bin pixabay -- search-videos --query "ocean" --per-page 10
# Advanced search with filters
cargo run --bin pixabay -- search-videos \
--query "sunset" \
--per-page 20 \
--video-type film \
--category nature \
--min-width 1920 \
--min-height 1080 \
--order latest \
--editors-choice
cargo run --bin pixabay -- get-video --id 31377
search_images(query, per_page, page) - Simple image searchsearch_images_advanced(params) - Advanced image search with parametersget_image(id) - Get a specific image by IDsearch_videos(query, per_page, page) - Simple video searchsearch_videos_advanced(params) - Advanced video search with parametersget_video(id) - Get a specific video by IDImageType: All, Photo, Illustration, VectorVideoType: All, Film, AnimationOrientation: All, Horizontal, VerticalOrder: Popular, LatestCategory: Backgrounds, Fashion, Nature, Science, Education, Feelings, Health, People, Religion, Places, Animals, Industry, Computer, Food, Sports, Transportation, Travel, Buildings, Business, MusicLanguage: Multiple language codes supported (En, De, Fr, Es, etc.)The library provides comprehensive error handling:
use pixabay_api::{Pixabay, PixabayError};
match client.search_images("test", Some(10), Some(1)).await {
Ok(response) => println!("Success: {} results", response.total_hits),
Err(PixabayError::RateLimitExceeded) => eprintln!("Rate limit exceeded"),
Err(PixabayError::InvalidApiKey) => eprintln!("Invalid API key"),
Err(e) => eprintln!("Error: {}", e),
}
By default, the Pixabay API allows up to 100 requests per 60 seconds. The library will return a RateLimitExceeded error when you hit this limit.
For detailed API documentation, visit:
Licensed under either of:
at your option.
Contributions are welcome! Please feel free to submit a Pull Request.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 or MIT license, shall be dual licensed as above, without any additional terms or conditions.