Skip to main content

Unified SERP API router supporting 11 providers

Project description

anyserp

PyPI version PyPI downloads License Python versions CI

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

Why anyserp?

One SDK, 11 SERP providers. Switch providers without changing code. Every provider returns the same unified response format, so your application logic stays consistent regardless of which provider you use. Self-hosted with your own API keys and zero routing fees. Built-in fallback routing means if one provider fails, the next is tried automatically. Zero heavy dependencies. Just httpx.

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

Support

If anyserp is useful to you, consider giving it a star. It helps others discover the project.

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.2.0.tar.gz (28.2 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.2.0-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for anyserp_py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d88be14ac7f98640b94c3fb54442e36c8d35e68081f57c4b089bfd5965aaee10
MD5 3f075246fabe5f54ae70e8aa2a9103c7
BLAKE2b-256 2035e9a19d60761f9fb802675bb17268c0f345fa5d6276a37e7deab94a1e4873

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for anyserp_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65948ddc095e49793bc2f297883a4ec8db69f04e1b007bff6f13aec657cb33dc
MD5 ceaa708cb43106b155bd3766ea02d04f
BLAKE2b-256 9293091702b5f01c7ef60e92a255d36fe6e9809579887a266ba5aadf69715e00

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