raspbytes 1.1.0__py3-none-any.whl

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.
Files changed (39) hide show
  1. raspbytes/__init__.py +87 -0
  2. raspbytes/_core/__init__.py +1 -0
  3. raspbytes/_core/constants.py +38 -0
  4. raspbytes/_core/http.py +160 -0
  5. raspbytes/_core/transport.py +175 -0
  6. raspbytes/_core/types.py +11 -0
  7. raspbytes/_core/version.py +8 -0
  8. raspbytes/client.py +88 -0
  9. raspbytes/config.py +122 -0
  10. raspbytes/countries.py +278 -0
  11. raspbytes/exceptions.py +115 -0
  12. raspbytes/managed_scrapers.py +4 -0
  13. raspbytes/models.py +89 -0
  14. raspbytes/py.typed +1 -0
  15. raspbytes/resources/__init__.py +17 -0
  16. raspbytes/resources/_base.py +75 -0
  17. raspbytes/resources/_polling.py +73 -0
  18. raspbytes/resources/browser.py +185 -0
  19. raspbytes/resources/proxies.py +49 -0
  20. raspbytes/resources/scraper/__init__.py +45 -0
  21. raspbytes/resources/scraper/_generated/__init__.py +1 -0
  22. raspbytes/resources/scraper/_generated/managed.py +190 -0
  23. raspbytes/resources/scraper/_generated/wire.py +632 -0
  24. raspbytes/resources/scraper/_managed.py +14 -0
  25. raspbytes/resources/scraper/_request.py +128 -0
  26. raspbytes/resources/scraper/builder.py +199 -0
  27. raspbytes/resources/scraper/hub.py +168 -0
  28. raspbytes/resources/scraper/monitoring.py +132 -0
  29. raspbytes/resources/scraper/runs.py +202 -0
  30. raspbytes/resources/scraper/schedules.py +172 -0
  31. raspbytes/resources/scraper/storage.py +155 -0
  32. raspbytes/resources/scraper/tasks.py +134 -0
  33. raspbytes/resources/scraper/types.py +96 -0
  34. raspbytes/resources/unblocker.py +131 -0
  35. raspbytes/scraper_types.py +4 -0
  36. raspbytes-1.1.0.dist-info/METADATA +297 -0
  37. raspbytes-1.1.0.dist-info/RECORD +39 -0
  38. raspbytes-1.1.0.dist-info/WHEEL +4 -0
  39. raspbytes-1.1.0.dist-info/licenses/LICENSE +25 -0
