Back to use cases

    Use case / Developers / 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 can include a title, snippet, link, date, source and highlights.

    The problem

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

    What the example does

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

    How it works

    The file calls basic_web_search with query, num and start. The current SDK method is web_search. It calls GET /web with query and start. Use 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

    result = desearch.basic_web_search(query="latest news on AI", num=10, start=0)
    

    Set the key in the environment when you use the current client. The file's setup lines use a placeholder string. Do not commit a real key.

    Endpoints

    • GET /web

    Example output

    The file documents result fields: title, snippet, link, date, source, author, image, favicon and highlights. It 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, create a key at console.desearch.ai, 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.

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

    Prompt you can paste for this example:

    Use Desearch web search for the query I give you. Return the title, snippet, link and source 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