Official Python SDK for the Serpex SERP API. Fetch search results in JSON format with full Python support.
pip install serpexpoetry add serpexGet started with the Serpex Python SDK in just a few lines of code.
from serpex import SerpexClient
# Initialize the client with your API key
client = SerpexClient('your-api-key-here')
# Web search with Google
results = client.search({
'q': 'python tutorial',
'engine': 'google',
'category': 'web',
'time_range': 'week' # Only for web search
})
# News search - always returns latest news
news_results = client.search({
'q': 'artificial intelligence',
'engine': 'google',
'category': 'news' # Always returns latest news
})
print(results.results[0].title)
print(news_results.results[0].published_date)SerpexClient(api_key: str, base_url: str = "https://api.serpex.dev")api_key - Your API key from the Serpex dashboardbase_url - Optional base URL (defaults to production API)# Using dictionary (simple approach)
results = client.search({
'q': 'javascript frameworks',
'engine': 'brave',
'category': 'search',
'country': 'US'
})
# Using SearchParams object (type-safe approach)
from serpex_sdk import SearchParams
params = SearchParams(
q='javascript frameworks',
engine='brave',
category='search',
country='US'
)
results = client.search(params)| Parameter | Type | Required | Description |
|---|---|---|---|
| q | str | Yes | Search query |
| engine | str | Yes | Search engine (auto, google, bing, duckduckgo, brave, yahoo, yandex) |
| category | str | No | Search category (web, news). News always returns latest articles. |
| time_range | str | No | Time range filter (day, week, month, year). Only for web search, ignored for news. |
@dataclass
class SearchResponse:
metadata: SearchMetadata
id: str
query: str
engines: List[str]
results: List[SearchResult]
answers: List[Any]
corrections: List[str]
infoboxes: List[Any]
suggestions: List[str]from serpex import SerpexClient, SerpApiException
try:
results = client.search({'q': 'test query', 'engine': 'google'})
except SerpApiException as e:
print(f"API error: {e}")
print(f"Status code: {e.status_code}")
print(f"Details: {e.details}")