@@ -0,0 +1,185 @@
1
+ """Browser API resources."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Mapping
6
+ from typing import Any
7
+
8
+ from .._core.constants import RequestField, ResponseField
9
+ from .._core.transport import AsyncTransport, SyncTransport
10
+ from .._core.types import ResponseData
11
+ from ..config import BrowserConfig
12
+ from ..models import BrowserSessionParams
13
+ from ._base import AsyncResource, SyncResource, prepare_payload
14
+ from ._polling import ObjectResponse, poll, poll_async
15
+
16
+ _FAILED_STATES = frozenset({"failed", "expired", "terminated", "node_lost"})
17
+
18
+
19
+ class _Routes:
20
+ PLANS = "browser/plans/"
21
+ PROXY_OPTIONS = "browser/proxy-options/"
22
+ SESSION_OPTIONS = "browser/session-options/"
23
+ ENTITLEMENT = "browser/entitlement/"
24
+ SESSIONS = "browser/sessions/"
25
+ USAGE = "browser/usage/"
26
+ USAGE_HISTORY = "browser/usage/history/"
27
+
28
+ @staticmethod
29
+ def session(session_id: str) -> str:
30
+ return f"{_Routes.SESSIONS}{session_id}/"
31
+
32
+
33
+ def _has_connection(resource: ObjectResponse) -> bool:
34
+ connection = resource.get(ResponseField.CONNECTION)
35
+ return isinstance(connection, dict) and bool(connection.get(ResponseField.URL))
36
+
37
+
38
+ class BrowserResource(SyncResource):
39
+ def __init__(self, transport: SyncTransport, config: BrowserConfig | None = None) -> None:
40
+ self._config = config or BrowserConfig()
41
+ super().__init__(transport, self._config)
42
+
43
+ def plans(self) -> ResponseData:
44
+ return self._get(_Routes.PLANS)
45
+
46
+ def proxy_options(self) -> ResponseData:
47
+ return self._get(_Routes.PROXY_OPTIONS)
48
+
49
+ def session_options(self) -> ResponseData:
50
+ return self._get(_Routes.SESSION_OPTIONS)
51
+
52
+ def entitlement(self) -> ResponseData:
53
+ return self._get(_Routes.ENTITLEMENT)
54
+
55
+ def list_sessions(
56
+ self, *, page: int | None = None, page_size: int | None = None, **filters: Any
57
+ ) -> ResponseData:
58
+ return self._get(
59
+ _Routes.SESSIONS,
60
+ params={RequestField.PAGE: page, RequestField.PAGE_SIZE: page_size, **filters},
61
+ )
62
+
63
+ def create_session(
64
+ self, request: BrowserSessionParams | Mapping[str, Any] | None = None, **fields: Any
65
+ ) -> ResponseData:
66
+ return self._post(_Routes.SESSIONS, json=prepare_payload(request, fields))
67
+
68
+ def get_session(self, session_id: str) -> ResponseData:
69
+ return self._get(_Routes.session(session_id))
70
+
71
+ def terminate_session(self, session_id: str) -> ResponseData:
72
+ return self._delete(_Routes.session(session_id))
73
+
74
+ def usage(self) -> ResponseData:
75
+ return self._get(_Routes.USAGE)
76
+
77
+ def usage_history(
78
+ self,
79
+ *,
80
+ page: int | None = None,
81
+ page_size: int | None = None,
82
+ session_id: str | None = None,
83
+ **filters: Any,
84
+ ) -> ResponseData:
85
+ return self._get(
86
+ _Routes.USAGE_HISTORY,
87
+ params={
88
+ RequestField.PAGE: page,
89
+ RequestField.PAGE_SIZE: page_size,
90
+ RequestField.SESSION: session_id,
91
+ **filters,
92
+ },
93
+ )
94
+
95
+ def wait_until_ready(
96
+ self,
97
+ session_id: str,
98
+ *,
99
+ timeout: float | None = None,
100
+ poll_interval: float | None = None,
101
+ ) -> ResponseData:
102
+ return poll(
103
+ lambda: self.get_session(session_id),
104
+ resource_id=session_id,
105
+ is_complete=_has_connection,
106
+ failed_states=_FAILED_STATES,
107
+ timeout=self._config.poll_timeout if timeout is None else timeout,
108
+ poll_interval=(self._config.poll_interval if poll_interval is None else poll_interval),
109
+ timeout_message=f"Timed out waiting for browser session {session_id}",
110
+ )
111
+
112
+
113
+ class AsyncBrowserResource(AsyncResource):
114
+ def __init__(self, transport: AsyncTransport, config: BrowserConfig | None = None) -> None:
115
+ self._config = config or BrowserConfig()
116
+ super().__init__(transport, self._config)
117
+
118
+ async def plans(self) -> ResponseData:
119
+ return await self._get(_Routes.PLANS)
120
+
121
+ async def proxy_options(self) -> ResponseData:
122
+ return await self._get(_Routes.PROXY_OPTIONS)
123
+
124
+ async def session_options(self) -> ResponseData:
125
+ return await self._get(_Routes.SESSION_OPTIONS)
126
+
127
+ async def entitlement(self) -> ResponseData:
128
+ return await self._get(_Routes.ENTITLEMENT)
129
+
130
+ async def list_sessions(
131
+ self, *, page: int | None = None, page_size: int | None = None, **filters: Any
132
+ ) -> ResponseData:
133
+ return await self._get(
134
+ _Routes.SESSIONS,
135
+ params={RequestField.PAGE: page, RequestField.PAGE_SIZE: page_size, **filters},
136
+ )
137
+
138
+ async def create_session(
139
+ self, request: BrowserSessionParams | Mapping[str, Any] | None = None, **fields: Any
140
+ ) -> ResponseData:
141
+ return await self._post(_Routes.SESSIONS, json=prepare_payload(request, fields))
142
+
143
+ async def get_session(self, session_id: str) -> ResponseData:
144
+ return await self._get(_Routes.session(session_id))
145
+
146
+ async def terminate_session(self, session_id: str) -> ResponseData:
147
+ return await self._delete(_Routes.session(session_id))
148
+
149
+ async def usage(self) -> ResponseData:
150
+ return await self._get(_Routes.USAGE)
151
+
152
+ async def usage_history(
153
+ self,
154
+ *,
155
+ page: int | None = None,
156
+ page_size: int | None = None,
157
+ session_id: str | None = None,
158
+ **filters: Any,
159
+ ) -> ResponseData:
160
+ return await self._get(
161
+ _Routes.USAGE_HISTORY,
162
+ params={
163
+ RequestField.PAGE: page,
164
+ RequestField.PAGE_SIZE: page_size,
165
+ RequestField.SESSION: session_id,
166
+ **filters,
167
+ },
168
+ )
169
+
170
+ async def wait_until_ready(
171
+ self,
172
+ session_id: str,
173
+ *,
174
+ timeout: float | None = None,
175
+ poll_interval: float | None = None,
176
+ ) -> ResponseData:
177
+ return await poll_async(
178
+ lambda: self.get_session(session_id),
179
+ resource_id=session_id,
180
+ is_complete=_has_connection,
181
+ failed_states=_FAILED_STATES,
182
+ timeout=self._config.poll_timeout if timeout is None else timeout,
183
+ poll_interval=(self._config.poll_interval if poll_interval is None else poll_interval),
184
+ timeout_message=f"Timed out waiting for browser session {session_id}",
185
+ )
@@ -0,0 +1,49 @@
1
+ """Proxy API resources."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Mapping
6
+ from typing import Any
7
+
8
+ from .._core.constants import RequestField
9
+ from .._core.types import ResponseData
10
+ from ..models import ProxyConnectionParams
11
+ from ._base import AsyncResource, SyncResource, prepare_payload
12
+
13
+
14
+ class _Routes:
15
+ OPTIONS = "proxy/proxies/options/"
16
+ CREATE = "proxy/proxies/get_proxy/"
17
+ RELEASE_STICKY_SESSION = "proxy/proxies/release_sticky_session/"
18
+
19
+
20
+ class ProxiesResource(SyncResource):
21
+ def options(self, *, proxy_type: str | None = None) -> ResponseData:
22
+ return self._get(_Routes.OPTIONS, params={RequestField.PROXY_TYPE: proxy_type})
23
+
24
+ def create(
25
+ self, request: ProxyConnectionParams | Mapping[str, Any] | None = None, **fields: Any
26
+ ) -> ResponseData:
27
+ return self._post(_Routes.CREATE, json=prepare_payload(request, fields))
28
+
29
+ def release_sticky_session(self, session_id: str, **fields: Any) -> ResponseData:
30
+ return self._put(
31
+ _Routes.RELEASE_STICKY_SESSION,
32
+ json={RequestField.SESSION_ID: session_id, **fields},
33
+ )
34
+
35
+
36
+ class AsyncProxiesResource(AsyncResource):
37
+ async def options(self, *, proxy_type: str | None = None) -> ResponseData:
38
+ return await self._get(_Routes.OPTIONS, params={RequestField.PROXY_TYPE: proxy_type})
39
+
40
+ async def create(
41
+ self, request: ProxyConnectionParams | Mapping[str, Any] | None = None, **fields: Any
42
+ ) -> ResponseData:
43
+ return await self._post(_Routes.CREATE, json=prepare_payload(request, fields))
44
+
45
+ async def release_sticky_session(self, session_id: str, **fields: Any) -> ResponseData:
46
+ return await self._put(
47
+ _Routes.RELEASE_STICKY_SESSION,
48
+ json={RequestField.SESSION_ID: session_id, **fields},
49
+ )
@@ -0,0 +1,45 @@
1
+ """Compose the synchronous and asynchronous Scraper resources."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from ..._core.transport import AsyncTransport, SyncTransport
6
+ from ...config import ScraperConfig
7
+ from .builder import AsyncScraperBuilder, ScraperBuilder
8
+ from .hub import AsyncScraperHub, HubScope, ScraperHub
9
+ from .monitoring import AsyncScraperMonitoringResource, ScraperMonitoringResource
10
+ from .runs import AsyncScraperRuns, ScraperRuns
11
+ from .schedules import AsyncScraperSchedules, ScraperSchedules
12
+ from .storage import AsyncScraperStorage, ScraperStorage
13
+ from .tasks import AsyncScraperTasks, ScraperTasks
14
+
15
+ __all__ = [
16
+ "AsyncScraperHub",
17
+ "AsyncScraperResource",
18
+ "AsyncScraperRuns",
19
+ "HubScope",
20
+ "ScraperHub",
21
+ "ScraperResource",
22
+ "ScraperRuns",
23
+ ]
24
+
25
+
26
+ class ScraperResource:
27
+ def __init__(self, transport: SyncTransport, config: ScraperConfig) -> None:
28
+ self.runs = ScraperRuns(transport, config)
29
+ self.hub = ScraperHub(transport, config, self.runs)
30
+ self.tasks = ScraperTasks(transport, config)
31
+ self.schedules = ScraperSchedules(transport, config)
32
+ self.storage = ScraperStorage(transport, config)
33
+ self.monitoring = ScraperMonitoringResource(transport, config)
34
+ self.builder = ScraperBuilder(transport, config)
35
+
36
+
37
+ class AsyncScraperResource:
38
+ def __init__(self, transport: AsyncTransport, config: ScraperConfig) -> None:
39
+ self.runs = AsyncScraperRuns(transport, config)
40
+ self.hub = AsyncScraperHub(transport, config, self.runs)
41
+ self.tasks = AsyncScraperTasks(transport, config)
42
+ self.schedules = AsyncScraperSchedules(transport, config)
43
+ self.storage = AsyncScraperStorage(transport, config)
44
+ self.monitoring = AsyncScraperMonitoringResource(transport, config)
45
+ self.builder = AsyncScraperBuilder(transport, config)
@@ -0,0 +1 @@
1
+ """Generated Scraper wire contracts and managed catalog."""
@@ -0,0 +1,190 @@
1
+ # Generated from schemas/managed-scrapers.production.json.
2
+
3
+ from typing import Literal, NotRequired, TypedDict
4
+
5
+ from raspbytes.resources.scraper._managed import ManagedScraper
6
+
7
+ CATALOG_ENVIRONMENT = "production"
8
+
9
+ __all__ = [
10
+ "BING_SEARCH",
11
+ "BingSearchInputs",
12
+ "CATALOG_ENVIRONMENT",
13
+ "DUCKDUCKGO_SEARCH",
14
+ "DuckduckgoSearchInputs",
15
+ "GOOGLE_SEARCH",
16
+ "GoogleSearchInputs",
17
+ "MANAGED_SCRAPERS",
18
+ "ManagedScraper",
19
+ "WEB_3148288F0388CB1492A674A5",
20
+ "WEB_45FFDB287C0CFE885141630C",
21
+ "WEB_A86720287472DE2F981A6F19",
22
+ "WEB_A8877DB56730CE212B3AD6BF",
23
+ "WEB_B8E973637A4C142D54BDC4C2",
24
+ "WEB_C082E212A95A63B5AA6A933F",
25
+ "WEB_EA3BBFD36499A2E18E5D01D0",
26
+ "WEB_EC61D18718DFE51B3AEAD7BA",
27
+ "Web3148288f0388cb1492a674a5Inputs",
28
+ "Web45ffdb287c0cfe885141630cInputs",
29
+ "WebA86720287472de2f981a6f19Inputs",
30
+ "WebA8877db56730ce212b3ad6bfInputs",
31
+ "WebB8e973637a4c142d54bdc4c2Inputs",
32
+ "WebC082e212a95a63b5aa6a933fInputs",
33
+ "WebEa3bbfd36499a2e18e5d01d0Inputs",
34
+ "WebEc61d18718dfe51b3aead7baInputs",
35
+ ]
36
+
37
+
38
+ class BingSearchInputs(TypedDict):
39
+ query: str
40
+ country: str
41
+ language: Literal["en", "fr", "de", "es", "it", "pt", "nl"]
42
+ device: Literal["desktop", "mobile"]
43
+ page: NotRequired[float]
44
+ results: NotRequired[float]
45
+ safe_search: NotRequired[bool]
46
+
47
+
48
+ BING_SEARCH: ManagedScraper[BingSearchInputs] = ManagedScraper(
49
+ "scp_raspbytes_bing_search", "scpr_raspbytes_bing_search_v1"
50
+ )
51
+
52
+
53
+ class DuckduckgoSearchInputs(TypedDict):
54
+ query: str
55
+ country: str
56
+ language: Literal["en", "fr", "de", "es", "it", "pt", "nl"]
57
+ device: Literal["desktop", "mobile"]
58
+ page: NotRequired[float]
59
+ results: NotRequired[float]
60
+ safe_search: NotRequired[bool]
61
+
62
+
63
+ DUCKDUCKGO_SEARCH: ManagedScraper[DuckduckgoSearchInputs] = ManagedScraper(
64
+ "scp_raspbytes_duckduckgo_search", "scpr_raspbytes_duckduckgo_search_v1"
65
+ )
66
+
67
+
68
+ class GoogleSearchInputs(TypedDict):
69
+ query: str
70
+ country: str
71
+ language: Literal["en", "fr", "de", "es", "it", "pt", "nl"]
72
+ device: Literal["desktop", "mobile"]
73
+ page: NotRequired[float]
74
+ results: NotRequired[float]
75
+ safe_search: NotRequired[bool]
76
+
77
+
78
+ GOOGLE_SEARCH: ManagedScraper[GoogleSearchInputs] = ManagedScraper(
79
+ "scp_raspbytes_google_search", "scpr_raspbytes_google_search_v1"
80
+ )
81
+
82
+
83
+ class Web3148288f0388cb1492a674a5Inputs(TypedDict, total=False):
84
+ item_name: str
85
+
86
+
87
+ WEB_3148288F0388CB1492A674A5: ManagedScraper[Web3148288f0388cb1492a674a5Inputs] = ManagedScraper(
88
+ "scp_raspbytes_web_3148288f0388cb1492a674a5", "scpr_0d7b399f60c446338aed912e"
89
+ )
90
+
91
+
92
+ class Web45ffdb287c0cfe885141630cInputs(TypedDict):
93
+ listing_type: Literal["property-for-sale", "property-to-rent"]
94
+ location: str
95
+ radius: NotRequired[float]
96
+ minBedrooms: NotRequired[float]
97
+ maxBedrooms: NotRequired[float]
98
+ include_let_agreed: NotRequired[Literal["on", "off"]]
99
+
100
+
101
+ WEB_45FFDB287C0CFE885141630C: ManagedScraper[Web45ffdb287c0cfe885141630cInputs] = ManagedScraper(
102
+ "scp_raspbytes_web_45ffdb287c0cfe885141630c", "scpr_4100c7161ba8462ca988cafb"
103
+ )
104
+
105
+
106
+ class WebA86720287472de2f981a6f19Inputs(TypedDict):
107
+ search_term: str
108
+
109
+
110
+ WEB_A86720287472DE2F981A6F19: ManagedScraper[WebA86720287472de2f981a6f19Inputs] = ManagedScraper(
111
+ "scp_raspbytes_web_a86720287472de2f981a6f19", "scpr_479fb09470224e1bbefc03d6"
112
+ )
113
+
114
+
115
+ class WebA8877db56730ce212b3ad6bfInputs(TypedDict):
116
+ item_name: str
117
+
118
+
119
+ WEB_A8877DB56730CE212B3AD6BF: ManagedScraper[WebA8877db56730ce212b3ad6bfInputs] = ManagedScraper(
120
+ "scp_raspbytes_web_a8877db56730ce212b3ad6bf", "scpr_9f1b45670bf34ed2b217e9d1"
121
+ )
122
+
123
+
124
+ class WebB8e973637a4c142d54bdc4c2Inputs(TypedDict):
125
+ listing_type: Literal["for-sale", "to-rent"]
126
+ location: str
127
+ beds_min: NotRequired[float]
128
+ beds_max: NotRequired[float]
129
+ price_min: NotRequired[float]
130
+ price_max: NotRequired[float]
131
+ property_sub_type: NotRequired[
132
+ list[
133
+ Literal[
134
+ "semi_detached",
135
+ "detached",
136
+ "terraced",
137
+ "flats",
138
+ "bungalow",
139
+ "park_home",
140
+ "farms_land",
141
+ ]
142
+ ]
143
+ ]
144
+ radius: NotRequired[float]
145
+
146
+
147
+ WEB_B8E973637A4C142D54BDC4C2: ManagedScraper[WebB8e973637a4c142d54bdc4c2Inputs] = ManagedScraper(
148
+ "scp_raspbytes_web_b8e973637a4c142d54bdc4c2", "scpr_a9b8c9a8c9c145e49b8491f3"
149
+ )
150
+
151
+
152
+ class WebC082e212a95a63b5aa6a933fInputs(TypedDict):
153
+ search_term: str
154
+
155
+
156
+ WEB_C082E212A95A63B5AA6A933F: ManagedScraper[WebC082e212a95a63b5aa6a933fInputs] = ManagedScraper(
157
+ "scp_raspbytes_web_c082e212a95a63b5aa6a933f", "scpr_df4928c1fc7b4095a7cfee22"
158
+ )
159
+
160
+
161
+ class WebEa3bbfd36499a2e18e5d01d0Inputs(TypedDict, total=False):
162
+ item_name: str
163
+
164
+
165
+ WEB_EA3BBFD36499A2E18E5D01D0: ManagedScraper[WebEa3bbfd36499a2e18e5d01d0Inputs] = ManagedScraper(
166
+ "scp_raspbytes_web_ea3bbfd36499a2e18e5d01d0", "scpr_28ea8b4b916c4190968c3fdd"
167
+ )
168
+
169
+
170
+ class WebEc61d18718dfe51b3aead7baInputs(TypedDict, total=False):
171
+ search_term: str
172
+
173
+
174
+ WEB_EC61D18718DFE51B3AEAD7BA: ManagedScraper[WebEc61d18718dfe51b3aead7baInputs] = ManagedScraper(
175
+ "scp_raspbytes_web_ec61d18718dfe51b3aead7ba", "scpr_29f5f4c2f378482da990f42c"
176
+ )
177
+
178
+ MANAGED_SCRAPERS = (
179
+ BING_SEARCH,
180
+ DUCKDUCKGO_SEARCH,
181
+ GOOGLE_SEARCH,
182
+ WEB_3148288F0388CB1492A674A5,
183
+ WEB_45FFDB287C0CFE885141630C,
184
+ WEB_A86720287472DE2F981A6F19,
185
+ WEB_A8877DB56730CE212B3AD6BF,
186
+ WEB_B8E973637A4C142D54BDC4C2,
187
+ WEB_C082E212A95A63B5AA6A933F,
188
+ WEB_EA3BBFD36499A2E18E5D01D0,
189
+ WEB_EC61D18718DFE51B3AEAD7BA,
190
+ )