Skip to content

Lenso

Classes

LensoResponse

Bases: BaseSearchResponse[LensoResultItem]

Encapsulates a complete Lenso search response.

Attributes:

Name Type Description
origin dict

The raw JSON response data from Lenso.

raw list[LensoResultItem]

List of all search results.

url str

URL of the search results page.

similar list[LensoResultItem]

Similar image results.

duplicates list[LensoResultItem]

Duplicate image results.

places list[LensoResultItem]

Place recognition results.

related list[LensoResultItem]

Related image results.

people list[LensoResultItem]

People recognition results.

detected_faces list[Any]

Detected faces in the image.

Source code in PicImageSearch/model/lenso.py
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
class LensoResponse(BaseSearchResponse[LensoResultItem]):
    """Encapsulates a complete Lenso search response.

    Attributes:
        origin (dict): The raw JSON response data from Lenso.
        raw (list[LensoResultItem]): List of all search results.
        url (str): URL of the search results page.
        similar (list[LensoResultItem]): Similar image results.
        duplicates (list[LensoResultItem]): Duplicate image results.
        places (list[LensoResultItem]): Place recognition results.
        related (list[LensoResultItem]): Related image results.
        people (list[LensoResultItem]): People recognition results.
        detected_faces (list[Any]): Detected faces in the image.
    """

    def __init__(self, resp_data: dict[str, Any], resp_url: str, **kwargs: Any) -> None:
        """Initializes with the response data.

        Args:
            resp_data (dict[str, Any]): A dictionary containing the parsed response data from Lenso's API.
            resp_url (str): URL of the search results page.
            **kwargs (Any): Additional keyword arguments.
        """
        self.raw: list[LensoResultItem] = []
        self.duplicates: list[LensoResultItem] = []
        self.similar: list[LensoResultItem] = []
        self.places: list[LensoResultItem] = []
        self.related: list[LensoResultItem] = []
        self.people: list[LensoResultItem] = []
        self.detected_faces: list[Any] = []
        super().__init__(resp_data, resp_url, **kwargs)

    def _parse_response(self, resp_data: dict[str, Any], **kwargs: Any) -> None:
        """Parse the raw response data into structured results.

        Args:
            resp_data (dict[str, Any]): Raw response dictionary from Lenso's API.
            **kwargs (Any): Additional keyword arguments (unused).
        """
        self.detected_faces = resp_data.get("detectedFaces", [])

        results_data = resp_data.get("results", {})
        result_types = {
            "duplicates": self.duplicates,
            "similar": self.similar,
            "places": self.places,
            "related": self.related,
            "people": self.people,
        }

        for result_type, result_list in result_types.items():
            result_list.extend(
                LensoResultItem(item) for item in results_data.get(result_type, [])
            )
            self.raw.extend(result_list)

Attributes

detected_faces = [] instance-attribute
duplicates = [] instance-attribute
people = [] instance-attribute
places = [] instance-attribute
raw = [] instance-attribute
related = [] instance-attribute
similar = [] instance-attribute

Functions

__init__(resp_data, resp_url, **kwargs)

Initializes with the response data.

Parameters:

Name Type Description Default
resp_data dict[str, Any]

A dictionary containing the parsed response data from Lenso's API.

required
resp_url str

URL of the search results page.

required
**kwargs Any

Additional keyword arguments.

{}
Source code in PicImageSearch/model/lenso.py
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
def __init__(self, resp_data: dict[str, Any], resp_url: str, **kwargs: Any) -> None:
    """Initializes with the response data.

    Args:
        resp_data (dict[str, Any]): A dictionary containing the parsed response data from Lenso's API.
        resp_url (str): URL of the search results page.
        **kwargs (Any): Additional keyword arguments.
    """
    self.raw: list[LensoResultItem] = []
    self.duplicates: list[LensoResultItem] = []
    self.similar: list[LensoResultItem] = []
    self.places: list[LensoResultItem] = []
    self.related: list[LensoResultItem] = []
    self.people: list[LensoResultItem] = []
    self.detected_faces: list[Any] = []
    super().__init__(resp_data, resp_url, **kwargs)
_parse_response(resp_data, **kwargs)

Parse the raw response data into structured results.

Parameters:

Name Type Description Default
resp_data dict[str, Any]

Raw response dictionary from Lenso's API.

required
**kwargs Any

Additional keyword arguments (unused).

{}
Source code in PicImageSearch/model/lenso.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def _parse_response(self, resp_data: dict[str, Any], **kwargs: Any) -> None:
    """Parse the raw response data into structured results.

    Args:
        resp_data (dict[str, Any]): Raw response dictionary from Lenso's API.
        **kwargs (Any): Additional keyword arguments (unused).
    """
    self.detected_faces = resp_data.get("detectedFaces", [])

    results_data = resp_data.get("results", {})
    result_types = {
        "duplicates": self.duplicates,
        "similar": self.similar,
        "places": self.places,
        "related": self.related,
        "people": self.people,
    }

    for result_type, result_list in result_types.items():
        result_list.extend(
            LensoResultItem(item) for item in results_data.get(result_type, [])
        )
        self.raw.extend(result_list)

