Skip to content

AsyncLinkUpClient

Base classes

Name Children Inherits
HttpSessionMixin
searchly.http
Gives a provider one `anyenv.HttpSession`, opened on first use.
WebSearchProvider
searchly.base
Protocol for web search providers.

⋔ Inheritance diagram

graph TD
  2321112441["client.AsyncLinkUpClient"]
  1226828128["http.HttpSessionMixin"]
  2751680898["builtins.object"]
  4037333726["base.WebSearchProvider"]
  1073422405["typing.Protocol"]
  3481597255["typing.Generic"]
  1226828128 --> 2321112441
  2751680898 --> 1226828128
  4037333726 --> 2321112441
  1073422405 --> 4037333726
  3481597255 --> 1073422405
  2751680898 --> 3481597255

🛈 DocStrings

Bases: HttpSessionMixin, WebSearchProvider

Async client for LinkUp API.

Note: LinkUp does not support country/language/max_results filtering. These parameters are accepted for protocol compatibility but are ignored.

Source code in src/searchly/providers/linkup_provider/client.py
class AsyncLinkUpClient(HttpSessionMixin, WebSearchProvider):
    """Async client for LinkUp API.

    Note: LinkUp does not support country/language/max_results filtering.
    These parameters are accepted for protocol compatibility but are ignored.
    """

    def __init__(
        self,
        *,
        api_key: str | None = None,
        base_url: str = "https://api.linkup.so/v1",
    ):
        """Initialize LinkUp client.

        Args:
            api_key: LinkUp API key. Defaults to LINKUP_API_KEY env var.
            base_url: Base URL for the API.
        """
        self.api_key = api_key or os.getenv("LINKUP_API_KEY")
        if not self.api_key:
            msg = "No API key provided. Set LINKUP_API_KEY env var or pass api_key"
            raise ValueError(msg)

        self.base_url = base_url
        self.headers = {
            "Authorization": f"Bearer {self.api_key}",
            "Content-Type": "application/json",
        }

    async def web_search(
        self,
        query: str,
        *,
        max_results: int = 10,
        country: CountryCode | None = None,
        language: LanguageCode | None = None,
        depth: SearchDepth = "standard",
        output_type: OutputType = "searchResults",
        **kwargs: Any,
    ) -> WebSearchResponse:
        """Execute a web search query.

        Args:
            query: Search query string.
            max_results: Ignored (LinkUp does not support result count).
            country: Ignored (LinkUp does not support country filtering).
            language: Ignored (LinkUp does not support language filtering).
            depth: Search depth - "standard" (faster) or "deep" (more thorough).
            output_type: Type of output format.
            **kwargs: Additional LinkUp-specific options.

        Returns:
            Unified web search response.
        """
        payload: dict[str, Any] = {"q": query, "depth": depth, "outputType": output_type, **kwargs}
        session = await self._session()
        data = await session.post_json(
            f"{self.base_url}/search",
            json_data=payload,
            headers=self.headers,
            return_type=dict,
        )
        results = [
            WebSearchResult(
                title=item.get("name", ""),
                url=item.get("url", ""),
                snippet=item.get("content", "") if item.get("content") else "",
            )
            for item in data.get("results", [])
            if item.get("url")
        ]
        return WebSearchResponse(results=results[:max_results])

__init__

__init__(*, api_key: str | None = None, base_url: str = 'https://api.linkup.so/v1')

Initialize LinkUp client.

Parameters:

Name Type Description Default
api_key str | None

LinkUp API key. Defaults to LINKUP_API_KEY env var.

None
base_url str

Base URL for the API.

'https://api.linkup.so/v1'
Source code in src/searchly/providers/linkup_provider/client.py
def __init__(
    self,
    *,
    api_key: str | None = None,
    base_url: str = "https://api.linkup.so/v1",
):
    """Initialize LinkUp client.

    Args:
        api_key: LinkUp API key. Defaults to LINKUP_API_KEY env var.
        base_url: Base URL for the API.
    """
    self.api_key = api_key or os.getenv("LINKUP_API_KEY")
    if not self.api_key:
        msg = "No API key provided. Set LINKUP_API_KEY env var or pass api_key"
        raise ValueError(msg)

    self.base_url = base_url
    self.headers = {
        "Authorization": f"Bearer {self.api_key}",
        "Content-Type": "application/json",
    }
web_search(
    query: str,
    *,
    max_results: int = 10,
    country: CountryCode | None = None,
    language: LanguageCode | None = None,
    depth: SearchDepth = "standard",
    output_type: OutputType = "searchResults",
    **kwargs: Any,
) -> WebSearchResponse

Execute a web search query.

Parameters:

Name Type Description Default
query str

Search query string.

required
max_results int

Ignored (LinkUp does not support result count).

10
country CountryCode | None

Ignored (LinkUp does not support country filtering).

None
language LanguageCode | None

Ignored (LinkUp does not support language filtering).

None
depth SearchDepth

Search depth - "standard" (faster) or "deep" (more thorough).

'standard'
output_type OutputType

Type of output format.

'searchResults'
**kwargs Any

Additional LinkUp-specific options.

{}

Returns:

Type Description
WebSearchResponse

Unified web search response.

Source code in src/searchly/providers/linkup_provider/client.py
async def web_search(
    self,
    query: str,
    *,
    max_results: int = 10,
    country: CountryCode | None = None,
    language: LanguageCode | None = None,
    depth: SearchDepth = "standard",
    output_type: OutputType = "searchResults",
    **kwargs: Any,
) -> WebSearchResponse:
    """Execute a web search query.

    Args:
        query: Search query string.
        max_results: Ignored (LinkUp does not support result count).
        country: Ignored (LinkUp does not support country filtering).
        language: Ignored (LinkUp does not support language filtering).
        depth: Search depth - "standard" (faster) or "deep" (more thorough).
        output_type: Type of output format.
        **kwargs: Additional LinkUp-specific options.

    Returns:
        Unified web search response.
    """
    payload: dict[str, Any] = {"q": query, "depth": depth, "outputType": output_type, **kwargs}
    session = await self._session()
    data = await session.post_json(
        f"{self.base_url}/search",
        json_data=payload,
        headers=self.headers,
        return_type=dict,
    )
    results = [
        WebSearchResult(
            title=item.get("name", ""),
            url=item.get("url", ""),
            snippet=item.get("content", "") if item.get("content") else "",
        )
        for item in data.get("results", [])
        if item.get("url")
    ]
    return WebSearchResponse(results=results[:max_results])

:fa-brands-github: Show source on GitHub