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.2.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.2.0-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for briefsearch-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4a7abce523269f456eab4596922b3415e0efa5826d28f1131e86b73e146c518f
MD5 6ff05f07762e8e599979ce7c083923f3
BLAKE2b-256 af5971549964dfd3f84af47973a97193c66ab98183914808b8a13909a1d0aa54

See more details on using hashes here.

File details

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

File metadata

  • Download URL: briefsearch-0.2.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.11.15

File hashes

Hashes for briefsearch-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 69d5db3749dff29e5cff8208b7d5fdf94827b1d943547316e92c85b53fe8c35e
MD5 71e0af3c9f9b61beaf93c962bb5231f6
BLAKE2b-256 1eee084714759320f3424f0330c2d51232cf783ad82797f8894c272fcd4e76cb

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