osintverse 0.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.
osintverse/__init__.py ADDED
@@ -0,0 +1,57 @@
1
+ """Official Python client for the OSINTverse SearchIn API.
2
+
3
+ This package talks to ``https://apiv1.osintverse.com`` (osintverse.com). It is
4
+ not affiliated with other products that reuse the OSINTverse name.
5
+ """
6
+
7
+ from osintverse._async_client import AsyncOSINTverse
8
+ from osintverse._client import OSINTverse
9
+ from osintverse._constants import VERSION as __version__
10
+ from osintverse._exceptions import (
11
+ APIError,
12
+ AuthenticationError,
13
+ ForbiddenError,
14
+ NotFoundError,
15
+ OSINTverseError,
16
+ PaymentRequiredError,
17
+ SearchFailedError,
18
+ SearchRefundedError,
19
+ ValidationError,
20
+ WaitTimeoutError,
21
+ )
22
+ from osintverse._models import (
23
+ BulkSearch,
24
+ BulkSummary,
25
+ InputType,
26
+ InputTypePrice,
27
+ Provider,
28
+ ProviderId,
29
+ ProviderResult,
30
+ Search,
31
+ SearchStatus,
32
+ )
33
+
34
+ __all__ = [
35
+ "APIError",
36
+ "AsyncOSINTverse",
37
+ "AuthenticationError",
38
+ "BulkSearch",
39
+ "BulkSummary",
40
+ "ForbiddenError",
41
+ "InputType",
42
+ "InputTypePrice",
43
+ "NotFoundError",
44
+ "OSINTverse",
45
+ "OSINTverseError",
46
+ "PaymentRequiredError",
47
+ "Provider",
48
+ "ProviderId",
49
+ "ProviderResult",
50
+ "Search",
51
+ "SearchFailedError",
52
+ "SearchRefundedError",
53
+ "SearchStatus",
54
+ "ValidationError",
55
+ "WaitTimeoutError",
56
+ "__version__",
57
+ ]
@@ -0,0 +1,90 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ from typing import Any
5
+
6
+ import httpx
7
+
8
+ from osintverse._async_search import AsyncSearchResource
9
+ from osintverse._constants import (
10
+ API_KEY_ENV,
11
+ DEFAULT_BASE_URL,
12
+ DEFAULT_TIMEOUT,
13
+ USER_AGENT,
14
+ )
15
+ from osintverse._exceptions import AuthenticationError
16
+ from osintverse._http import raise_for_status
17
+ from osintverse._models import Provider
18
+
19
+
20
+ class AsyncProvidersResource:
21
+ def __init__(self, client: AsyncOSINTverse) -> None:
22
+ self._client = client
23
+
24
+ async def list(self) -> list[Provider]:
25
+ """Return the live provider catalog via ``GET /v1/providers``."""
26
+ payload = await self._client.request("GET", "/v1/providers", auth=False)
27
+ return [Provider.model_validate(item) for item in payload]
28
+
29
+
30
+ class AsyncOSINTverse:
31
+ """Async client for the OSINTverse SearchIn API.
32
+
33
+ Parameters match :class:`osintverse.OSINTverse`.
34
+ """
35
+
36
+ def __init__(
37
+ self,
38
+ api_key: str | None = None,
39
+ *,
40
+ base_url: str = DEFAULT_BASE_URL,
41
+ timeout: float = DEFAULT_TIMEOUT,
42
+ http_client: httpx.AsyncClient | None = None,
43
+ ) -> None:
44
+ self.api_key = api_key if api_key is not None else os.environ.get(API_KEY_ENV)
45
+ self.base_url = base_url.rstrip("/")
46
+ self._owns_http_client = http_client is None
47
+ self._http = http_client or httpx.AsyncClient(
48
+ base_url=self.base_url,
49
+ timeout=timeout,
50
+ headers={"User-Agent": USER_AGENT, "Accept": "application/json"},
51
+ )
52
+ self.providers = AsyncProvidersResource(self)
53
+ self.search = AsyncSearchResource(self)
54
+
55
+ async def health(self) -> dict[str, Any]:
56
+ """Service health check via ``GET /health``."""
57
+ payload = await self.request("GET", "/health", auth=False)
58
+ return payload if isinstance(payload, dict) else {"status": payload}
59
+
60
+ async def request(
61
+ self,
62
+ method: str,
63
+ path: str,
64
+ *,
65
+ json: dict[str, Any] | None = None,
66
+ auth: bool = True,
67
+ ) -> Any:
68
+ headers: dict[str, str] = {}
69
+ if auth:
70
+ if not self.api_key:
71
+ raise AuthenticationError(
72
+ f"Missing API key. Pass api_key= or set {API_KEY_ENV}.",
73
+ status_code=401,
74
+ )
75
+ headers["x-api-key"] = self.api_key
76
+ response = await self._http.request(method, path, headers=headers, json=json)
77
+ raise_for_status(response)
78
+ if response.status_code == 204 or not response.content:
79
+ return None
80
+ return response.json()
81
+
82
+ async def aclose(self) -> None:
83
+ if self._owns_http_client:
84
+ await self._http.aclose()
85
+
86
+ async def __aenter__(self) -> AsyncOSINTverse:
87
+ return self
88
+
89
+ async def __aexit__(self, *args: object) -> None:
90
+ await self.aclose()
@@ -0,0 +1,150 @@
1
+ from __future__ import annotations
2
+
3
+ import asyncio
4
+ from collections.abc import Sequence
5
+ from typing import Any
6
+
7
+ from osintverse._constants import DEFAULT_POLL_INTERVAL, DEFAULT_WAIT_TIMEOUT, TERMINAL_STATUSES
8
+ from osintverse._exceptions import WaitTimeoutError
9
+ from osintverse._models import BulkSearch, Search
10
+ from osintverse._search import _raise_if_unsuccessful, _summarize
11
+
12
+
13
+ class AsyncSearchResource:
14
+ def __init__(self, client: Any) -> None:
15
+ self._client = client
16
+
17
+ async def create(
18
+ self,
19
+ *,
20
+ provider: str,
21
+ input_type: str,
22
+ query: str,
23
+ premium: bool = False,
24
+ wait: bool = False,
25
+ poll_interval: float = DEFAULT_POLL_INTERVAL,
26
+ timeout: float = DEFAULT_WAIT_TIMEOUT,
27
+ ) -> Search:
28
+ """Create a SearchIn job via ``POST /v1/search``."""
29
+ body: dict[str, Any] = {
30
+ "provider": provider,
31
+ "input_type": input_type,
32
+ "query": query,
33
+ }
34
+ if premium:
35
+ body["premium"] = True
36
+ search = Search.model_validate(await self._client.request("POST", "/v1/search", json=body))
37
+ if wait:
38
+ return await self.wait(search, poll_interval=poll_interval, timeout=timeout)
39
+ return search
40
+
41
+ async def bulk(
42
+ self,
43
+ *,
44
+ input_type: str,
45
+ queries: Sequence[str],
46
+ providers: Sequence[str],
47
+ premium: bool = False,
48
+ wait: bool = False,
49
+ poll_interval: float = DEFAULT_POLL_INTERVAL,
50
+ timeout: float = DEFAULT_WAIT_TIMEOUT,
51
+ ) -> BulkSearch:
52
+ """Create many jobs via ``POST /v1/search/bulk``."""
53
+ body: dict[str, Any] = {
54
+ "input_type": input_type,
55
+ "queries": list(queries),
56
+ "providers": list(providers),
57
+ }
58
+ if premium:
59
+ body["premium"] = True
60
+ batch = BulkSearch.model_validate(
61
+ await self._client.request("POST", "/v1/search/bulk", json=body)
62
+ )
63
+ if wait:
64
+ return await self.wait_bulk(batch, poll_interval=poll_interval, timeout=timeout)
65
+ return batch
66
+
67
+ async def retrieve(self, search_id: str) -> Search:
68
+ """Fetch a job via ``GET /v1/search/{id}``."""
69
+ return Search.model_validate(await self._client.request("GET", f"/v1/search/{search_id}"))
70
+
71
+ get = retrieve
72
+
73
+ async def unlock(self, search_id: str) -> Search:
74
+ """Unlock remaining LeakRadar credentials via ``POST /v1/search/{id}/unlock``."""
75
+ return Search.model_validate(
76
+ await self._client.request(
77
+ "POST",
78
+ f"/v1/search/{search_id}/unlock",
79
+ json={"unlock_remaining": True},
80
+ )
81
+ )
82
+
83
+ async def premium(self, search_id: str) -> Search:
84
+ """Run OSINT Industries premium modules via ``POST /v1/search/{id}/premium``."""
85
+ return Search.model_validate(
86
+ await self._client.request(
87
+ "POST",
88
+ f"/v1/search/{search_id}/premium",
89
+ json={"premium": True},
90
+ )
91
+ )
92
+
93
+ async def wait(
94
+ self,
95
+ search: Search | str,
96
+ *,
97
+ poll_interval: float = DEFAULT_POLL_INTERVAL,
98
+ timeout: float = DEFAULT_WAIT_TIMEOUT,
99
+ ) -> Search:
100
+ """Poll until the job leaves ``running``, then raise on ``failed`` / ``refunded``."""
101
+ current = await self.retrieve(search) if isinstance(search, str) else search
102
+ loop = asyncio.get_running_loop()
103
+ deadline = loop.time() + timeout
104
+ while current.status == "running":
105
+ if loop.time() >= deadline:
106
+ raise WaitTimeoutError(f"Timed out waiting for search {current.id}")
107
+ if poll_interval > 0:
108
+ await asyncio.sleep(poll_interval)
109
+ current = await self.retrieve(current.id)
110
+ return _raise_if_unsuccessful(current)
111
+
112
+ async def wait_bulk(
113
+ self,
114
+ batch: BulkSearch,
115
+ *,
116
+ poll_interval: float = DEFAULT_POLL_INTERVAL,
117
+ timeout: float = DEFAULT_WAIT_TIMEOUT,
118
+ ) -> BulkSearch:
119
+ """Poll every ``running`` job in a bulk batch to a terminal status."""
120
+ searches: list[Search] = []
121
+ for search in batch.searches:
122
+ if search.status == "running":
123
+ searches.append(
124
+ await self._wait_terminal(
125
+ search,
126
+ poll_interval=poll_interval,
127
+ timeout=timeout,
128
+ )
129
+ )
130
+ else:
131
+ searches.append(search)
132
+ return batch.model_copy(update={"searches": searches, "summary": _summarize(searches)})
133
+
134
+ async def _wait_terminal(
135
+ self,
136
+ search: Search,
137
+ *,
138
+ poll_interval: float,
139
+ timeout: float,
140
+ ) -> Search:
141
+ current = search
142
+ loop = asyncio.get_running_loop()
143
+ deadline = loop.time() + timeout
144
+ while current.status not in TERMINAL_STATUSES:
145
+ if loop.time() >= deadline:
146
+ raise WaitTimeoutError(f"Timed out waiting for search {current.id}")
147
+ if poll_interval > 0:
148
+ await asyncio.sleep(poll_interval)
149
+ current = await self.retrieve(current.id)
150
+ return current
osintverse/_client.py ADDED
@@ -0,0 +1,98 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ from typing import Any
5
+
6
+ import httpx
7
+
8
+ from osintverse._constants import (
9
+ API_KEY_ENV,
10
+ DEFAULT_BASE_URL,
11
+ DEFAULT_TIMEOUT,
12
+ USER_AGENT,
13
+ )
14
+ from osintverse._exceptions import AuthenticationError
15
+ from osintverse._http import raise_for_status
16
+ from osintverse._models import Provider
17
+ from osintverse._search import SearchResource
18
+
19
+
20
+ class ProvidersResource:
21
+ def __init__(self, client: OSINTverse) -> None:
22
+ self._client = client
23
+
24
+ def list(self) -> list[Provider]:
25
+ """Return the live provider catalog via ``GET /v1/providers``."""
26
+ payload = self._client.request("GET", "/v1/providers", auth=False)
27
+ return [Provider.model_validate(item) for item in payload]
28
+
29
+
30
+ class OSINTverse:
31
+ """Synchronous client for the OSINTverse SearchIn API.
32
+
33
+ Parameters
34
+ ----------
35
+ api_key:
36
+ Secret from Dashboard → API keys. Defaults to ``OSINTVERSE_API_KEY``.
37
+ Required for search routes; optional for ``health()`` and ``providers.list()``.
38
+ base_url:
39
+ API host. Defaults to ``https://apiv1.osintverse.com``.
40
+ timeout:
41
+ httpx timeout in seconds.
42
+ """
43
+
44
+ def __init__(
45
+ self,
46
+ api_key: str | None = None,
47
+ *,
48
+ base_url: str = DEFAULT_BASE_URL,
49
+ timeout: float = DEFAULT_TIMEOUT,
50
+ http_client: httpx.Client | None = None,
51
+ ) -> None:
52
+ self.api_key = api_key if api_key is not None else os.environ.get(API_KEY_ENV)
53
+ self.base_url = base_url.rstrip("/")
54
+ self._owns_http_client = http_client is None
55
+ self._http = http_client or httpx.Client(
56
+ base_url=self.base_url,
57
+ timeout=timeout,
58
+ headers={"User-Agent": USER_AGENT, "Accept": "application/json"},
59
+ )
60
+ self.providers = ProvidersResource(self)
61
+ self.search = SearchResource(self)
62
+
63
+ def health(self) -> dict[str, Any]:
64
+ """Service health check via ``GET /health``."""
65
+ payload = self.request("GET", "/health", auth=False)
66
+ return payload if isinstance(payload, dict) else {"status": payload}
67
+
68
+ def request(
69
+ self,
70
+ method: str,
71
+ path: str,
72
+ *,
73
+ json: dict[str, Any] | None = None,
74
+ auth: bool = True,
75
+ ) -> Any:
76
+ headers: dict[str, str] = {}
77
+ if auth:
78
+ if not self.api_key:
79
+ raise AuthenticationError(
80
+ f"Missing API key. Pass api_key= or set {API_KEY_ENV}.",
81
+ status_code=401,
82
+ )
83
+ headers["x-api-key"] = self.api_key
84
+ response = self._http.request(method, path, headers=headers, json=json)
85
+ raise_for_status(response)
86
+ if response.status_code == 204 or not response.content:
87
+ return None
88
+ return response.json()
89
+
90
+ def close(self) -> None:
91
+ if self._owns_http_client:
92
+ self._http.close()
93
+
94
+ def __enter__(self) -> OSINTverse:
95
+ return self
96
+
97
+ def __exit__(self, *args: object) -> None:
98
+ self.close()
@@ -0,0 +1,9 @@
1
+ DEFAULT_BASE_URL = "https://apiv1.osintverse.com"
2
+ DEFAULT_TIMEOUT = 60.0
3
+ DEFAULT_POLL_INTERVAL = 2.0
4
+ DEFAULT_WAIT_TIMEOUT = 120.0
5
+ API_KEY_ENV = "OSINTVERSE_API_KEY"
6
+ VERSION = "0.1.0"
7
+ USER_AGENT = f"osintverse-python/{VERSION}"
8
+
9
+ TERMINAL_STATUSES = frozenset({"completed", "failed", "refunded"})
@@ -0,0 +1,67 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+
6
+ class OSINTverseError(Exception):
7
+ """Base error for the OSINTverse Python SDK."""
8
+
9
+
10
+ class APIError(OSINTverseError):
11
+ """HTTP error returned by the SearchIn API."""
12
+
13
+ def __init__(
14
+ self,
15
+ message: str,
16
+ *,
17
+ status_code: int | None = None,
18
+ body: Any = None,
19
+ ) -> None:
20
+ super().__init__(message)
21
+ self.status_code = status_code
22
+ self.body = body
23
+ self.detail = message
24
+
25
+
26
+ class AuthenticationError(APIError):
27
+ """Missing, invalid, disabled, or expired API key (HTTP 401)."""
28
+
29
+
30
+ class PaymentRequiredError(APIError):
31
+ """Insufficient prepaid balance (HTTP 402)."""
32
+
33
+
34
+ class ForbiddenError(APIError):
35
+ """Account is banned (HTTP 403)."""
36
+
37
+
38
+ class NotFoundError(APIError):
39
+ """Search not found or not owned by this account (HTTP 404)."""
40
+
41
+
42
+ class ValidationError(APIError):
43
+ """Invalid request body or provider/input_type pair (HTTP 422)."""
44
+
45
+
46
+ class WaitTimeoutError(OSINTverseError):
47
+ """Timed out waiting for an async search to finish."""
48
+
49
+
50
+ class SearchFailedError(OSINTverseError):
51
+ """Search finished with status ``failed`` (typically insufficient balance)."""
52
+
53
+ def __init__(self, search: Any) -> None:
54
+ message = getattr(search, "error", None) or f"Search {getattr(search, 'id', '?')} failed"
55
+ super().__init__(message)
56
+ self.search = search
57
+
58
+
59
+ class SearchRefundedError(OSINTverseError):
60
+ """Search finished with status ``refunded`` after an upstream failure."""
61
+
62
+ def __init__(self, search: Any) -> None:
63
+ message = getattr(search, "error", None) or (
64
+ f"Search {getattr(search, 'id', '?')} was refunded after an upstream failure"
65
+ )
66
+ super().__init__(message)
67
+ self.search = search
osintverse/_http.py ADDED
@@ -0,0 +1,71 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ import httpx
6
+
7
+ from osintverse._exceptions import (
8
+ APIError,
9
+ AuthenticationError,
10
+ ForbiddenError,
11
+ NotFoundError,
12
+ PaymentRequiredError,
13
+ ValidationError,
14
+ )
15
+
16
+
17
+ def extract_detail(response: httpx.Response) -> str:
18
+ try:
19
+ payload = response.json()
20
+ except ValueError:
21
+ text = response.text.strip()
22
+ return text or f"HTTP {response.status_code}"
23
+
24
+ detail = payload.get("detail") if isinstance(payload, dict) else payload
25
+ if isinstance(detail, str) and detail:
26
+ return detail
27
+ if isinstance(detail, list):
28
+ parts: list[str] = []
29
+ for item in detail:
30
+ if isinstance(item, dict):
31
+ loc = item.get("loc")
32
+ msg = item.get("msg") or str(item)
33
+ if loc:
34
+ parts.append(f"{_format_loc(loc)}: {msg}")
35
+ else:
36
+ parts.append(str(msg))
37
+ else:
38
+ parts.append(str(item))
39
+ if parts:
40
+ return "; ".join(parts)
41
+ if detail is not None:
42
+ return str(detail)
43
+ return f"HTTP {response.status_code}"
44
+
45
+
46
+ def _format_loc(loc: Any) -> str:
47
+ if isinstance(loc, (list, tuple)):
48
+ return ".".join(str(part) for part in loc)
49
+ return str(loc)
50
+
51
+
52
+ def raise_for_status(response: httpx.Response) -> None:
53
+ if response.is_success:
54
+ return
55
+
56
+ message = extract_detail(response)
57
+ body: Any
58
+ try:
59
+ body = response.json()
60
+ except ValueError:
61
+ body = response.text
62
+
63
+ mapping: dict[int, type[APIError]] = {
64
+ 401: AuthenticationError,
65
+ 402: PaymentRequiredError,
66
+ 403: ForbiddenError,
67
+ 404: NotFoundError,
68
+ 422: ValidationError,
69
+ }
70
+ error_cls = mapping.get(response.status_code, APIError)
71
+ raise error_cls(message, status_code=response.status_code, body=body)
osintverse/_models.py ADDED
@@ -0,0 +1,104 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Literal
4
+
5
+ from pydantic import BaseModel, ConfigDict, Field
6
+
7
+ SearchStatus = Literal["pending", "running", "completed", "failed", "refunded"]
8
+ InputType = Literal["email", "username", "phone", "domain", "name", "image", "ip"]
9
+ ProviderId = Literal[
10
+ "osint-industries",
11
+ "leakradar-lite",
12
+ "leakosintbot",
13
+ "facecheck",
14
+ "picarta",
15
+ "predicta-search",
16
+ "dehashed",
17
+ "whoxy",
18
+ "whoisxml",
19
+ "securitytrails",
20
+ "snusbase",
21
+ "shodan",
22
+ ]
23
+
24
+
25
+ class InputTypePrice(BaseModel):
26
+ model_config = ConfigDict(extra="allow")
27
+
28
+ id: str
29
+ price_usd: str | None = None
30
+
31
+
32
+ class Provider(BaseModel):
33
+ """Provider catalog row from ``GET /v1/providers``."""
34
+
35
+ model_config = ConfigDict(extra="allow")
36
+
37
+ id: str
38
+ name: str
39
+ category: str
40
+ max_unlocks: int | None = None
41
+ extra_unlock_usd_per_1k: str | None = None
42
+ premium_usd: str | None = None
43
+ input_types: list[InputTypePrice]
44
+
45
+
46
+ class ProviderResult(BaseModel):
47
+ """Normalized search results from the upstream provider."""
48
+
49
+ model_config = ConfigDict(extra="allow")
50
+
51
+ sources: list[dict[str, Any]] = Field(default_factory=list)
52
+ matches: list[dict[str, Any]] = Field(default_factory=list)
53
+ raw: Any = None
54
+
55
+
56
+ class Search(BaseModel):
57
+ """Search job status and results."""
58
+
59
+ model_config = ConfigDict(extra="allow")
60
+
61
+ id: str
62
+ status: SearchStatus
63
+ provider: str
64
+ input_type: str
65
+ query: str
66
+ cost_usd: str | None = None
67
+ balance_after: str | None = None
68
+ result: ProviderResult | None = None
69
+ error: str | None = None
70
+ poll_url: str | None = None
71
+ has_stored_result: bool = False
72
+ result_expires_at: str | None = None
73
+ batch_id: str | None = None
74
+
75
+ @property
76
+ def completed(self) -> bool:
77
+ return self.status == "completed"
78
+
79
+ @property
80
+ def running(self) -> bool:
81
+ return self.status == "running"
82
+
83
+
84
+ class BulkSummary(BaseModel):
85
+ model_config = ConfigDict(extra="allow")
86
+
87
+ completed: int = 0
88
+ running: int = 0
89
+ failed: int = 0
90
+ refunded: int = 0
91
+ pending: int = 0
92
+
93
+
94
+ class BulkSearch(BaseModel):
95
+ """Bulk search batch: one :class:`Search` per (query, provider) job."""
96
+
97
+ model_config = ConfigDict(extra="allow")
98
+
99
+ batch_id: str
100
+ input_type: str
101
+ total: int
102
+ estimated_cost_usd: str
103
+ summary: BulkSummary
104
+ searches: list[Search]
osintverse/_search.py ADDED
@@ -0,0 +1,170 @@
1
+ from __future__ import annotations
2
+
3
+ import time
4
+ from collections.abc import Sequence
5
+ from typing import Any
6
+
7
+ from osintverse._constants import DEFAULT_POLL_INTERVAL, DEFAULT_WAIT_TIMEOUT, TERMINAL_STATUSES
8
+ from osintverse._exceptions import SearchFailedError, SearchRefundedError, WaitTimeoutError
9
+ from osintverse._models import BulkSearch, BulkSummary, Search
10
+
11
+
12
+ class SearchResource:
13
+ def __init__(self, client: Any) -> None:
14
+ self._client = client
15
+
16
+ def create(
17
+ self,
18
+ *,
19
+ provider: str,
20
+ input_type: str,
21
+ query: str,
22
+ premium: bool = False,
23
+ wait: bool = False,
24
+ poll_interval: float = DEFAULT_POLL_INTERVAL,
25
+ timeout: float = DEFAULT_WAIT_TIMEOUT,
26
+ ) -> Search:
27
+ """Create a SearchIn job via ``POST /v1/search``.
28
+
29
+ Set ``wait=True`` to poll until the job is no longer ``running``.
30
+ Terminal ``failed`` / ``refunded`` statuses raise.
31
+ """
32
+ body: dict[str, Any] = {
33
+ "provider": provider,
34
+ "input_type": input_type,
35
+ "query": query,
36
+ }
37
+ if premium:
38
+ body["premium"] = True
39
+ search = Search.model_validate(self._client.request("POST", "/v1/search", json=body))
40
+ if wait:
41
+ return self.wait(search, poll_interval=poll_interval, timeout=timeout)
42
+ return search
43
+
44
+ def bulk(
45
+ self,
46
+ *,
47
+ input_type: str,
48
+ queries: Sequence[str],
49
+ providers: Sequence[str],
50
+ premium: bool = False,
51
+ wait: bool = False,
52
+ poll_interval: float = DEFAULT_POLL_INTERVAL,
53
+ timeout: float = DEFAULT_WAIT_TIMEOUT,
54
+ ) -> BulkSearch:
55
+ """Create many jobs via ``POST /v1/search/bulk``.
56
+
57
+ Partial success is normal. ``wait=True`` polls every ``running`` job;
58
+ failed or refunded jobs stay on the returned batch (inspect ``summary``).
59
+ """
60
+ body: dict[str, Any] = {
61
+ "input_type": input_type,
62
+ "queries": list(queries),
63
+ "providers": list(providers),
64
+ }
65
+ if premium:
66
+ body["premium"] = True
67
+ payload = self._client.request("POST", "/v1/search/bulk", json=body)
68
+ batch = BulkSearch.model_validate(payload)
69
+ if wait:
70
+ return self.wait_bulk(batch, poll_interval=poll_interval, timeout=timeout)
71
+ return batch
72
+
73
+ def retrieve(self, search_id: str) -> Search:
74
+ """Fetch a job via ``GET /v1/search/{id}``."""
75
+ return Search.model_validate(self._client.request("GET", f"/v1/search/{search_id}"))
76
+
77
+ get = retrieve
78
+
79
+ def unlock(self, search_id: str) -> Search:
80
+ """Unlock remaining LeakRadar credentials via ``POST /v1/search/{id}/unlock``."""
81
+ return Search.model_validate(
82
+ self._client.request(
83
+ "POST",
84
+ f"/v1/search/{search_id}/unlock",
85
+ json={"unlock_remaining": True},
86
+ )
87
+ )
88
+
89
+ def premium(self, search_id: str) -> Search:
90
+ """Run OSINT Industries premium modules via ``POST /v1/search/{id}/premium``."""
91
+ return Search.model_validate(
92
+ self._client.request(
93
+ "POST",
94
+ f"/v1/search/{search_id}/premium",
95
+ json={"premium": True},
96
+ )
97
+ )
98
+
99
+ def wait(
100
+ self,
101
+ search: Search | str,
102
+ *,
103
+ poll_interval: float = DEFAULT_POLL_INTERVAL,
104
+ timeout: float = DEFAULT_WAIT_TIMEOUT,
105
+ ) -> Search:
106
+ """Poll until the job leaves ``running``, then raise on ``failed`` / ``refunded``."""
107
+ current = self.retrieve(search) if isinstance(search, str) else search
108
+ deadline = time.monotonic() + timeout
109
+ while current.status == "running":
110
+ if time.monotonic() >= deadline:
111
+ raise WaitTimeoutError(f"Timed out waiting for search {current.id}")
112
+ if poll_interval > 0:
113
+ time.sleep(poll_interval)
114
+ current = self.retrieve(current.id)
115
+ return _raise_if_unsuccessful(current)
116
+
117
+ def wait_bulk(
118
+ self,
119
+ batch: BulkSearch,
120
+ *,
121
+ poll_interval: float = DEFAULT_POLL_INTERVAL,
122
+ timeout: float = DEFAULT_WAIT_TIMEOUT,
123
+ ) -> BulkSearch:
124
+ """Poll every ``running`` job in a bulk batch to a terminal status."""
125
+ searches: list[Search] = []
126
+ for search in batch.searches:
127
+ if search.status == "running":
128
+ searches.append(
129
+ self._wait_terminal(
130
+ search,
131
+ poll_interval=poll_interval,
132
+ timeout=timeout,
133
+ )
134
+ )
135
+ else:
136
+ searches.append(search)
137
+ return batch.model_copy(update={"searches": searches, "summary": _summarize(searches)})
138
+
139
+ def _wait_terminal(
140
+ self,
141
+ search: Search,
142
+ *,
143
+ poll_interval: float,
144
+ timeout: float,
145
+ ) -> Search:
146
+ current = search
147
+ deadline = time.monotonic() + timeout
148
+ while current.status not in TERMINAL_STATUSES:
149
+ if time.monotonic() >= deadline:
150
+ raise WaitTimeoutError(f"Timed out waiting for search {current.id}")
151
+ if poll_interval > 0:
152
+ time.sleep(poll_interval)
153
+ current = self.retrieve(current.id)
154
+ return current
155
+
156
+
157
+ def _raise_if_unsuccessful(search: Search) -> Search:
158
+ if search.status == "failed":
159
+ raise SearchFailedError(search)
160
+ if search.status == "refunded":
161
+ raise SearchRefundedError(search)
162
+ return search
163
+
164
+
165
+ def _summarize(searches: list[Search]) -> BulkSummary:
166
+ counts = {"completed": 0, "running": 0, "failed": 0, "refunded": 0, "pending": 0}
167
+ for search in searches:
168
+ if search.status in counts:
169
+ counts[search.status] += 1
170
+ return BulkSummary.model_validate(counts)
osintverse/py.typed ADDED
File without changes
@@ -0,0 +1,134 @@
1
+ Metadata-Version: 2.5
2
+ Name: osintverse
3
+ Version: 0.1.0
4
+ Summary: Official Python client for the OSINTverse SearchIn API
5
+ Project-URL: Homepage, https://osintverse.com
6
+ Project-URL: Documentation, https://osintverse.com/docs/python
7
+ Project-URL: Repository, https://github.com/dheerajydv19/osintverse-pythonsdk
8
+ Project-URL: Issues, https://github.com/dheerajydv19/osintverse-pythonsdk/issues
9
+ Author-email: OSINTverse <hi@osintverse.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: api,osint,osintverse,searchin
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Security
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: httpx>=0.27.0
25
+ Requires-Dist: pydantic>=2.0.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
28
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
29
+ Requires-Dist: respx>=0.22.0; extra == 'dev'
30
+ Requires-Dist: ruff>=0.8.0; extra == 'dev'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # Official Python client for the OSINTverse SearchIn API (osintverse.com).
34
+
35
+ This is the **official** client for [OSINTverse](https://osintverse.com) SearchIn: one REST API for LeakRadar, OSINT Industries, Facecheck.id, SecurityTrails, and every other SearchIn provider.
36
+
37
+ It talks to **`https://apiv1.osintverse.com`**. It is not affiliated with other products that reuse the OSINTverse name.
38
+
39
+ ## Install
40
+
41
+ ```bash
42
+ pip install osintverse
43
+ ```
44
+
45
+ Create an API key at [Dashboard → API keys](https://osintverse.com/dashboard/api). Keys use the `ov_` prefix and are shown only once.
46
+
47
+ ## Quick start
48
+
49
+ ```python
50
+ from osintverse import OSINTverse
51
+
52
+ client = OSINTverse() # reads OSINTVERSE_API_KEY, or pass api_key="ov_…"
53
+
54
+ providers = client.providers.list()
55
+ search = client.search.create(
56
+ provider="leakradar-lite",
57
+ input_type="email",
58
+ query="user@example.com",
59
+ wait=True, # poll GET /v1/search/{id} every ~2s when status is running
60
+ )
61
+ print(search.status, search.cost_usd, len(search.result.matches if search.result else []))
62
+ ```
63
+
64
+ Async:
65
+
66
+ ```python
67
+ from osintverse import AsyncOSINTverse
68
+
69
+ async with AsyncOSINTverse() as client:
70
+ search = await client.search.create(
71
+ provider="leakradar-lite",
72
+ input_type="email",
73
+ query="user@example.com",
74
+ wait=True,
75
+ )
76
+ ```
77
+
78
+ ## Auth
79
+
80
+ - Header: `x-api-key` (the SDK sets this for you)
81
+ - Env: `OSINTVERSE_API_KEY`
82
+ - Docs: [https://osintverse.com/docs/python](https://osintverse.com/docs/python)
83
+
84
+ `GET /health` and `GET /v1/providers` do not require a key. Search routes do.
85
+
86
+ ## Methods
87
+
88
+ | SDK | HTTP |
89
+ | --- | --- |
90
+ | `client.health()` | `GET /health` |
91
+ | `client.providers.list()` | `GET /v1/providers` |
92
+ | `client.search.create(...)` | `POST /v1/search` |
93
+ | `client.search.bulk(...)` | `POST /v1/search/bulk` |
94
+ | `client.search.retrieve(id)` | `GET /v1/search/{id}` |
95
+ | `client.search.unlock(id)` | `POST /v1/search/{id}/unlock` |
96
+ | `client.search.premium(id)` | `POST /v1/search/{id}/premium` |
97
+
98
+ ```python
99
+ batch = client.search.bulk(
100
+ input_type="email",
101
+ queries=["alice@example.com", "bob@example.com"],
102
+ providers=["leakradar-lite", "dehashed"],
103
+ wait=True,
104
+ )
105
+
106
+ client.search.unlock(search.id) # LeakRadar leftover credentials
107
+ client.search.premium(search.id) # OSINT Industries premium modules
108
+ ```
109
+
110
+ `wait=True` on **create** raises `SearchFailedError` / `SearchRefundedError` if the job ends in `failed` or `refunded`. Bulk wait polls running jobs and returns the batch — inspect `summary` for partial success.
111
+
112
+ ## Errors
113
+
114
+ HTTP `{ "detail": "…" }` maps to `AuthenticationError` (401), `PaymentRequiredError` (402), `ForbiddenError` (403), `NotFoundError` (404), `ValidationError` (422), and `APIError` (5xx).
115
+
116
+ ## Development
117
+
118
+ ```bash
119
+ pip install -e ".[dev]"
120
+ pytest
121
+ ruff check src tests
122
+ ```
123
+
124
+ ## License
125
+
126
+ MIT
127
+
128
+ ## Publishing
129
+
130
+ CI runs lint and tests on every push. PyPI publishes from `.github/workflows/publish.yml` on `v*` tags using [Trusted Publishing](https://docs.pypi.org/trusted-publishers/).
131
+
132
+ 1. On PyPI, add a pending trusted publisher for project **osintverse**: GitHub owner `dheerajydv19`, repo `osintverse-pythonsdk`, workflow `publish.yml`, environment blank.
133
+ 2. Tag a release: `git tag v0.1.0 && git push origin v0.1.0`.
134
+
@@ -0,0 +1,14 @@
1
+ osintverse/__init__.py,sha256=YX4nDRzuThuxrfZtmG_a6RqFGOV2TKP1QeVfFwAc64U,1278
2
+ osintverse/_async_client.py,sha256=nci97X7rlyhgjgW0zUtT3WyyshkLvfM_8MFJ24Rqgnk,2886
3
+ osintverse/_async_search.py,sha256=Lxme3_22ssH6dmbuOimUgeCfbSFF36tCQNVYq39z_8M,5287
4
+ osintverse/_client.py,sha256=MPF114sFNY_uc_ohTylz0P-o9qxG9pypf2KqP1TQt8I,3053
5
+ osintverse/_constants.py,sha256=WqrMCwp1G1CfpRm4WLMz2AgPtMeYu3mqCxin2-SbSP8,295
6
+ osintverse/_exceptions.py,sha256=975jJHVRZt8y_0kW77oPBstpnAI_lDroE5wAL6CVhH0,1811
7
+ osintverse/_http.py,sha256=NZzabTlwZqn7PkJXUqDlQDbtBG7E8o4uuz_-HgN5EEQ,1905
8
+ osintverse/_models.py,sha256=4FChh-03-JICwg3ZjQmhgbezl1A2-V7kR1YHaU-s0L8,2412
9
+ osintverse/_search.py,sha256=0pHqw7IzpoZ1Yfonv-zo4cyTnzJ8ejDqVMw5B4hD1K4,5905
10
+ osintverse/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ osintverse-0.1.0.dist-info/METADATA,sha256=Qjy0TQcrQV9-iP2Pm7TBkcN2X_n3-S6H3FYl1TuyuTw,4537
12
+ osintverse-0.1.0.dist-info/WHEEL,sha256=THafob7ofN-NsuMN7Mg4qZyHaQI7KkD-QlcQatYhXPo,87
13
+ osintverse-0.1.0.dist-info/licenses/LICENSE,sha256=B4m4EtnBqFo0LqIc8crXlid7zjoJm_IrQmF7HsJOikg,1067
14
+ osintverse-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.3
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OSINTverse
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.