LensoResultItem

Bases: BaseSearchItem

Represents a single Lenso search result item.

Attributes:

Name Type Description
origin dict

The raw JSON data of the search result item.

title str

Title or name of the search result.

url str

URL of the webpage containing the image.

hash str

The hash of the image.

similarity float

The similarity score (0-100).

thumbnail str

URL of the thumbnail version of the image.

url_list list[LensoURLItem]

List of related URLs.

width int

The width of the image.

height int

The height of the image.

Source code in PicImageSearch/model/lenso.py
28
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
58
59
60
61
62
class LensoResultItem(BaseSearchItem):
    """Represents a single Lenso search result item.

    Attributes:
        origin (dict): The raw JSON data of the search result item.
        title (str): Title or name of the search result.
        url (str): URL of the webpage containing the image.
        hash (str): The hash of the image.
        similarity (float): The similarity score (0-100).
        thumbnail (str): URL of the thumbnail version of the image.
        url_list (list[LensoURLItem]): List of related URLs.
        width (int): The width of the image.
        height (int): The height of the image.
    """

    def __init__(self, data: dict[str, Any], **kwargs: Any) -> None:
        self.url_list: list[LensoURLItem] = []
        self.width: int = 0
        self.height: int = 0
        super().__init__(data, **kwargs)

    def _parse_data(self, data: dict[str, Any], **kwargs: Any) -> None:
        """Parse search result data."""
        self.origin: dict[str, Any] = data
        self.title: str = deep_get(data, "urlList[0].title") or ""
        self.url: str = deep_get(data, "urlList[0].sourceUrl") or ""
        self.hash: str = data.get("hash", "")

        distance: float = data.get("distance", 0.0)
        self.similarity: float = round(distance * 100, 2)

        self.thumbnail: str = data.get("proxyUrl", "")
        self.url_list = [LensoURLItem(url_data) for url_data in data.get("urlList", [])]
        self.width = data.get("width", 0)
        self.height = data.get("height", 0)

Attributes

height = 0 instance-attribute
url_list = [] instance-attribute
width = 0 instance-attribute

Functions

__init__(data, **kwargs)
Source code in PicImageSearch/model/lenso.py
43
44
45
46
47
def __init__(self, data: dict[str, Any], **kwargs: Any) -> None:
    self.url_list: list[LensoURLItem] = []
    self.width: int = 0
    self.height: int = 0
    super().__init__(data, **kwargs)
_parse_data(data, **kwargs)

Parse search result data.

Source code in PicImageSearch/model/lenso.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def _parse_data(self, data: dict[str, Any], **kwargs: Any) -> None:
    """Parse search result data."""
    self.origin: dict[str, Any] = data
    self.title: str = deep_get(data, "urlList[0].title") or ""
    self.url: str = deep_get(data, "urlList[0].sourceUrl") or ""
    self.hash: str = data.get("hash", "")

    distance: float = data.get("distance", 0.0)
    self.similarity: float = round(distance * 100, 2)

    self.thumbnail: str = data.get("proxyUrl", "")
    self.url_list = [LensoURLItem(url_data) for url_data in data.get("urlList", [])]
    self.width = data.get("width", 0)
    self.height = data.get("height", 0)

LensoURLItem

Represents a URL item in Lenso search results.

A class that processes and stores URL-related information from a Lenso search result.

Attributes:

Name Type Description
origin dict

The raw JSON data of the URL item.

image_url str

Direct URL to the full-size image.

source_url str

URL of the webpage containing the image.

title str

Title or description of the image.

lang str

Language of the webpage.

Source code in PicImageSearch/model/lenso.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class LensoURLItem:
    """Represents a URL item in Lenso search results.

    A class that processes and stores URL-related information from a Lenso search result.

    Attributes:
        origin (dict): The raw JSON data of the URL item.
        image_url (str): Direct URL to the full-size image.
        source_url (str): URL of the webpage containing the image.
        title (str): Title or description of the image.
        lang (str): Language of the webpage.
    """

    def __init__(self, data: dict[str, Any]) -> None:
        self.origin: dict[str, Any] = data
        self.image_url: str = data.get("imageUrl", "")
        self.source_url: str = data.get("sourceUrl", "")
        self.title: str = data.get("title") or ""
        self.lang: str = data.get("lang", "")

Attributes

image_url = data.get('imageUrl', '') instance-attribute
lang = data.get('lang', '') instance-attribute
origin = data instance-attribute
source_url = data.get('sourceUrl', '') instance-attribute
title = data.get('title') or '' instance-attribute

Functions

__init__(data)
Source code in PicImageSearch/model/lenso.py
20
21
22
23
24
25
def __init__(self, data: dict[str, Any]) -> None:
    self.origin: dict[str, Any] = data
    self.image_url: str = data.get("imageUrl", "")
    self.source_url: str = data.get("sourceUrl", "")
    self.title: str = data.get("title") or ""
    self.lang: str = data.get("lang", "")

Functions