SerpAPI Rust SDK
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
Features
- 🦀 Type-safe: Strongly typed request builders and response structures
- ⚡ Async/await: Built on tokio with efficient async I/O
- 🎯 Ergonomic: Fluent builder APIs for constructing queries
- 🔄 Resilient: Automatic retry logic with exponential backoff
- 🌊 Streaming: Support for paginated result streaming
- 🏭 Production-ready: Comprehensive error handling and logging
- 🔍 Specialized: Built-in support for images, news, videos, shopping, and local search
Quick Start
Add this to your Cargo.toml:
[]
= "0.1"
= { = "1.0", = ["full"] }
Documentation
- Crates.io - Official package registry
- Docs.rs - Auto-generated API documentation
- GitHub Repository - Source code and examples
To generate local documentation:
Basic Usage
use ;
async
Advanced Features
Streaming Results
Stream paginated results for large queries:
use StreamExt;
use ;
let mut stream = client.search_stream;
while let Some = stream.next.await
Specialized Search Types
Image Search
let images = client.search.await?;
News Search
let news = client.search.await?;
Video Search
let videos = client.search.await?;
Shopping Search
let products = client.search.await?;
Local Search
let local = client.search.await?;
Advanced Query Building
let results = client.search.await?;
Error Handling
The SDK provides comprehensive error handling with the SerpError enum:
match client.search.await
Retry Policy Configuration
use RetryPolicy;
use Duration;
let client = builder
.api_key
.retry_policy
.build?;
Configuration
Environment Variables
SERP_API_KEY: Your SerpAPI key (if not provided via builder)
Client Configuration
let client = builder
.api_key
.base_url // Custom base URL
.timeout // Request timeout
.user_agent // Custom User-Agent
.default_header? // Add custom headers
.build?;
Response Types
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 result
Examples
The repository includes comprehensive examples:
basic_search.rs: Basic search functionalitystreaming.rs: Streaming and paginationspecialized_search.rs: Different search types
Run examples with:
# Set your API key
# Run basic search example
# Run streaming example
# Run specialized search example
Testing
Run the test suite:
Run with logging:
RUST_LOG=debug
Features
streaming: Enable streaming support (enabled by default)mcp: Enable MCP (Model Context Protocol) integration
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
Performance
The SDK is designed for high performance with minimal overhead:
- Query Building: ~54ns for simple queries, ~113ns for complex queries
- HTTP Client: Built on reqwest with connection pooling and keepalive
- Memory Efficient: Streaming support prevents large result sets from consuming excessive memory
- Zero-Cost Abstractions: Leverages Rust's type system for compile-time guarantees
Roadmap
Sponsors
This project is supported by our generous sponsors:
Acknowledgments
- AI Tinkerers Paris - For organizing the hackathon and fostering AI innovation
- SerpAPI - For providing the excellent search API service and sponsoring the hackathon
- The Rust community for exceptional async and HTTP libraries
- All contributors who help improve this project
Team
This SDK was developed by:
- Hamze Ghalebi - Developer
- Reetika Gautam - Developer
- Leon Carlo - Developer
Roadmap
📍 See ROADMAP.md for detailed implementation plans
Summary
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.