Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.13"] # Min and max supported versions
python-version: ["3.10", "3.14"] # Min and max supported versions
steps:
- name: Checkout
uses: actions/checkout@v5
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9
3.10
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ keywords = ["api", "client", "linkup", "sdk", "search"]
license = "MIT"
name = "linkup-sdk"
readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.10"
version = "0.11.0"

classifiers = [
Expand Down Expand Up @@ -52,7 +52,7 @@ skip_covered = true

[tool.ruff]
line-length = 100
target-version = "py39"
target-version = "py310"

[tool.ruff.lint]
extend-ignore = ["D107"]
Expand Down Expand Up @@ -114,4 +114,4 @@ version_toml = ["pyproject.toml:project.version"]
parse_squash_commits = false

[tool.uv]
required-version = ">=0.8.0,<0.9.0"
required-version = ">=0.8.0,<0.11.0"
132 changes: 64 additions & 68 deletions src/linkup/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,12 @@ def search(
include_sources=include_sources,
)

try:
response: httpx.Response = self._request(
method="POST",
url="/search",
json=params,
timeout=timeout,
)
except httpx.TimeoutException as e:
raise LinkupTimeoutError(
"The request to the Linkup API timed out. Try increasing the timeout value."
) from e
if response.status_code != 200:
self._raise_linkup_error(response=response)
response: httpx.Response = self._request(
method="POST",
url="/search",
json=params,
timeout=timeout,
)

return self._parse_search_response(
response=response,
Expand Down Expand Up @@ -245,19 +238,12 @@ async def async_search(
include_sources=include_sources,
)

try:
response: httpx.Response = await self._async_request(
method="POST",
url="/search",
json=params,
timeout=timeout,
)
except httpx.TimeoutException as e:
raise LinkupTimeoutError(
"The request to the Linkup API timed out. Try increasing the timeout value."
) from e
if response.status_code != 200:
self._raise_linkup_error(response=response)
response: httpx.Response = await self._async_request(
method="POST",
url="/search",
json=params,
timeout=timeout,
)

return self._parse_search_response(
response=response,
Expand Down Expand Up @@ -304,19 +290,12 @@ def fetch(
extract_images=extract_images,
)

try:
response: httpx.Response = self._request(
method="POST",
url="/fetch",
json=params,
timeout=timeout,
)
except httpx.TimeoutException as e:
raise LinkupTimeoutError(
"The request to the Linkup API timed out. Try increasing the timeout value."
) from e
if response.status_code != 200:
self._raise_linkup_error(response=response)
response: httpx.Response = self._request(
method="POST",
url="/fetch",
json=params,
timeout=timeout,
)

return self._parse_fetch_response(response=response)

Expand Down Expand Up @@ -358,19 +337,12 @@ async def async_fetch(
extract_images=extract_images,
)

try:
response: httpx.Response = await self._async_request(
method="POST",
url="/fetch",
json=params,
timeout=timeout,
)
except httpx.TimeoutException as e:
raise LinkupTimeoutError(
"The request to the Linkup API timed out. Try increasing the timeout value."
) from e
if response.status_code != 200:
self._raise_linkup_error(response=response)
response: httpx.Response = await self._async_request(
method="POST",
url="/fetch",
json=params,
timeout=timeout,
)

return self._parse_fetch_response(response=response)

Expand All @@ -387,27 +359,51 @@ def _request(
self,
method: str,
url: str,
**kwargs: Any, # noqa: ANN401
) -> httpx.Response: # pragma: no cover
with httpx.Client(base_url=self._base_url, headers=self._headers()) as client:
return client.request(
method=method,
url=url,
**kwargs,
)
*,
json: dict[str, Any],
timeout: float | None,
) -> httpx.Response:
try:
with httpx.Client(base_url=self._base_url, headers=self._headers()) as client:
response: httpx.Response = client.request(
method=method,
url=url,
json=json,
timeout=timeout,
)
except httpx.TimeoutException as e:
raise LinkupTimeoutError(
"The request to the Linkup API timed out. Try increasing the timeout value."
) from e
if response.status_code != 200:
self._raise_linkup_error(response=response)
return response

async def _async_request(
self,
method: str,
url: str,
**kwargs: Any, # noqa: ANN401
) -> httpx.Response: # pragma: no cover
async with httpx.AsyncClient(base_url=self._base_url, headers=self._headers()) as client:
return await client.request(
method=method,
url=url,
**kwargs,
)
*,
json: dict[str, Any],
timeout: float | None,
) -> httpx.Response:
try:
async with httpx.AsyncClient(
base_url=self._base_url, headers=self._headers()
) as client:
response: httpx.Response = await client.request(
method=method,
url=url,
json=json,
timeout=timeout,
)
except httpx.TimeoutException as e:
raise LinkupTimeoutError(
"The request to the Linkup API timed out. Try increasing the timeout value."
) from e
if response.status_code != 200:
self._raise_linkup_error(response=response)
return response

def _raise_linkup_error(self, response: httpx.Response) -> None:
error_data = response.json()
Expand Down
4 changes: 2 additions & 2 deletions src/linkup/_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from importlib.metadata import PackageNotFoundError, version

try:
__version__ = version("linkup-sdk")
except PackageNotFoundError:
__version__: str = version("linkup-sdk")
except PackageNotFoundError: # pragma: no cover
# Fallback for when package metadata is not available (e.g., PyInstaller builds)
__version__ = "0.0.0"
24 changes: 12 additions & 12 deletions tests/unit/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def test_search(
) -> None:
mocker.patch("linkup._client.date").today.return_value = date(2000, 1, 1)
request_mock = mocker.patch(
"linkup._client.LinkupClient._request",
"httpx.Client.request",
return_value=Response(
status_code=200,
content=mock_request_response_content,
Expand Down Expand Up @@ -313,7 +313,7 @@ async def test_async_search(
) -> None:
mocker.patch("linkup._client.date").today.return_value = date(2000, 1, 1)
request_mock = mocker.patch(
"linkup._client.LinkupClient._async_request",
"httpx.AsyncClient.request",
return_value=Response(
status_code=200,
content=mock_request_response_content,
Expand Down Expand Up @@ -456,7 +456,7 @@ def test_search_error(
expected_exception: type[Exception],
) -> None:
request_mock = mocker.patch(
"linkup._client.LinkupClient._request",
"httpx.Client.request",
return_value=Response(
status_code=mock_request_response_status_code,
content=mock_request_response_content,
Expand All @@ -481,7 +481,7 @@ async def test_async_search_error(
expected_exception: type[Exception],
) -> None:
request_mock = mocker.patch(
"linkup._client.LinkupClient._async_request",
"httpx.AsyncClient.request",
return_value=Response(
status_code=mock_request_response_status_code,
content=mock_request_response_content,
Expand All @@ -498,7 +498,7 @@ def test_search_timeout(
client: LinkupClient,
) -> None:
mocker.patch(
"linkup._client.LinkupClient._request",
"httpx.Client.request",
side_effect=httpx.ReadTimeout("Request timed out"),
)

Expand All @@ -512,7 +512,7 @@ async def test_async_search_timeout(
client: LinkupClient,
) -> None:
mocker.patch(
"linkup._client.LinkupClient._async_request",
"httpx.AsyncClient.request",
side_effect=httpx.ReadTimeout("Request timed out"),
)

Expand Down Expand Up @@ -572,7 +572,7 @@ def test_fetch(
expected_fetch_response: LinkupFetchResponse,
) -> None:
request_mock = mocker.patch(
"linkup._client.LinkupClient._request",
"httpx.Client.request",
return_value=Response(
status_code=200,
content=mock_request_response_content,
Expand Down Expand Up @@ -609,7 +609,7 @@ async def test_async_fetch(
expected_fetch_response: LinkupFetchResponse,
) -> None:
request_mock = mocker.patch(
"linkup._client.LinkupClient._async_request",
"httpx.AsyncClient.request",
return_value=Response(
status_code=200,
content=mock_request_response_content,
Expand Down Expand Up @@ -674,7 +674,7 @@ def test_fetch_error(
expected_exception: type[Exception],
) -> None:
request_mock = mocker.patch(
"linkup._client.LinkupClient._request",
"httpx.Client.request",
return_value=Response(
status_code=mock_request_response_status_code,
content=mock_request_response_content,
Expand All @@ -699,7 +699,7 @@ async def test_async_fetch_error(
expected_exception: type[Exception],
) -> None:
request_mock = mocker.patch(
"linkup._client.LinkupClient._async_request",
"httpx.AsyncClient.request",
return_value=Response(
status_code=mock_request_response_status_code,
content=mock_request_response_content,
Expand All @@ -716,7 +716,7 @@ def test_fetch_timeout(
client: LinkupClient,
) -> None:
mocker.patch(
"linkup._client.LinkupClient._request",
"httpx.Client.request",
side_effect=httpx.ReadTimeout("Request timed out"),
)

Expand All @@ -730,7 +730,7 @@ async def test_async_fetch_timeout(
client: LinkupClient,
) -> None:
mocker.patch(
"linkup._client.LinkupClient._async_request",
"httpx.AsyncClient.request",
side_effect=httpx.ReadTimeout("Request timed out"),
)

Expand Down
Loading