Skip to main content

Unified SERP API router supporting 11 providers

Project description

anyserp

Unified SERP API router for Python. Route search requests across Google, Bing, Brave, and more with a single API. Self-hosted, zero fees.

Install

pip install anyserp

Quick Start

Set your API keys as environment variables:

export SERPER_API_KEY=...
export BRAVE_API_KEY=...
import asyncio
from anyserp import AnySerp

async def main():
    client = AnySerp()

    # Search with the first available provider
    results = await client.search("best python frameworks")
    print(results["results"][0]["title"], results["results"][0]["url"])

asyncio.run(main())

Supported Providers

Provider Env Var Web Images News Videos
Serper SERPER_API_KEY Yes Yes Yes Yes
SerpAPI SERPAPI_API_KEY Yes Yes Yes Yes
Google CSE GOOGLE_CSE_API_KEY + GOOGLE_CSE_ENGINE_ID Yes Yes No No
Bing BING_API_KEY Yes Yes Yes Yes
Brave BRAVE_API_KEY Yes Yes Yes Yes
DataForSEO DATAFORSEO_LOGIN + DATAFORSEO_PASSWORD Yes No Yes No
SearchAPI SEARCHAPI_API_KEY Yes Yes Yes Yes
ValueSERP VALUESERP_API_KEY Yes Yes Yes Yes
ScrapingDog SCRAPINGDOG_API_KEY Yes Yes Yes No
Bright Data BRIGHTDATA_API_KEY Yes Yes Yes Yes
SearchCans SEARCHCANS_API_KEY Yes No Yes No

Provider Routing

Specify a provider with provider/query format:

# Use a specific provider
results = await client.search("serper/python frameworks")

# Or just search with the first available
results = await client.search("python frameworks")

Search Options

results = await client.search({
    "query": "python frameworks",
    "num": 20,             # number of results
    "page": 2,             # page number
    "country": "us",       # country code
    "language": "en",      # language code
    "safe": True,          # safe search
    "type": "web",         # web, images, news, videos
    "dateRange": "month",  # day, week, month, year
})

Fallback Routing

Try multiple providers in order. If one fails, the next is attempted:

results = await client.search_with_fallback(
    {"query": "python frameworks"},
    ["serper", "brave", "bing"],
)

Search All Providers

Search all configured providers and get combined results:

all_results = await client.search_all({"query": "python frameworks"})

for result in all_results:
    print(f"{result['provider']}: {len(result['results'])} results")

Unified Response Format

All providers return the same response shape:

{
    "provider": "serper",
    "query": "python frameworks",
    "results": [
        {
            "position": 1,
            "title": "...",
            "url": "...",
            "description": "...",
            "domain": "...",
            "datePublished": "...",
            # Image fields
            "imageUrl": "...",
            "imageWidth": 800,
            "imageHeight": 600,
            # News fields
            "source": "...",
            # Video fields
            "duration": "...",
            "channel": "...",
        }
    ],
    "totalResults": 1000000,
    "searchTime": 250,
    "relatedSearches": ["..."],
    "peopleAlsoAsk": [{"question": "...", "snippet": "...", "title": "...", "url": "..."}],
    "knowledgePanel": {"title": "...", "type": "...", "description": "..."},
    "answerBox": {"snippet": "...", "title": "...", "url": "..."},
    "aiOverview": {"markdown": "...", "textBlocks": [...], "references": [...]},
}

Configuration

Programmatic

client = AnySerp({
    "serper": {"api_key": "..."},
    "brave": {"api_key": "..."},
    "google": {"api_key": "...", "engine_id": "..."},
    "dataforseo": {"login": "...", "password": "..."},
    "searchapi": {"api_key": "..."},
    "valueserp": {"api_key": "..."},
    "scrapingdog": {"api_key": "..."},
    "brightdata": {"api_key": "..."},
    "searchcans": {"api_key": "..."},
    "defaults": {
        "num": 10,
        "country": "us",
        "language": "en",
        "safe": True,
    },
    "aliases": {
        "fast": "serper",
        "default": "brave",
    },
})

Environment Variables

export SERPER_API_KEY=...
export SERPAPI_API_KEY=...
export GOOGLE_CSE_API_KEY=...
export GOOGLE_CSE_ENGINE_ID=...
export BING_API_KEY=...
export BRAVE_API_KEY=...
export DATAFORSEO_LOGIN=...
export DATAFORSEO_PASSWORD=...
export SEARCHAPI_API_KEY=...
export VALUESERP_API_KEY=...
export SCRAPINGDOG_API_KEY=...
export BRIGHTDATA_API_KEY=...
export SEARCHCANS_API_KEY=...

People Also Ask

Available from 8 providers (Serper, SerpAPI, SearchAPI, ValueSERP, DataForSEO, ScrapingDog, Bright Data, SearchCans):

results = await client.search("how to start an LLC")
for paa in results.get("peopleAlsoAsk", []):
    print(paa["question"], paa.get("snippet", ""))

AI Overview

Fetch Google's AI-generated overview content (requires SearchAPI):

results = await client.search({
    "query": "how to start an LLC",
    "includeAiOverview": True,
})

if results.get("aiOverview"):
    print(results["aiOverview"]["markdown"])
    for ref in results["aiOverview"]["references"]:
        print(f"  [{ref['index']}] {ref['title']} - {ref['url']}")

See Also

Package Description
@probeo/anyserp TypeScript version of this package
anyserp-go Go version of this package
anymodel-py Unified LLM router for Python
workflow-py Stage-based pipeline engine for Python

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

anyserp_py-0.1.1.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

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

anyserp_py-0.1.1-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

File details

Details for the file anyserp_py-0.1.1.tar.gz.

File metadata

  • Download URL: anyserp_py-0.1.1.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for anyserp_py-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6b77c59e177eb9de120df55df94d7ba18883b6c00bff3d69818bf0e717def024
MD5 795a676137d6f3f723efa2357abad183
BLAKE2b-256 c0ad19bac1e4b50af36bae2f239a652754f9e86b1af2901c20ee8d9382358828

See more details on using hashes here.

File details

Details for the file anyserp_py-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: anyserp_py-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for anyserp_py-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce1336b0f5d7886bcd650bf241e98987b212de0c5e413dc7aa67bd74499b9b4d
MD5 88ba273626c3c7c804701842e79f0b25
BLAKE2b-256 81eb9ed37e56d25dcf0b6cb051280b3590a5414cec51144d8db3d9872d9b2a71

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