Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

Improve API client documentation with clearer examples and descriptions

Devansh KMbc27e472d768
diff --git a/src/local_deep_research/api/client.py b/src/local_deep_research/api/client.py
index 68eb83c7a4..3a77ca36f7 100644
--- a/src/local_deep_research/api/client.py
+++ b/src/local_deep_research/api/client.py
@@ -2,12 +2,24 @@
HTTP Client for Local Deep Research API.
Simplifies authentication and API access by handling CSRF tokens automatically.
+This client allows you to programmatically interact with the Local Deep Research (LDR)
+application, enabling seamless integration with Python scripts and applications.
+It handles all the complexity of authentication, session management, and request formatting.
+
Why CSRF with login?
--------------------
CSRF tokens prevent cross-site request forgery attacks. Even though you're logged in,
CSRF ensures requests come from YOUR code, not from malicious websites that might
try to use your browser's active session cookies to make unauthorized requests.
+Features:
+---------
+- Automatic login and session management
+- CSRF token handling
+- Research query submission and result retrieval
+- User settings management
+- Research history access
+
Example usage:
-------------
from local_deep_research.api.client import LDRClient
@@ -18,9 +30,29 @@ Example usage:
result = client.quick_research("What is quantum computing?")
print(result["summary"])
- # Or use the one-liner
+ # With context manager (auto-logout)
+ with LDRClient() as client:
+ client.login("username", "password")
+ result = client.quick_research("What is quantum computing?")
+ print(result["summary"])
+
+ # Get research history
+ with LDRClient() as client:
+ client.login("username", "password")
+ history = client.get_history()
+ for item in history:
+ print(f"Research: {item['query']}")
+
+ # One-liner for quick queries
from local_deep_research.api.client import quick_query
summary = quick_query("username", "password", "What is DNA?")
+
+ # Update user settings
+ with LDRClient() as client:
+ client.login("username", "password")
+ client.update_setting("llm.model", "gemma:7b")
+ settings = client.get_settings()
+ print(f"Current model: {settings['llm']['model']}")
"""
import requests
@@ -143,22 +175,29 @@ class LDRClient:
timeout: int = 300,
) -> Dict[str, Any]:
"""
- Perform research on a topic.
+ Research a topic using LLMs and search engines.
+
+ This method runs a research process on your query using search engines
+ and large language models. It might take a few minutes to complete.
Args:
- query: Research question
- model: LLM model to use (optional, uses user's default if not specified)
- search_engines: List of search engines (default: ["searxng"])
- iterations: Number of research iterations (default: 2)
- wait_for_result: If True, wait for completion. If False, return immediately with research_id
- timeout: Maximum time to wait in seconds (default: 300)
+ query: Your research question
+ model: LLM model to use (e.g., "gemma:7b", "llama:8b")
+ search_engines: Search engines to use (default: ["searxng"])
+ iterations: How many research cycles to run (default: 2)
+ wait_for_result: If True, wait until done. If False, return immediately
+ timeout: Maximum seconds to wait (default: 300)
Returns:
- If wait_for_result=True: Dict with summary, sources, findings
- If wait_for_result=False: Dict with research_id for polling manually
+ If waiting for result: Dict with summary, sources, and findings
+ If not waiting: Dict with research_id to check status later
Raises:
RuntimeError: If not logged in or request fails
+
+ Example:
+ result = client.quick_research("Latest developments in fusion energy")
+ print(result["summary"])
"""
if not self.logged_in:
raise RuntimeError("Not logged in. Call login() first.")
@@ -209,17 +248,26 @@ class LDRClient:
self, research_id: str, timeout: int = 300
) -> Dict[str, Any]:
"""
- Wait for research to complete and return results.
+ Wait for research to complete and get results.
+
+ Use this after starting research with quick_research(wait_for_result=False).
+ Checks status every 5 seconds until complete or timeout.
Args:
research_id: ID of the research to wait for
- timeout: Maximum time to wait in seconds
+ timeout: Maximum seconds to wait (default: 300)
Returns:
- Dict with research results
+ Dict with research results (summary, sources, findings)
Raises:
RuntimeError: If research fails or times out
+
+ Example:
+ # Start research without waiting
+ resp = client.quick_research("Climate change impacts", wait_for_result=False)
+ # Get results when ready
+ results = client.wait_for_research(resp["research_id"])
"""
start_time = time.time()
@@ -284,7 +332,22 @@ class LDRClient:
return response.status_code == 200
def get_history(self) -> List[Dict[str, Any]]:
- """Get research history."""
+ """
+ Get your past research queries.
+
+ Returns a list of previous research sessions with their details.
+
+ Returns:
+ List of research items with query, timestamp, and status info
+
+ Raises:
+ RuntimeError: If not logged in
+
+ Example:
+ history = client.get_history()
+ for item in history[:5]:
+ print(f"{item['timestamp']}: {item['query']}")
+ """
if not self.logged_in:
raise RuntimeError("Not logged in. Call login() first.")