Back to use cases

    Use case / AI SEARCH / Python 3 / Published

    Run a Basic Web Search with Python

    Run a web query and print the results, with a start offset for the next page. The example is a short SDK call against the Desearch web search endpoint.

    Card for Run a Basic Web Search with Python

    Basic Web Search is a short Python example. It runs one web query, sets a start offset, and prints the results. Each result includes a title, snippet and link.

    The problem

    A web result page is enough to read. A script needs the same rows as data: title, link and snippet, plus a way to ask for the next page.

    What the app does

    • Sends a query and a start offset.
    • Prints the result list.

    How it works

    The file calls web_search with query and start (no num). It calls GET /web with those two arguments. start is how many results to skip.

    The rank checker example uses the same endpoint when you want the best rank of one domain across many keywords.

    The code

    PYTHON
    import asyncio
    import os
    
    from desearch_py import Desearch
    
    # Set DESEARCH_API_KEY in your environment to a key from the Desearch console. Do not commit a real key.
    API_KEY = os.environ["DESEARCH_API_KEY"]
    
    
    async def main():
        # desearch-py 1.2.1: web_search(query, start) calls GET /web.
        # start is how many results to skip. There is no num argument.
        async with Desearch(api_key=API_KEY) as desearch:
            result = await desearch.web_search(query="latest news on AI", start=0)
            print(result)
    
    
    if __name__ == "__main__":
        asyncio.run(main())

    Set DESEARCH_API_KEY in your environment to a key from the Desearch console. Do not commit a real key.

    Endpoints

    • GET /web

    Example output

    The script prints the response. The file does not include a saved sample run or a measured cost.

    Run it yourself

    The file linked above is basic_web_search.py in the examples repository. Install desearch-py 1.2.1, create a key at console.desearch.ai, set DESEARCH_API_KEY in your environment, and call web_search with query and start.

    What it costs

    This example does not record X-Desearch-Cost-Usd. Current responses include that header. See pricing.

    Ideas to extend it

    • Page with start until you have the number of new URLs you need.
    • Pass the links to the page-to-Markdown example.
    • Check one domain's best rank with the rank checker.

    Use with AI agents

    Point an MCP client at the hosted Desearch server. Replace the placeholder with a key from the console. Do not commit the key.

    JSON
    {
      "mcpServers": {
        "desearch": {
          "url": "https://mcp.desearch.ai/mcp",
          "headers": {
            "Authorization": "Bearer <key>"
          }
        }
      }
    }

    Prompt you can paste for this example:

    Use Desearch web search for the query I give you. Return the title, snippet and link for each result you received. Use the start offset if I ask for the next page. Do not invent results.

    Build your own example.

    Give your agents access to web and social search. Get an API key to start building, or talk to us about your integration.

    Read docs