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 SerpexClient

# Initialize the client with your API key
client = SerpexClient('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

SerpexClient

Constructor

SerpexClient(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 SerpexClient, 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.1.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.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: serpex-2.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 acd9458a457b09ec60a175e0a8fbfac30d10080ceaa95eaeed7f3cdf4083234c
MD5 bacc86b8988d842b8afecda4ea93f063
BLAKE2b-256 7c3369ecbd6c21a3b1e74ae34e29ad77c1b777ac20f24f843b5772ac0ba19d44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: serpex-2.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d16af932f939efaabbaa330064d6e0aaa909ad2908114a8375871aadde0e3ee3
MD5 a15c840f6e2c3976abb60a02a9e1bd94
BLAKE2b-256 590d9bb4ea03ccf6d5edeee9d95b002801740ce24a8158544a84c307f02f93f5

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