Skip to main content

Official Python SDK for Serpex SERP API - Fetch search results in JSON format

Project description

serpex

Official Python SDK for the Serpex SERP API - Fetch search results in JSON format.

Installation

pip install serpex

Or with poetry:

poetry add serpex

Quick Start

from serpex import SerpApiClient

# Initialize the client with your API key
client = SerpApiClient('your-api-key-here')

# Search using a dictionary (recommended for simple use cases)
results = client.search({
    'q': 'python tutorial',
    'engine': 'google',
    'language': 'en'
})

# Or using SearchParams object for type safety
from serpex import SearchParams

params = SearchParams(q='python tutorial', engine='google', language='en')
results = client.search(params)

print(results.results)

API Reference

SerpApiClient

Constructor

SerpApiClient(api_key: str, base_url: str = "https://api.serpex.dev")
  • api_key: Your API key from the Serpex dashboard
  • base_url: Optional base URL (defaults to 'https://api.serpex.dev')

Methods

search(params: SearchParams | Dict[str, Any]) -> SearchResponse

Search using the SERP API with flexible parameters. Accepts either a SearchParams object or a dictionary. Engine parameter is required.

# Using dictionary (simple approach)
results = client.search({
    'q': 'javascript frameworks',
    'engine': 'brave',
    'category': 'search',
    'country': 'US'
})

# Using SearchParams object (type-safe approach)
from serpex import SearchParams

params = SearchParams(
    q='javascript frameworks',
    engine='brave',
    category='search',
    country='US'
)
results = client.search(params)

Search Parameters

The SearchParams dataclass supports all search parameters:

@dataclass
class SearchParams:
    # Required: query (use either q or query)
    q: Optional[str] = None
    query: Optional[str] = None

    # Engine selection (only one engine allowed)
    engine: Optional[str] = None

    # Common parameters
    language: Optional[str] = None
    pageno: Optional[int] = None
    page: Optional[int] = None
    time_range: Optional[str] = None
    safesearch: Optional[int] = None

    # Google specific
    hl: Optional[str] = None  # language
    lr: Optional[str] = None  # language restrict
    cr: Optional[str] = None  # country restrict

    # Bing specific
    mkt: Optional[str] = None  # market

    # DuckDuckGo specific
    region: Optional[str] = None

    # Brave specific
    category: Optional[str] = None
    spellcheck: Optional[bool] = None
    ui_lang: Optional[str] = None
    country: Optional[str] = None

    # Legacy support
    maxResults: Optional[int] = None

Response Format

@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]

Error Handling

The SDK raises SerpApiException for API errors:

from serpex import SerpApiClient, SerpApiException

try:
    results = client.search(SearchParams(q='test query'))
except SerpApiException as e:
    print(f"API error: {e}")
    print(f"Status code: {e.status_code}")
    print(f"Details: {e.details}")

Requirements

  • Python 3.8+
  • requests

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

serpex-2.0.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

serpex-2.0.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file serpex-2.0.0.tar.gz.

File metadata

  • Download URL: serpex-2.0.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for serpex-2.0.0.tar.gz
Algorithm Hash digest
SHA256 e4f013fe810a94413fd9e9e4f6a3659579e117a265a212a65ca0747520d9eaba
MD5 4cb82aef2de123ce8ef2fda15dfd7bb5
BLAKE2b-256 b1e7f7bba5a58f69d3edbf72d4303da4d2ebb56642424f133c2b7f03df0b1ce0

See more details on using hashes here.

File details

Details for the file serpex-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: serpex-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for serpex-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7908a4983810446908421e7e9aef0fe3f68c1fbe51da2e26d05d4ff4776df274
MD5 f437ba148060e20702715f33a40a961d
BLAKE2b-256 9737f4e8f95d75475d6b776755f1d842edfed6168d483aaf1e130c158ee0c269

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page