reserp-haystack 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reserp_haystack-0.1.0/.gitignore +9 -0
- reserp_haystack-0.1.0/LICENSE +22 -0
- reserp_haystack-0.1.0/PKG-INFO +52 -0
- reserp_haystack-0.1.0/README.md +31 -0
- reserp_haystack-0.1.0/pyproject.toml +34 -0
- reserp_haystack-0.1.0/src/haystack_integrations/components/websearch/py.typed +1 -0
- reserp_haystack-0.1.0/src/haystack_integrations/components/websearch/reserp/__init__.py +6 -0
- reserp_haystack-0.1.0/src/haystack_integrations/components/websearch/reserp/websearch.py +49 -0
- reserp_haystack-0.1.0/tests/test_websearch.py +89 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Reserp
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: reserp-haystack
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Minimal Haystack component for the Reserp Google Search API
|
|
5
|
+
Project-URL: Homepage, https://reserp.ai/
|
|
6
|
+
Project-URL: Documentation, https://reserp.ai/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/reserp-ai/reserp-haystack
|
|
8
|
+
Project-URL: Issues, https://github.com/reserp-ai/reserp-haystack/issues
|
|
9
|
+
Author: Reserp
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: google-search,haystack,reserp,search-api,serp-api
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Requires-Dist: haystack-ai<3,>=2.24.1
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# Reserp Haystack Integration
|
|
23
|
+
|
|
24
|
+
`ReserpWebSearch` exposes the [Reserp Google Search API](https://reserp.ai/) as a minimal Haystack component.
|
|
25
|
+
|
|
26
|
+
The component accepts the public Reserp request field—a complete Google Search URL—makes one request, and returns the public JSON under Haystack's required output key. It adds no retries, timeout policy, concurrency management, caching, queues, result conversion, or automatic pagination.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install reserp-haystack
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from haystack.utils import Secret
|
|
38
|
+
from haystack_integrations.components.websearch.reserp import ReserpWebSearch
|
|
39
|
+
|
|
40
|
+
search = ReserpWebSearch(api_key=Secret.from_env_var("RESERP_API_KEY"))
|
|
41
|
+
result = search.run(
|
|
42
|
+
url="https://www.google.com/search?q=photonic+computing&gl=us&hl=en"
|
|
43
|
+
)
|
|
44
|
+
print(result["response"])
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The surrounding pipeline owns retries, timeouts, task queues, concurrency, observability, and pagination. See the [Reserp API documentation](https://reserp.ai/docs) and [OpenAPI definition](https://reserp.ai/openapi.json).
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
MIT
|
|
52
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Reserp Haystack Integration
|
|
2
|
+
|
|
3
|
+
`ReserpWebSearch` exposes the [Reserp Google Search API](https://reserp.ai/) as a minimal Haystack component.
|
|
4
|
+
|
|
5
|
+
The component accepts the public Reserp request field—a complete Google Search URL—makes one request, and returns the public JSON under Haystack's required output key. It adds no retries, timeout policy, concurrency management, caching, queues, result conversion, or automatic pagination.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install reserp-haystack
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from haystack.utils import Secret
|
|
17
|
+
from haystack_integrations.components.websearch.reserp import ReserpWebSearch
|
|
18
|
+
|
|
19
|
+
search = ReserpWebSearch(api_key=Secret.from_env_var("RESERP_API_KEY"))
|
|
20
|
+
result = search.run(
|
|
21
|
+
url="https://www.google.com/search?q=photonic+computing&gl=us&hl=en"
|
|
22
|
+
)
|
|
23
|
+
print(result["response"])
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The surrounding pipeline owns retries, timeouts, task queues, concurrency, observability, and pagination. See the [Reserp API documentation](https://reserp.ai/docs) and [OpenAPI definition](https://reserp.ai/openapi.json).
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
MIT
|
|
31
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "reserp-haystack"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Minimal Haystack component for the Reserp Google Search API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Reserp" }]
|
|
13
|
+
keywords = ["haystack", "reserp", "google-search", "search-api", "serp-api"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"Typing :: Typed",
|
|
20
|
+
]
|
|
21
|
+
dependencies = ["haystack-ai>=2.24.1,<3"]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://reserp.ai/"
|
|
25
|
+
Documentation = "https://reserp.ai/docs"
|
|
26
|
+
Repository = "https://github.com/reserp-ai/reserp-haystack"
|
|
27
|
+
Issues = "https://github.com/reserp-ai/reserp-haystack/issues"
|
|
28
|
+
|
|
29
|
+
[tool.hatch.build.targets.wheel]
|
|
30
|
+
packages = ["src/haystack_integrations"]
|
|
31
|
+
|
|
32
|
+
[tool.pytest.ini_options]
|
|
33
|
+
testpaths = ["tests"]
|
|
34
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Minimal Haystack component for Reserp."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Any
|
|
7
|
+
from urllib.request import Request, urlopen
|
|
8
|
+
|
|
9
|
+
from haystack import component, default_from_dict, default_to_dict
|
|
10
|
+
from haystack.utils import Secret, deserialize_secrets_inplace
|
|
11
|
+
|
|
12
|
+
ENDPOINT = "https://api.reserp.ai/v1/serp"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@component
|
|
16
|
+
class ReserpWebSearch:
|
|
17
|
+
"""Expose one public Reserp request as a Haystack component call."""
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
api_key: Secret | None = None,
|
|
22
|
+
) -> None:
|
|
23
|
+
self.api_key = api_key or Secret.from_env_var("RESERP_API_KEY")
|
|
24
|
+
self.api_key.resolve_value()
|
|
25
|
+
|
|
26
|
+
def to_dict(self) -> dict[str, Any]:
|
|
27
|
+
"""Serialize this component."""
|
|
28
|
+
return default_to_dict(self, api_key=self.api_key.to_dict())
|
|
29
|
+
|
|
30
|
+
@classmethod
|
|
31
|
+
def from_dict(cls, data: dict[str, Any]) -> ReserpWebSearch:
|
|
32
|
+
"""Deserialize this component."""
|
|
33
|
+
deserialize_secrets_inplace(data["init_parameters"], keys=["api_key"])
|
|
34
|
+
return default_from_dict(cls, data)
|
|
35
|
+
|
|
36
|
+
@component.output_types(response=dict[str, Any])
|
|
37
|
+
def run(self, url: str) -> dict[str, dict[str, Any]]:
|
|
38
|
+
"""Make one Reserp request and expose the public JSON response."""
|
|
39
|
+
request = Request(
|
|
40
|
+
ENDPOINT,
|
|
41
|
+
data=json.dumps({"url": url}).encode(),
|
|
42
|
+
headers={
|
|
43
|
+
"Authorization": f"Bearer {self.api_key.resolve_value()}",
|
|
44
|
+
"Content-Type": "application/json",
|
|
45
|
+
},
|
|
46
|
+
method="POST",
|
|
47
|
+
)
|
|
48
|
+
with urlopen(request) as response:
|
|
49
|
+
return {"response": json.load(response)}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Contract tests for ReserpWebSearch."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import io
|
|
6
|
+
import json
|
|
7
|
+
from unittest.mock import patch
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
from haystack.utils import Secret
|
|
11
|
+
|
|
12
|
+
from haystack_integrations.components.websearch.reserp import ReserpWebSearch
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class FakeResponse(io.BytesIO):
|
|
16
|
+
def __enter__(self):
|
|
17
|
+
return self
|
|
18
|
+
|
|
19
|
+
def __exit__(self, *_args):
|
|
20
|
+
self.close()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_serialization(monkeypatch) -> None:
|
|
24
|
+
monkeypatch.setenv("RESERP_API_KEY", "test-key")
|
|
25
|
+
component = ReserpWebSearch()
|
|
26
|
+
data = component.to_dict()
|
|
27
|
+
assert data == {
|
|
28
|
+
"type": (
|
|
29
|
+
"haystack_integrations.components.websearch.reserp.websearch."
|
|
30
|
+
"ReserpWebSearch"
|
|
31
|
+
),
|
|
32
|
+
"init_parameters": {
|
|
33
|
+
"api_key": {
|
|
34
|
+
"env_vars": ["RESERP_API_KEY"],
|
|
35
|
+
"strict": True,
|
|
36
|
+
"type": "env_var",
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
restored = ReserpWebSearch.from_dict(data)
|
|
41
|
+
assert restored.api_key.resolve_value() == "test-key"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_one_request_and_unchanged_payload() -> None:
|
|
45
|
+
payload = {
|
|
46
|
+
"ok": True,
|
|
47
|
+
"url": "https://www.google.com/search?q=test",
|
|
48
|
+
"finalUrl": "https://www.google.com/search?q=test",
|
|
49
|
+
"results": [{"url": "https://example.com"}],
|
|
50
|
+
"pagination": {
|
|
51
|
+
"start": 0,
|
|
52
|
+
"nextStart": 10,
|
|
53
|
+
"nextUrl": "https://www.google.com/search?q=test&start=10",
|
|
54
|
+
},
|
|
55
|
+
"billed": True,
|
|
56
|
+
}
|
|
57
|
+
response = FakeResponse(json.dumps(payload).encode())
|
|
58
|
+
|
|
59
|
+
with patch(
|
|
60
|
+
"haystack_integrations.components.websearch.reserp.websearch.urlopen",
|
|
61
|
+
return_value=response,
|
|
62
|
+
) as opener:
|
|
63
|
+
result = ReserpWebSearch(api_key=Secret.from_token("test-key")).run(
|
|
64
|
+
url="https://www.google.com/search?q=test"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
assert result == {"response": payload}
|
|
68
|
+
opener.assert_called_once()
|
|
69
|
+
assert opener.call_args.kwargs == {}
|
|
70
|
+
request = opener.call_args.args[0]
|
|
71
|
+
assert request.full_url == "https://api.reserp.ai/v1/serp"
|
|
72
|
+
assert request.get_header("Authorization") == "Bearer test-key"
|
|
73
|
+
assert json.loads(request.data) == {
|
|
74
|
+
"url": "https://www.google.com/search?q=test"
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_failure_propagates_without_retry() -> None:
|
|
79
|
+
failure = RuntimeError("transport failure")
|
|
80
|
+
with patch(
|
|
81
|
+
"haystack_integrations.components.websearch.reserp.websearch.urlopen",
|
|
82
|
+
side_effect=failure,
|
|
83
|
+
) as opener, pytest.raises(RuntimeError) as caught:
|
|
84
|
+
ReserpWebSearch(api_key=Secret.from_token("test-key")).run(
|
|
85
|
+
url="https://www.google.com/search?q=test"
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
assert caught.value is failure
|
|
89
|
+
opener.assert_called_once()
|