diff --git a/README.md b/README.md index 55ac7cd..3dad6cd 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ with Client() as client: ## Requirements - Python 3.10+ -- [httpx](https://www.python-httpx.org/) (installed automatically) +- [httpx2](https://github.com/pydantic/httpx2) (installed automatically) - [pydantic](https://docs.pydantic.dev/) v2 (installed automatically) ## Contributing diff --git a/pyproject.toml b/pyproject.toml index a0bcf26..c66ecd2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,8 +24,8 @@ classifiers = [ "Typing :: Typed", ] dependencies = [ - "httpx>=0.27.0", - "pydantic>=2.7.0", + "httpx2>=2.0.0,<3", + "pydantic>=2.7.0,<3", ] [project.urls] @@ -59,6 +59,8 @@ exclude = [ "/scripts", "/spec", "/tests", + "/.gitattributes", + "/.gitignore", "uv.lock", ] @@ -98,6 +100,8 @@ typeCheckingMode = "strict" include = ["src"] [tool.pytest.ini_options] +addopts = "-p tests._alias_httpx" +pythonpath = ["."] testpaths = ["tests"] asyncio_mode = "auto" asyncio_default_fixture_loop_scope = "function" diff --git a/src/triggerdev/_base_client.py b/src/triggerdev/_base_client.py index 3420400..b12630f 100644 --- a/src/triggerdev/_base_client.py +++ b/src/triggerdev/_base_client.py @@ -5,7 +5,7 @@ import os from typing import Any, TypeVar, cast, overload -import httpx +import httpx2 from pydantic import BaseModel from triggerdev._exceptions import ( @@ -27,7 +27,7 @@ ) DEFAULT_BASE_URL = "https://api.trigger.dev" -DEFAULT_TIMEOUT = httpx.Timeout(60.0) +DEFAULT_TIMEOUT = httpx2.Timeout(60.0) DEFAULT_MAX_RETRIES = 0 _ModelT = TypeVar("_ModelT", bound=BaseModel) @@ -45,10 +45,10 @@ class BaseClient: api_key: str base_url: str - timeout: httpx.Timeout + timeout: httpx2.Timeout max_retries: int - _client: httpx.Client + _client: httpx2.Client _owns_client: bool def __init__( @@ -56,9 +56,9 @@ def __init__( *, api_key: str | None = None, base_url: str | None = None, - timeout: float | httpx.Timeout | None = None, + timeout: float | httpx2.Timeout | None = None, max_retries: int | None = None, - http_client: httpx.Client | None = None, + http_client: httpx2.Client | None = None, default_headers: dict[str, str] | None = None, ) -> None: resolved_key = api_key or os.environ.get("TRIGGER_SECRET_KEY") @@ -74,7 +74,7 @@ def __init__( if timeout is None: self.timeout = DEFAULT_TIMEOUT elif isinstance(timeout, (int, float)): - self.timeout = httpx.Timeout(float(timeout)) + self.timeout = httpx2.Timeout(float(timeout)) else: self.timeout = timeout @@ -86,7 +86,7 @@ def __init__( self._client = http_client self._owns_client = False else: - self._client = httpx.Client(timeout=self.timeout) + self._client = httpx2.Client(timeout=self.timeout) self._owns_client = True @overload @@ -154,10 +154,10 @@ def _request( params=params, headers=headers, ) - except httpx.TimeoutException as exc: - raise APITimeoutError(request=httpx.Request(method, url)) from exc - except httpx.TransportError as exc: - raise APIConnectionError(request=httpx.Request(method, url)) from exc + except httpx2.TimeoutException as exc: + raise APITimeoutError(request=httpx2.Request(method, url)) from exc + except httpx2.TransportError as exc: + raise APIConnectionError(request=httpx2.Request(method, url)) from exc if not response.is_success: raise self._make_status_error(response) @@ -173,7 +173,7 @@ def _request( return cast_to.model_validate(data) @staticmethod - def _make_status_error(response: httpx.Response) -> APIStatusError: + def _make_status_error(response: httpx2.Response) -> APIStatusError: body: dict[str, Any] | None try: raw: object = response.json() diff --git a/src/triggerdev/_client.py b/src/triggerdev/_client.py index b0507b2..fb466a5 100644 --- a/src/triggerdev/_client.py +++ b/src/triggerdev/_client.py @@ -11,7 +11,7 @@ from triggerdev.resources.tasks import Tasks if TYPE_CHECKING: - import httpx + import httpx2 class Client(BaseClient): @@ -22,9 +22,9 @@ def __init__( *, api_key: str | None = None, base_url: str | None = None, - timeout: float | httpx.Timeout | None = None, + timeout: float | httpx2.Timeout | None = None, max_retries: int | None = None, - http_client: httpx.Client | None = None, + http_client: httpx2.Client | None = None, default_headers: dict[str, str] | None = None, ) -> None: super().__init__( diff --git a/src/triggerdev/_exceptions.py b/src/triggerdev/_exceptions.py index 3043c6b..801146a 100644 --- a/src/triggerdev/_exceptions.py +++ b/src/triggerdev/_exceptions.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - import httpx + import httpx2 class TriggerDevError(Exception): @@ -21,14 +21,14 @@ def __init__(self, message: str) -> None: class APIError(TriggerDevError): """An error from the Trigger.dev API.""" - request: httpx.Request + request: httpx2.Request body: object | None def __init__( self, message: str, *, - request: httpx.Request, + request: httpx2.Request, body: object | None, ) -> None: super().__init__(message) @@ -39,14 +39,14 @@ def __init__( class APIStatusError(APIError): """An HTTP error response from the API.""" - response: httpx.Response + response: httpx2.Response status_code: int def __init__( self, message: str, *, - response: httpx.Response, + response: httpx2.Response, body: object | None, ) -> None: super().__init__( @@ -119,7 +119,7 @@ class ServiceUnavailableError(InternalServerError): class APIConnectionError(APIError): """Failed to connect to the API.""" - def __init__(self, *, request: httpx.Request) -> None: + def __init__(self, *, request: httpx2.Request) -> None: super().__init__( "Connection error.", request=request, @@ -130,7 +130,7 @@ def __init__(self, *, request: httpx.Request) -> None: class APITimeoutError(APIConnectionError): """The request timed out.""" - def __init__(self, *, request: httpx.Request) -> None: + def __init__(self, *, request: httpx2.Request) -> None: super().__init__(request=request) self.message = "Request timed out." diff --git a/src/triggerdev/types/__init__.py b/src/triggerdev/types/__init__.py index 5076f46..b1c6422 100644 --- a/src/triggerdev/types/__init__.py +++ b/src/triggerdev/types/__init__.py @@ -47,7 +47,6 @@ RunTags, SerializedError, TriggerFunction, - _ApiModel, ) from triggerdev.types.tasks import ( BatchTriggerTaskRequestBodyItem, @@ -107,5 +106,4 @@ "TriggerTaskResponse", "UpdateMetadataResponse", "UpdateScheduleOptions", - "_ApiModel", ] diff --git a/tests/_alias_httpx.py b/tests/_alias_httpx.py new file mode 100644 index 0000000..cd89cd8 --- /dev/null +++ b/tests/_alias_httpx.py @@ -0,0 +1,9 @@ +"""Loaded as an early pytest plugin (`-p tests._alias_httpx` in `pyproject.toml`). + +`respx` mocks `httpx`, while this SDK is built on `httpx2`, so we make `import httpx` (and `httpcore`) +resolve to `httpx2` (and `httpcore2`) before `respx` is imported, which lets it mock our client. +""" + +import httpx2 + +httpx2.alias_httpx() diff --git a/tests/conftest.py b/tests/conftest.py index 41f5aa0..cd88081 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,7 +2,7 @@ from __future__ import annotations -import httpx +import httpx2 import pytest import respx @@ -31,5 +31,5 @@ def client(api_key: str, base_url: str) -> Client: @pytest.fixture() -def mock_response() -> httpx.Response: - return httpx.Response(200, json={"id": "run_1234"}) +def mock_response() -> httpx2.Response: + return httpx2.Response(200, json={"id": "run_1234"}) diff --git a/tests/test_client.py b/tests/test_client.py index 98a128e..2af5a19 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -5,7 +5,7 @@ import os from unittest.mock import patch -import httpx +import httpx2 import pytest import respx @@ -62,14 +62,14 @@ def test_base_url_strips_trailing_slash(self) -> None: def test_default_timeout(self) -> None: client = Client(api_key="tr_dev_sk_test") - assert client.timeout == httpx.Timeout(60.0) + assert client.timeout == httpx2.Timeout(60.0) def test_custom_timeout_float(self) -> None: client = Client(api_key="tr_dev_sk_test", timeout=30.0) - assert client.timeout == httpx.Timeout(30.0) + assert client.timeout == httpx2.Timeout(30.0) def test_custom_timeout_object(self) -> None: - t = httpx.Timeout(10.0, connect=5.0) + t = httpx2.Timeout(10.0, connect=5.0) client = Client(api_key="tr_dev_sk_test", timeout=t) assert client.timeout == t @@ -93,7 +93,7 @@ def test_close(self) -> None: assert client.is_closed def test_custom_http_client_not_closed(self) -> None: - http_client = httpx.Client() + http_client = httpx2.Client() client = Client(api_key="tr_dev_sk_test", http_client=http_client) client.close() assert not http_client.is_closed @@ -104,7 +104,7 @@ class TestClientAuth: @respx.mock def test_auth_header_sent(self, client: Client) -> None: route = respx.get("https://api.trigger.dev/api/v1/timezones").mock( - return_value=httpx.Response(200, json={"timezones": []}) + return_value=httpx2.Response(200, json={"timezones": []}) ) client.schedules.timezones() assert route.called @@ -132,7 +132,7 @@ class TestErrorMapping: @respx.mock def test_status_code_to_exception(self, client: Client, status: int, exc_cls: type) -> None: respx.get("https://api.trigger.dev/api/v3/runs/run_1234").mock( - return_value=httpx.Response(status, json={"error": "test error"}) + return_value=httpx2.Response(status, json={"error": "test error"}) ) with pytest.raises(exc_cls): client.runs.retrieve("run_1234") @@ -140,7 +140,7 @@ def test_status_code_to_exception(self, client: Client, status: int, exc_cls: ty @respx.mock def test_unknown_4xx_raises_api_status_error(self, client: Client) -> None: respx.get("https://api.trigger.dev/api/v3/runs/run_1234").mock( - return_value=httpx.Response(418, json={"error": "I'm a teapot"}) + return_value=httpx2.Response(418, json={"error": "I'm a teapot"}) ) with pytest.raises(APIStatusError) as exc_info: client.runs.retrieve("run_1234") @@ -149,7 +149,7 @@ def test_unknown_4xx_raises_api_status_error(self, client: Client) -> None: @respx.mock def test_error_body_parsed(self, client: Client) -> None: respx.get("https://api.trigger.dev/api/v3/runs/run_1234").mock( - return_value=httpx.Response(404, json={"error": "Run not found"}) + return_value=httpx2.Response(404, json={"error": "Run not found"}) ) with pytest.raises(NotFoundError) as exc_info: client.runs.retrieve("run_1234") @@ -159,7 +159,7 @@ def test_error_body_parsed(self, client: Client) -> None: @respx.mock def test_non_json_error_body(self, client: Client) -> None: respx.get("https://api.trigger.dev/api/v3/runs/run_1234").mock( - return_value=httpx.Response( + return_value=httpx2.Response( 502, content=b"Bad Gateway", headers={"content-type": "text/html"}, @@ -173,14 +173,14 @@ def test_non_json_error_body(self, client: Client) -> None: @respx.mock def test_connection_error(self, client: Client) -> None: respx.get("https://api.trigger.dev/api/v3/runs/run_1234").mock( - side_effect=httpx.ConnectError("Connection refused") + side_effect=httpx2.ConnectError("Connection refused") ) with pytest.raises(APIConnectionError): client.runs.retrieve("run_1234") @respx.mock def test_timeout_error(self, client: Client) -> None: - respx.get("https://api.trigger.dev/api/v3/runs/run_1234").mock(side_effect=httpx.ReadTimeout("Read timed out")) + respx.get("https://api.trigger.dev/api/v3/runs/run_1234").mock(side_effect=httpx2.ReadTimeout("Read timed out")) with pytest.raises(APITimeoutError): client.runs.retrieve("run_1234") diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index ec7b5d7..1e17586 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -2,7 +2,7 @@ from __future__ import annotations -import httpx +import httpx2 import pytest from triggerdev._exceptions import ( @@ -25,12 +25,12 @@ ) -def _make_request() -> httpx.Request: - return httpx.Request("GET", "https://api.trigger.dev/api/v1/runs") +def _make_request() -> httpx2.Request: + return httpx2.Request("GET", "https://api.trigger.dev/api/v1/runs") -def _make_response(status_code: int, headers: dict[str, str] | None = None) -> httpx.Response: - return httpx.Response( +def _make_response(status_code: int, headers: dict[str, str] | None = None) -> httpx2.Response: + return httpx2.Response( status_code, request=_make_request(), headers=headers or {}, diff --git a/tests/test_resources_runs.py b/tests/test_resources_runs.py index 82bab79..c3ef9ea 100644 --- a/tests/test_resources_runs.py +++ b/tests/test_resources_runs.py @@ -4,7 +4,7 @@ from typing import TYPE_CHECKING, Any -import httpx +import httpx2 import pytest import respx @@ -39,7 +39,7 @@ class TestRunsList: @respx.mock def test_list_basic(self, client: Client) -> None: route = respx.get("https://api.trigger.dev/api/v1/runs").mock( - return_value=httpx.Response( + return_value=httpx2.Response( 200, json={ "data": [ @@ -67,7 +67,7 @@ def test_list_basic(self, client: Client) -> None: @respx.mock def test_list_with_status_filter(self, client: Client) -> None: route = respx.get("https://api.trigger.dev/api/v1/runs").mock( - return_value=httpx.Response(200, json={"data": []}) + return_value=httpx2.Response(200, json={"data": []}) ) client.runs.list(status=["QUEUED", "EXECUTING"]) request = route.calls[0].request @@ -77,7 +77,7 @@ def test_list_with_status_filter(self, client: Client) -> None: @respx.mock def test_list_with_pagination(self, client: Client) -> None: route = respx.get("https://api.trigger.dev/api/v1/runs").mock( - return_value=httpx.Response(200, json={"data": []}) + return_value=httpx2.Response(200, json={"data": []}) ) client.runs.list(page_size=10, cursor_after="run_100") request = route.calls[0].request @@ -88,7 +88,7 @@ def test_list_with_pagination(self, client: Client) -> None: @respx.mock def test_list_with_created_at_period(self, client: Client) -> None: route = respx.get("https://api.trigger.dev/api/v1/runs").mock( - return_value=httpx.Response(200, json={"data": []}) + return_value=httpx2.Response(200, json={"data": []}) ) client.runs.list(created_at_period="30d") request = route.calls[0].request @@ -100,7 +100,7 @@ class TestRunsRetrieve: @respx.mock def test_retrieve(self, client: Client) -> None: respx.get("https://api.trigger.dev/api/v3/runs/run_1234").mock( - return_value=httpx.Response(200, json=RETRIEVE_RUN_RESPONSE) + return_value=httpx2.Response(200, json=RETRIEVE_RUN_RESPONSE) ) result = client.runs.retrieve("run_1234") assert isinstance(result, RetrieveRunResponse) @@ -110,7 +110,7 @@ def test_retrieve(self, client: Client) -> None: @respx.mock def test_retrieve_not_found(self, client: Client) -> None: respx.get("https://api.trigger.dev/api/v3/runs/run_bad").mock( - return_value=httpx.Response(404, json={"error": "Run not found"}) + return_value=httpx2.Response(404, json={"error": "Run not found"}) ) with pytest.raises(NotFoundError): client.runs.retrieve("run_bad") @@ -120,7 +120,7 @@ class TestRunsResult: @respx.mock def test_result_success(self, client: Client) -> None: respx.get("https://api.trigger.dev/api/v1/runs/run_1234/result").mock( - return_value=httpx.Response( + return_value=httpx2.Response( 200, json={ "ok": True, @@ -140,7 +140,7 @@ def test_result_success(self, client: Client) -> None: @respx.mock def test_result_failure(self, client: Client) -> None: respx.get("https://api.trigger.dev/api/v1/runs/run_bad/result").mock( - return_value=httpx.Response( + return_value=httpx2.Response( 200, json={ "ok": False, @@ -158,7 +158,7 @@ class TestRunsReplay: @respx.mock def test_replay_no_overrides(self, client: Client) -> None: route = respx.post("https://api.trigger.dev/api/v1/runs/run_1234/replay").mock( - return_value=httpx.Response(200, json={"id": "run_5678"}) + return_value=httpx2.Response(200, json={"id": "run_5678"}) ) result = client.runs.replay("run_1234") assert result.id == "run_5678" @@ -169,7 +169,7 @@ def test_replay_with_overrides(self, client: Client) -> None: import json route = respx.post("https://api.trigger.dev/api/v1/runs/run_1234/replay").mock( - return_value=httpx.Response(200, json={"id": "run_9999"}) + return_value=httpx2.Response(200, json={"id": "run_9999"}) ) result = client.runs.replay( "run_1234", @@ -188,7 +188,7 @@ class TestRunsCancel: @respx.mock def test_cancel(self, client: Client) -> None: respx.post("https://api.trigger.dev/api/v2/runs/run_1234/cancel").mock( - return_value=httpx.Response(200, json={"id": "run_1234"}) + return_value=httpx2.Response(200, json={"id": "run_1234"}) ) result = client.runs.cancel("run_1234") assert result.id == "run_1234" @@ -198,7 +198,7 @@ class TestRunsReschedule: @respx.mock def test_reschedule_with_delay_string(self, client: Client) -> None: respx.post("https://api.trigger.dev/api/v1/runs/run_1234/reschedule").mock( - return_value=httpx.Response(200, json=RETRIEVE_RUN_RESPONSE) + return_value=httpx2.Response(200, json=RETRIEVE_RUN_RESPONSE) ) result = client.runs.reschedule("run_1234", delay="1h30m") assert isinstance(result, RetrieveRunResponse) @@ -209,7 +209,7 @@ def test_reschedule_with_datetime(self, client: Client) -> None: from datetime import datetime, timezone route = respx.post("https://api.trigger.dev/api/v1/runs/run_1234/reschedule").mock( - return_value=httpx.Response(200, json=RETRIEVE_RUN_RESPONSE) + return_value=httpx2.Response(200, json=RETRIEVE_RUN_RESPONSE) ) dt = datetime(2026, 12, 1, 15, 30, 0, tzinfo=timezone.utc) result = client.runs.reschedule("run_1234", delay=dt) @@ -224,7 +224,7 @@ def test_update_metadata(self, client: Client) -> None: import json route = respx.put("https://api.trigger.dev/api/v1/runs/run_1234/metadata").mock( - return_value=httpx.Response(200, json={"metadata": {"key": "value"}}) + return_value=httpx2.Response(200, json={"metadata": {"key": "value"}}) ) result = client.runs.update_metadata("run_1234", metadata={"key": "value"}) assert result.metadata == {"key": "value"} @@ -238,7 +238,7 @@ def test_add_tags(self, client: Client) -> None: import json route = respx.post("https://api.trigger.dev/api/v1/runs/run_1234/tags").mock( - return_value=httpx.Response(200, json={"message": "Successfully set 2 new tags."}) + return_value=httpx2.Response(200, json={"message": "Successfully set 2 new tags."}) ) result = client.runs.add_tags("run_1234", tags=["tag-1", "tag-2"]) assert "Successfully" in result.message @@ -248,7 +248,7 @@ def test_add_tags(self, client: Client) -> None: @respx.mock def test_add_single_tag_as_string(self, client: Client) -> None: respx.post("https://api.trigger.dev/api/v1/runs/run_1234/tags").mock( - return_value=httpx.Response(200, json={"message": "Successfully set 1 new tags."}) + return_value=httpx2.Response(200, json={"message": "Successfully set 1 new tags."}) ) result = client.runs.add_tags("run_1234", tags="single-tag") assert result.message is not None @@ -258,7 +258,7 @@ class TestRunsEvents: @respx.mock def test_events(self, client: Client) -> None: respx.get("https://api.trigger.dev/api/v1/runs/run_1234/events").mock( - return_value=httpx.Response( + return_value=httpx2.Response( 200, json={ "events": [ @@ -285,7 +285,7 @@ class TestRunsTrace: @respx.mock def test_trace_tree(self, client: Client) -> None: respx.get("https://api.trigger.dev/api/v1/runs/run_1234/trace").mock( - return_value=httpx.Response( + return_value=httpx2.Response( 200, json={ "trace": { @@ -306,7 +306,7 @@ def test_trace_tree(self, client: Client) -> None: @respx.mock def test_trace_paged(self, client: Client) -> None: respx.get("https://api.trigger.dev/api/v1/runs/run_1234/trace").mock( - return_value=httpx.Response( + return_value=httpx2.Response( 200, json={ "data": [{"id": "span_1", "message": "hello"}], diff --git a/tests/test_resources_schedules.py b/tests/test_resources_schedules.py index 4c8547d..1d01f7b 100644 --- a/tests/test_resources_schedules.py +++ b/tests/test_resources_schedules.py @@ -4,7 +4,7 @@ from typing import TYPE_CHECKING -import httpx +import httpx2 import pytest import respx @@ -33,7 +33,7 @@ class TestSchedulesList: @respx.mock def test_list_basic(self, client: Client) -> None: route = respx.get("https://api.trigger.dev/api/v1/schedules").mock( - return_value=httpx.Response( + return_value=httpx2.Response( 200, json={"data": [SCHEDULE_JSON], "pagination": {"currentPage": 1, "totalPages": 1, "count": 1}}, ) @@ -48,7 +48,7 @@ def test_list_basic(self, client: Client) -> None: @respx.mock def test_list_with_pagination(self, client: Client) -> None: route = respx.get("https://api.trigger.dev/api/v1/schedules").mock( - return_value=httpx.Response(200, json={"data": []}) + return_value=httpx2.Response(200, json={"data": []}) ) client.schedules.list(page=2, per_page=10) url = str(route.calls[0].request.url) @@ -62,7 +62,7 @@ def test_create(self, client: Client) -> None: import json route = respx.post("https://api.trigger.dev/api/v1/schedules").mock( - return_value=httpx.Response(200, json=SCHEDULE_JSON) + return_value=httpx2.Response(200, json=SCHEDULE_JSON) ) result = client.schedules.create( task="my-task", @@ -82,7 +82,7 @@ class TestSchedulesRetrieve: @respx.mock def test_retrieve(self, client: Client) -> None: respx.get("https://api.trigger.dev/api/v1/schedules/sched_1234").mock( - return_value=httpx.Response(200, json=SCHEDULE_JSON) + return_value=httpx2.Response(200, json=SCHEDULE_JSON) ) result = client.schedules.retrieve("sched_1234") assert isinstance(result, ScheduleObject) @@ -91,7 +91,7 @@ def test_retrieve(self, client: Client) -> None: @respx.mock def test_retrieve_not_found(self, client: Client) -> None: respx.get("https://api.trigger.dev/api/v1/schedules/sched_bad").mock( - return_value=httpx.Response(404, json={"error": "Resource not found"}) + return_value=httpx2.Response(404, json={"error": "Resource not found"}) ) with pytest.raises(NotFoundError): client.schedules.retrieve("sched_bad") @@ -103,7 +103,7 @@ def test_update(self, client: Client) -> None: import json route = respx.put("https://api.trigger.dev/api/v1/schedules/sched_1234").mock( - return_value=httpx.Response(200, json=SCHEDULE_JSON) + return_value=httpx2.Response(200, json=SCHEDULE_JSON) ) result = client.schedules.update( "sched_1234", @@ -119,7 +119,7 @@ class TestSchedulesDelete: @respx.mock def test_delete(self, client: Client) -> None: route = respx.delete("https://api.trigger.dev/api/v1/schedules/sched_1234").mock( - return_value=httpx.Response(200) + return_value=httpx2.Response(200) ) result = client.schedules.delete("sched_1234") assert result is None @@ -130,7 +130,7 @@ class TestSchedulesActivateDeactivate: @respx.mock def test_activate(self, client: Client) -> None: respx.post("https://api.trigger.dev/api/v1/schedules/sched_1234/activate").mock( - return_value=httpx.Response(200, json={**SCHEDULE_JSON, "active": True}) + return_value=httpx2.Response(200, json={**SCHEDULE_JSON, "active": True}) ) result = client.schedules.activate("sched_1234") assert isinstance(result, ScheduleObject) @@ -139,7 +139,7 @@ def test_activate(self, client: Client) -> None: @respx.mock def test_deactivate(self, client: Client) -> None: respx.post("https://api.trigger.dev/api/v1/schedules/sched_1234/deactivate").mock( - return_value=httpx.Response(200, json={**SCHEDULE_JSON, "active": False}) + return_value=httpx2.Response(200, json={**SCHEDULE_JSON, "active": False}) ) result = client.schedules.deactivate("sched_1234") assert isinstance(result, ScheduleObject) @@ -150,7 +150,7 @@ class TestSchedulesTimezones: @respx.mock def test_timezones(self, client: Client) -> None: respx.get("https://api.trigger.dev/api/v1/timezones").mock( - return_value=httpx.Response(200, json={"timezones": ["UTC", "America/New_York"]}) + return_value=httpx2.Response(200, json={"timezones": ["UTC", "America/New_York"]}) ) result = client.schedules.timezones() assert isinstance(result, GetTimezonesResult) @@ -160,7 +160,7 @@ def test_timezones(self, client: Client) -> None: @respx.mock def test_timezones_exclude_utc(self, client: Client) -> None: route = respx.get("https://api.trigger.dev/api/v1/timezones").mock( - return_value=httpx.Response(200, json={"timezones": ["America/New_York"]}) + return_value=httpx2.Response(200, json={"timezones": ["America/New_York"]}) ) client.schedules.timezones(exclude_utc=True) url = str(route.calls[0].request.url) diff --git a/tests/test_resources_tasks.py b/tests/test_resources_tasks.py index 4538847..934b242 100644 --- a/tests/test_resources_tasks.py +++ b/tests/test_resources_tasks.py @@ -4,7 +4,7 @@ from typing import TYPE_CHECKING -import httpx +import httpx2 import respx from triggerdev.types.tasks import ( @@ -20,7 +20,7 @@ class TestTasksTrigger: @respx.mock def test_trigger_basic(self, client: Client) -> None: route = respx.post("https://api.trigger.dev/api/v1/tasks/my-task/trigger").mock( - return_value=httpx.Response(200, json={"id": "run_1234"}) + return_value=httpx2.Response(200, json={"id": "run_1234"}) ) result = client.tasks.trigger("my-task", payload={"message": "hello"}) assert isinstance(result, TriggerTaskResponse) @@ -35,7 +35,7 @@ def test_trigger_basic(self, client: Client) -> None: @respx.mock def test_trigger_with_options(self, client: Client) -> None: route = respx.post("https://api.trigger.dev/api/v1/tasks/my-task/trigger").mock( - return_value=httpx.Response(200, json={"id": "run_5678"}) + return_value=httpx2.Response(200, json={"id": "run_5678"}) ) result = client.tasks.trigger( "my-task", @@ -52,7 +52,7 @@ def test_trigger_with_options(self, client: Client) -> None: @respx.mock def test_trigger_empty_payload(self, client: Client) -> None: respx.post("https://api.trigger.dev/api/v1/tasks/my-task/trigger").mock( - return_value=httpx.Response(200, json={"id": "run_0"}) + return_value=httpx2.Response(200, json={"id": "run_0"}) ) result = client.tasks.trigger("my-task") assert result.id == "run_0" @@ -62,7 +62,7 @@ class TestTasksBatchTrigger: @respx.mock def test_batch_trigger_by_task_id(self, client: Client) -> None: route = respx.post("https://api.trigger.dev/api/v1/tasks/my-task/batch").mock( - return_value=httpx.Response( + return_value=httpx2.Response( 200, json={"batchId": "batch_1", "runs": ["run_1", "run_2"]}, ) @@ -79,7 +79,7 @@ def test_batch_trigger_by_task_id(self, client: Client) -> None: @respx.mock def test_batch_trigger_multi_task(self, client: Client) -> None: route = respx.post("https://api.trigger.dev/api/v1/tasks/batch").mock( - return_value=httpx.Response( + return_value=httpx2.Response( 200, json={"batchId": "batch_2", "runs": ["run_3"]}, ) diff --git a/uv.lock b/uv.lock index 797f454..a451943 100644 --- a/uv.lock +++ b/uv.lock @@ -3,7 +3,8 @@ revision = 3 requires-python = ">=3.10" resolution-markers = [ "python_full_version >= '3.15'", - "python_full_version >= '3.11' and python_full_version < '3.15'", + "python_full_version >= '3.12' and python_full_version < '3.15' and sys_platform == 'emscripten'", + "(python_full_version >= '3.11' and python_full_version < '3.15' and sys_platform != 'emscripten') or (python_full_version == '3.11.*' and sys_platform == 'emscripten')", "python_full_version < '3.11'", ] @@ -263,7 +264,8 @@ version = "7.17.5" source = { registry = "https://pypi.org/simple" } resolution-markers = [ "python_full_version >= '3.15'", - "python_full_version >= '3.11' and python_full_version < '3.15'", + "python_full_version >= '3.12' and python_full_version < '3.15' and sys_platform == 'emscripten'", + "(python_full_version >= '3.11' and python_full_version < '3.15' and sys_platform != 'emscripten') or (python_full_version == '3.11.*' and sys_platform == 'emscripten')", ] sdist = { url = "https://files.pythonhosted.org/packages/b1/a8/6c44415a740290c66451e664bc42f835d65a17888be2bb17e87d6d7a27b8/coverage-7.17.5.tar.gz", hash = "sha256:4f41d35b798714a2e79ec2097d6b03c92cd3b7de58e422fce7a1ca2c0c25b276", size = 1009924, upload-time = "2026-11-23T13:54:57.93Z" } wheels = [ @@ -421,6 +423,39 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/7e/f5/f66802a942d491edb555dd61e3a9961140fd64c90bce1eafd741609d334d/httpcore-1.0.9-py3-none-any.whl", hash = "sha256:2d400746a40668fc9dec9810239072b40b4484b640a8c38fd654a024c7a1bf55", size = 78784, upload-time = "2025-04-24T22:06:20.566Z" }, ] +[[package]] +name = "httpcore2" +version = "2.14.0" +source = { registry = "https://pypi.org/simple" } +resolution-markers = [ + "python_full_version < '3.11'", +] +dependencies = [ + { name = "h11", marker = "python_full_version < '3.11'" }, + { name = "truststore", marker = "python_full_version < '3.11'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/30/ff/b53af1b49bb2cb5fa97c92215614b173ca5c1a99ded80e2d52f15a94fa6d/httpcore2-2.14.0.tar.gz", hash = "sha256:4f57a1a8249fe6af589d935cfd456f1d13bbdcb0f0fc72af9142368fc94811d7", size = 69096, upload-time = "2026-10-18T16:29:21.898Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/02/06/a8d6a8f90d11b76d9086242b6bb0ee4b503473bfc8be34c2d5b067275c22/httpcore2-2.14.0-py3-none-any.whl", hash = "sha256:4c4f64f4b544afeb778c42c0ffb5941b29e671157e90ed3f6dc787c4bca90cd1", size = 84291, upload-time = "2026-10-18T16:29:19.743Z" }, +] + +[[package]] +name = "httpcore2" +version = "2.16.2" +source = { registry = "https://pypi.org/simple" } +resolution-markers = [ + "python_full_version >= '3.15'", + "(python_full_version >= '3.11' and python_full_version < '3.15' and sys_platform != 'emscripten') or (python_full_version == '3.11.*' and sys_platform == 'emscripten')", +] +dependencies = [ + { name = "h11", marker = "(python_full_version >= '3.11' and sys_platform != 'emscripten') or (python_full_version == '3.11.*' and sys_platform == 'emscripten') or (python_full_version >= '3.15' and sys_platform == 'emscripten')" }, + { name = "truststore", marker = "(python_full_version >= '3.11' and sys_platform != 'emscripten') or (python_full_version == '3.11.*' and sys_platform == 'emscripten') or (python_full_version >= '3.15' and sys_platform == 'emscripten')" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/92/9d/df40b41f7db0370f82019820709244e7b660c52aa3da3c9e5c4e8141f6e6/httpcore2-2.16.2.tar.gz", hash = "sha256:6c519d0f7b44f7269fa9bbb4d2763db395a4a2370f046d8e8e0a4b38227815d2", size = 70064, upload-time = "2026-11-16T10:12:19.491Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/2a/e8/009c347feac27f8960605aa98d55ed263b5870dd4fd80b82fd1d00d5716c/httpcore2-2.16.2-py3-none-any.whl", hash = "sha256:16051ae2a42f776007543f32de9349a317b23d2cbb4e1456b4bac0e88b87419a", size = 85551, upload-time = "2026-11-16T10:12:16.674Z" }, +] + [[package]] name = "httpx" version = "0.28.1" @@ -436,6 +471,56 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/2a/39/e50c7c3a983047577ee07d2a9e53faf5a69493943ec3f6a384bdc792deb2/httpx-0.28.1-py3-none-any.whl", hash = "sha256:d909fcccc110f8c7faf814ca82a9a4d816bc5a6dbfea25d6591d6985b8ba59ad", size = 73517, upload-time = "2024-12-06T15:37:21.509Z" }, ] +[[package]] +name = "httpx2" +version = "2.14.0" +source = { registry = "https://pypi.org/simple" } +resolution-markers = [ + "python_full_version < '3.11'", +] +dependencies = [ + { name = "anyio", marker = "python_full_version < '3.11' and sys_platform != 'emscripten'" }, + { name = "httpcore2", version = "2.14.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11' and sys_platform != 'emscripten'" }, + { name = "idna", marker = "python_full_version < '3.11'" }, + { name = "truststore", marker = "python_full_version < '3.11' and sys_platform != 'emscripten'" }, + { name = "typing-extensions", marker = "python_full_version < '3.11'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/e8/67/58353f1848b4ba568e1ec22ea1e0d8e039f0bca5fde7e2d1f07739fd83e7/httpx2-2.14.0.tar.gz", hash = "sha256:47ad61a3c40282cd8d0dc96311531f00f5bfc71a066c6fe3b36d8f63fb9e4f6e", size = 102036, upload-time = "2026-10-18T16:29:22.627Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/69/5a/469616aa8c2cbb0bb9dd67a3c18d07c01ab604cc0b236ee1c47d260c7f6e/httpx2-2.14.0-py3-none-any.whl", hash = "sha256:9d20c13a10bae1773a0be3b0f1e5beeb4bdd549bc3a2ba18efa32897c65403e4", size = 96901, upload-time = "2026-10-18T16:29:20.819Z" }, +] + +[[package]] +name = "httpx2" +version = "2.16.2" +source = { registry = "https://pypi.org/simple" } +resolution-markers = [ + "python_full_version >= '3.15'", + "python_full_version >= '3.12' and python_full_version < '3.15' and sys_platform == 'emscripten'", + "(python_full_version >= '3.11' and python_full_version < '3.15' and sys_platform != 'emscripten') or (python_full_version == '3.11.*' and sys_platform == 'emscripten')", +] +dependencies = [ + { name = "anyio", marker = "python_full_version >= '3.11' and sys_platform != 'emscripten'" }, + { name = "httpcore2", version = "2.16.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11' and sys_platform != 'emscripten'" }, + { name = "httpx2-jsfetch", marker = "python_full_version >= '3.12' and sys_platform == 'emscripten'" }, + { name = "idna", marker = "python_full_version >= '3.11'" }, + { name = "truststore", marker = "python_full_version >= '3.11' and sys_platform != 'emscripten'" }, + { name = "typing-extensions", marker = "python_full_version >= '3.11' and python_full_version < '3.13'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/1c/77/6515121dc5ac3c743ad1bff5afe635bcd1a3f23cc40db3c5c89f7d02917d/httpx2-2.16.2.tar.gz", hash = "sha256:748b615678f07d8e3b183efe81ad13b655ca88bfc56ce4589219b2d442860574", size = 103370, upload-time = "2026-11-16T10:12:20.49Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/77/de/8c4306a3d6aa2495111986addf33a9e561eff4c47552e4c4b9251160d0ad/httpx2-2.16.2-py3-none-any.whl", hash = "sha256:f05c13aade4c45dbf1c9060647a1058f0acad62398fad96e741269edb33d46f5", size = 97893, upload-time = "2026-11-16T10:12:18.192Z" }, +] + +[[package]] +name = "httpx2-jsfetch" +version = "1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/cd/c4/0e5636363151a2a1795e0a77617168b9ca438e1748ec05fc9b5687f93d64/httpx2_jsfetch-1.0.tar.gz", hash = "sha256:70a0e3eabfef7cce5ad9c629f7d01ca05e418f586646f4ddf14782e4c1454c60", size = 6872, upload-time = "2026-08-07T00:13:07.492Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/9b/43/832f631d32e4f1211caa2ba368317739fe71f0b8530e4c9d15dc454bac2a/httpx2_jsfetch-1.0-py3-none-any.whl", hash = "sha256:cb916b707601e69a07721aabc8f3f6659be3a6893bc1ff5c6f9e02241df2da32", size = 6382, upload-time = "2026-08-07T00:13:06.567Z" }, +] + [[package]] name = "hypothesis" version = "6.168.5" @@ -541,7 +626,8 @@ version = "6.170.17" source = { registry = "https://pypi.org/simple" } resolution-markers = [ "python_full_version >= '3.15'", - "python_full_version >= '3.11' and python_full_version < '3.15'", + "python_full_version >= '3.12' and python_full_version < '3.15' and sys_platform == 'emscripten'", + "(python_full_version >= '3.11' and python_full_version < '3.15' and sys_platform != 'emscripten') or (python_full_version == '3.11.*' and sys_platform == 'emscripten')", ] dependencies = [ { name = "sortedcontainers", marker = "python_full_version >= '3.11'" }, @@ -1251,7 +1337,8 @@ wheels = [ name = "triggerdev" source = { editable = "." } dependencies = [ - { name = "httpx" }, + { name = "httpx2", version = "2.14.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, + { name = "httpx2", version = "2.16.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, { name = "pydantic" }, ] @@ -1270,8 +1357,8 @@ dev = [ [package.metadata] requires-dist = [ - { name = "httpx", specifier = ">=0.27.0" }, - { name = "pydantic", specifier = ">=2.7.0" }, + { name = "httpx2", specifier = ">=2.0.0,<3" }, + { name = "pydantic", specifier = ">=2.7.0,<3" }, ] [package.metadata.requires-dev] @@ -1286,6 +1373,15 @@ dev = [ { name = "ruff", specifier = ">=0.7" }, ] +[[package]] +name = "truststore" +version = "0.10.5" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/ee/9f/c5201d42a484c061e528825fc8e2d565f5abd50a4ced6fb7d29c4ec99b2b/truststore-0.10.5.tar.gz", hash = "sha256:30d36967ccaded5cbb38d602c433f53600036c79d502f4533a49b60a03bbefcd", size = 28091, upload-time = "2026-10-12T22:27:31.808Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/51/e9/3a7820be2bb0fe53b6bc9c3be26d3d1158004e4c3ab953aa6840b955b1e9/truststore-0.10.5-py3-none-any.whl", hash = "sha256:9aaaedaefaf06d8b206278cf8b5012bc897f485a874503501e12d776df78951c", size = 19017, upload-time = "2026-10-12T22:27:30.377Z" }, +] + [[package]] name = "typing-extensions" version = "4.16.0"