| Crates.io | serp-sdk |
| lib.rs | serp-sdk |
| version | 0.2.1 |
| created_at | 2025-09-21 09:46:33.165189+00 |
| updated_at | 2025-09-22 15:32:00.627815+00 |
| description | A comprehensive, production-ready Rust SDK for SerpAPI with async support, type safety, and ergonomic APIs. Developed during the Realtime Search AI Hackathon powered by SerpAPI. |
| homepage | https://github.com/RustSandbox/SerpRS |
| repository | https://github.com/RustSandbox/SerpRS |
| max_upload_size | |
| id | 1848659 |
| size | 202,049 |
A comprehensive, production-ready Rust SDK for the SerpAPI service that provides ergonomic APIs, type safety, and async-first design.
🏆 Developed during the Realtime Search AI Hackathon (Hybrid) powered by SerpAPI and organized by AI Tinkerers Paris
Add this to your Cargo.toml:
[dependencies]
serp-sdk = "0.1"
tokio = { version = "1.0", features = ["full"] }
To generate local documentation:
cargo doc --all-features --no-deps --open
use serp_sdk::{SerpClient, SearchQuery};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize client (API key from env var SERP_API_KEY or builder)
let client = SerpClient::builder()
.api_key("your-serp-api-key")
.build()?;
// Build and execute search
let results = client.search(
SearchQuery::new("Rust programming language")
.language("en")
.country("us")
.limit(10)?
).await?;
// Process results
if let Some(organic) = results.organic_results {
for result in organic {
println!("{}: {}", result.title, result.link);
}
}
Ok(())
}
Stream paginated results for large queries:
use futures::StreamExt;
use serp_sdk::{SerpClient, SearchQuery, StreamConfig};
let mut stream = client.search_stream(
SearchQuery::new("rust tutorials"),
StreamConfig::new()
.page_size(20)?
.max_pages(5)
.delay(std::time::Duration::from_millis(500))
);
while let Some(page) = stream.next().await {
match page {
Ok(results) => println!("Got page with {} results",
results.organic_results.as_ref().map_or(0, |r| r.len())),
Err(e) => eprintln!("Error: {}", e),
}
}
let images = client.search(
SearchQuery::new("rust logo").images()
).await?;
let news = client.search(
SearchQuery::new("rust programming").news()
).await?;
let videos = client.search(
SearchQuery::new("rust tutorial").videos()
).await?;
let products = client.search(
SearchQuery::new("rust book").shopping()
).await?;
let local = client.search(
SearchQuery::new("rust meetup")
.location("San Francisco, CA")
).await?;
let results = client.search(
SearchQuery::new("site:github.com rust web framework")
.language("en")
.country("us")
.device("desktop")
.safe_search("off")
.domain("google.com")
.limit(50)?
.offset(10)
).await?;
The SDK provides comprehensive error handling with the SerpError enum:
match client.search(query).await {
Ok(results) => {
// Process results
}
Err(SerpError::RateLimited { retry_after }) => {
println!("Rate limited, retry after {} seconds", retry_after);
}
Err(SerpError::ApiError { code, message }) => {
println!("API error {}: {}", code, message);
}
Err(SerpError::MissingApiKey) => {
println!("Please set SERP_API_KEY environment variable");
}
Err(e) => {
println!("Other error: {}", e);
}
}
use serp_sdk::RetryPolicy;
use std::time::Duration;
let client = SerpClient::builder()
.api_key("your-key")
.retry_policy(
RetryPolicy::new(5) // Max 5 retries
.with_base_delay(Duration::from_millis(200))
.with_max_delay(Duration::from_secs(30))
.with_backoff_multiplier(2.0)
)
.build()?;
SERP_API_KEY: Your SerpAPI key (if not provided via builder)let client = SerpClient::builder()
.api_key("your-key")
.base_url("https://serpapi.com") // Custom base URL
.timeout(Duration::from_secs(30)) // Request timeout
.user_agent("my-app/1.0") // Custom User-Agent
.default_header("X-Custom", "value")? // Add custom headers
.build()?;
The SDK provides strongly-typed response structures:
SearchResults: Complete search responseOrganicResult: Individual organic search resultAnswerBox: Featured snippet/answer boxKnowledgeGraph: Knowledge panel informationNewsResult: News article resultVideoResult: Video search resultShoppingResult: Shopping/product resultLocalPlace: Local business resultThe repository includes comprehensive examples:
basic_search.rs: Basic search functionalitystreaming.rs: Streaming and paginationspecialized_search.rs: Different search typesRun examples with:
# Set your API key
export SERP_API_KEY="your-serp-api-key"
# Run basic search example
cargo run --example basic_search
# Run streaming example
cargo run --example streaming
# Run specialized search example
cargo run --example specialized_search
Run the test suite:
cargo test
Run with logging:
RUST_LOG=debug cargo test
streaming: Enable streaming support (enabled by default)mcp: Enable MCP (Model Context Protocol) integrationContributions are welcome! Please feel free to submit a Pull Request.
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
The SDK is designed for high performance with minimal overhead:
This project is supported by our generous sponsors:
This SDK was developed by:
📍 See ROADMAP.md for detailed implementation plans
This SDK is evolving into a comprehensive AI-powered search infrastructure through three strategic phases:
🎯 Rig Integration (Q1 2026): Transform the SDK into an intelligent search layer for LLM applications, enabling RAG pipelines, semantic search, and AI agent tools.
🗄️ PostgreSQL Integration (Q2 2026): Add persistent caching, search analytics, and query optimization with database-backed storage for enterprise-scale deployments.
🌐 MCP Server (Q3 2026): Expose search capabilities to AI assistants through the Model Context Protocol, enabling multi-assistant collaboration.