Back to use cases

    Use case / DEVELOPERS / Python 3 / Published

    Build a Hacker News Search App with JSON and CSV Export in Python

    Search Hacker News discussions on any topic from code or a small web page and get item links, snippets and top comments, with JSON and CSV export built in.

    Card for Build a Hacker News Search App with JSON and CSV Export in Python

    This Hacker News search app is for developers who want to pull Hacker News discussions on a topic into their own scripts or a small web page. Type a topic like "sqlite in production" and get item links, titles, snippets and the most relevant comments, with JSON and CSV export. It uses one Desearch call and the Python standard library.

    The problem

    Hacker News threads are a good record of what developers think about a tool, a database or a pattern. Finding the right threads by hand means several searches, opening each item and copying links and quotes into notes. Getting that into a spreadsheet or a script is more work again. A search you can call from code, with clean item links, removes the copying.

    What the Hacker News search app does

    • Takes a topic, 1 to 300 characters. Alternatives go in parentheses: (sqlite OR duckdb) production.
    • Returns 10, 20 or 30 Hacker News results per call: stories and single comments.
    • Keeps only news.ycombinator.com/item?id= links and removes duplicate items.
    • Shows each result's title, link, snippet and highlights (the most relevant comments).
    • Exports the same results as JSON or CSV, from the CLI or the web page.
    • Serves the same request again within 10 minutes from memory at no cost.

    How it works

    1. Check the input. A blank topic, a bad count or unbalanced parentheses gets HTTP 400 before any call.
    2. Search Hacker News. POST /desearch/ai/search with tools: ["hackernews"], result_type: "ONLY_LINKS" and count 10, 20 or 30. ONLY_LINKS skips the AI summary.
    3. Filter and dedupe. Keep item page links only and dedupe by item id, so the output is safe to join with other data.
    4. Serve or export. The CLI writes JSON and CSV; the local server shows an HTML page with export links and answers /search and /search.csv.

    The code

    The core call, copied from the example's README. The key is read from the DESEARCH_API_KEY env var:

    BASH
    curl -s https://api.desearch.ai/desearch/ai/search \
      -H "Authorization: $DESEARCH_API_KEY" -H "Content-Type: application/json" \
      -d '{"prompt": "rust async runtime", "tools": ["hackernews"], "streaming": false, "result_type": "ONLY_LINKS", "count": 10}'

    The request body is built by body in core.py:

    PYTHON
    def body(query, count=10, date_filter=""):
        """Request body for POST /desearch/ai/search with only the hackernews tool, links only, no streaming."""
        b = {"prompt": query, "tools": ["hackernews"], "streaming": False, "result_type": "ONLY_LINKS", "count": count}
        if date_filter:
            b["date_filter"] = date_filter
        return b

    The response holds search (each result's title, link, snippet and highlights) plus cost_usd. The cost is also in the X-Desearch-Cost-Usd header.

    The folder layout:

    • core.py: input checks, request body, item filter, dedupe, CSV and JSON export, HTML. No network.
    • app.py: the CLI, the HTTP page and the Desearch client.
    • test_core.py: offline tests.
    • samples/: a JSON and CSV export and an HTML page for one search.

    Endpoints

    • POST /desearch/ai/search

    Example output

    Saved sample from a run on 2026-10-16 for "sqlite in production" with count 10. This page shows that stored request and response. It does not run a live demo.

    Sample request

    JSON
    {
      "prompt": "sqlite in production",
      "tools": ["hackernews"],
      "streaming": false,
      "result_type": "ONLY_LINKS",
      "count": 10
    }

    Sample response

    The saved run cost $0.004.

    What came backCount
    Links returned10
    Hacker News item pages kept10 of 10
    Duplicates removed0

    The top results, as returned:

    1. How (and why) to run SQLite in production
    2. Ask HN: Who uses SQLite database in production?
    3. Ask HN: SQLite in Production?

    Titles, snippets and highlights are Hacker News text, quoted as returned. The full export is in samples/sqlite-in-production.json and .csv.

    Run it yourself

    BASH
    git clone https://github.com/Desearch-ai/desearch-py-examples && cd desearch-py-examples/hacker-news-search-app
    export DESEARCH_API_KEY=...   # from console.desearch.ai
    python3 app.py --cli "rust async runtime" --count 10 --csv out.csv --json out.json

    For the web page, run python3 app.py --port 8000 and open http://127.0.0.1:8000/.

    • --count: 10, 20 or 30 results per call.
    • --csv and --json: save the results as a spreadsheet or as data.
    • --log-dir runs/today: save each API call with the key removed.

    What it costs

    Measured on 2026-10-16 from the X-Desearch-Cost-Usd header: $0.004 for 10 results and $0.008 for 20, so $0.0004 per result. Repeat requests within 10 minutes come from memory and cost nothing. See pricing.

    Ideas to extend it

    • Track what Hacker News has said about your product and its category, saved to CSV each week.
    • Feed the highlights into a summary step to get a short "what developers think" note per topic.
    • Join the CSV with your own docs search to answer support questions with real threads.

    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 <DESEARCH_API_KEY>"
          }
        }
      }
    }

    Prompt you can paste for this example:

    Use Desearch POST /desearch/ai/search with tools set to hackernews and result_type ONLY_LINKS for the topic I name. Return Hacker News item links with the title, snippet and highlights. Keep only news.ycombinator.com item links and drop duplicate item ids. Export the same rows as JSON and CSV. Do not name individual posters.

    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