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.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: briefsearch-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 ac5541744a50ca7ab3e6a618dc4d1452cbd3d22d78a8c32b12e474d3fde7353e
MD5 1eb2fd26508b6ea87d24f7d6bddbc89a
BLAKE2b-256 08eb23e1ab50c79b531dae9b5ecbf7173c2d269a172ee4494fb5e49df958aef9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: briefsearch-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aeb8f1adc9f8af277957fec9d8188e2bcab543a07c483c1f2fb9eb60739a1552
MD5 666a2717539ec9e9c0c50daece1ee1d0
BLAKE2b-256 14d434824e63baac97a4af83c158ea1a69ddeaa6bb33e1590eb3747551d65f57

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