Skip to content

codingame_tools.client.service.services.search

search

Async Search service endpoint.

CgSearchServiceHelper

CgSearchServiceHelper(service)

Bases: CgServiceHelper['CgSearchService']

Helper methods for CgSearchService. Currently empty.

Source code in codingame_tools/client/service/cg_service.py
124
125
def __init__(self, service: TService) -> None:
    self.service = service

CgSearchService

CgSearchService(client)

Bases: CgService

Async Search service endpoint.

Source code in codingame_tools/client/service/services/search.py
25
26
27
def __init__(self, client: CgClient) -> None:
    super().__init__(client, "Search")
    self.helper = CgSearchServiceHelper(self)

search async

search(query, locale='en', type_filter=None)

Search for codingamers, puzzles, and other objects by name.

Parameters:

  • query (str) –

    The search query text, e.g. a codingamer's pseudo or part of a puzzle title.

  • locale (str, default: 'en' ) –

    Locale code for localized result names, e.g. "en", "fr". Defaults to "en".

  • type_filter (CgSearchResultType | None, default: None ) –

    If provided, restricts results to a single CgSearchResultType (e.g. "USER", "PUZZLE"). Passing a list/tuple of types instead of a single string is rejected by the server with a 422 INVALID_PARAMETERS error. If not provided, results of all types are returned.

Returns:

Raises:

  • CgAuthenticationError

    If the session is not authenticated and cannot implicitly login.

  • CgClientHttpError

    If a transport error occurs, if the response content could not be decoded at all, if the status code is not 2xx, or if the decoded content is not a list.

Source code in codingame_tools/client/service/services/search.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
async def search(
            self,
            query: str,
            locale: str = "en",
            type_filter: CgSearchResultType | None = None,
        ) -> list[CgSearchResult]:
    """Search for codingamers, puzzles, and other objects by name.

    Args:
        query:       The search query text, e.g. a codingamer's pseudo or part of a puzzle title.
        locale:      Locale code for localized result names, e.g. "en", "fr". Defaults to "en".
        type_filter: If provided, restricts results to a single `CgSearchResultType` (e.g.
                     "USER", "PUZZLE"). Passing a list/tuple of types instead of a single
                     string is rejected by the server with a 422 INVALID_PARAMETERS error.
                     If not provided, results of all types are returned.

    Returns:
        A list of CgSearchResult objects.

    Raises:
        CgAuthenticationError:
            If the session is not authenticated and cannot implicitly login.
        CgClientHttpError:
            If a transport error occurs, if the response content could not be decoded at all,
            if the status code is not 2xx, or if the decoded content is not a list.
    """
    raw_results = await self.service_request_to_list(
            "search", [query, locale, type_filter])
    return CgSearchResult.from_list(cast(list[JsonDict], raw_results))