Skip to main content

Async DDG search with LLM-ready output

Project description

briefsearch

Thin async wrapper around duckduckgo_search + trafilatura that returns LLM-ready markdown from a search query. Designed for use in a daily brief generation pipeline.

Installation

pip install briefsearch

Quick Start

import asyncio
from briefsearch import search, search_many, results_to_markdown, SearchResult

async def main():
    # Snippet-only (default, fast)
    results: list[SearchResult] = await search("Tauri framework news", max_results=5)

    # With full article text for top N results
    results = await search("Tauri framework news", max_results=5, fetch_content=True, fetch_top_n=2)

    # Batch (parallel queries)
    all_results: dict[str, list[SearchResult]] = await search_many(
        ["query one", "query two"],
        max_results=5,
        timeout=8.0,
    )

    # Render to LLM-ready markdown
    md: str = results_to_markdown("Tauri framework news", results)
    print(md)

asyncio.run(main())

API Reference

search(query, *, max_results=5, fetch_content=False, fetch_top_n=1, fetch_timeout=5.0)

Search DuckDuckGo. Returns list[SearchResult]. Never raises — returns [] on failure.

Parameter Type Default Description
query str Search query
max_results int 5 Max DDG results
fetch_content bool False Fetch full article text
fetch_top_n int 1 How many top results to fetch content for
fetch_timeout float 5.0 Per-URL fetch timeout in seconds

search_many(queries, *, max_results=5, fetch_content=False, fetch_top_n=1, fetch_timeout=5.0, timeout=10.0)

Run multiple queries in parallel. Returns dict[str, list[SearchResult]]. Queries that exceed timeout return [].

results_to_markdown(query, results)

Render results as LLM-ready markdown:

**Query:** {query}
- [{title}]({url}): {snippet}
  {first 300 chars of content if available}

SearchResult

@dataclass
class SearchResult:
    title: str
    url: str
    snippet: str                  # DDG body text
    content: str | None = None    # trafilatura full text, if fetched
    fetch_error: str | None = None

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

briefsearch-0.1.0.tar.gz (32.5 kB view details)

Uploaded Source

Built Distribution

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

briefsearch-0.1.0-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file briefsearch-0.1.0.tar.gz.

File metadata

  • Download URL: briefsearch-0.1.0.tar.gz
  • Upload date:
  • Size: 32.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for briefsearch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3d41965389f37b7e114f7ed4d3caeafe70684b2e6f3860aed47a15067efeb7e1
MD5 6a9a5758ba3dec877d24ce3776b3e836
BLAKE2b-256 2aa04c20d49cf340eb30a499fe128b001ae48e6c2a87fec8839947ddafac33fe

See more details on using hashes here.

File details

Details for the file briefsearch-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: briefsearch-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for briefsearch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31fb8e69f1888598cd8879acbb9221149c951d606531f73675de4735f3a10c24
MD5 26cb127175d1d72fa4b71c38f7ac650c
BLAKE2b-256 a456dbd82d905d4dffdebf24342e6930ca1f97b514abfa9d44eefebf4996d11b

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