diff --git a/.fern/metadata.json b/.fern/metadata.json new file mode 100644 index 0000000..66d2553 --- /dev/null +++ b/.fern/metadata.json @@ -0,0 +1,13 @@ +{ + "cliVersion": "1.0.4", + "generatorName": "fernapi/fern-python-sdk", + "generatorVersion": "4.36.2", + "generatorConfig": { + "client": { + "class_name": "Client", + "filename": "client.py", + "exported_class_name": "Pipedream", + "exported_filename": "pipedream.py" + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index ea4d0a3..27ab363 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,21 @@ The Pipedream Python library provides convenient access to the Pipedream APIs from Python. +## Table of Contents + +- [Installation](#installation) +- [Reference](#reference) +- [Usage](#usage) +- [Async Client](#async-client) +- [Exception Handling](#exception-handling) +- [Pagination](#pagination) +- [Advanced](#advanced) + - [Access Raw Response Data](#access-raw-response-data) + - [Retries](#retries) + - [Timeouts](#timeouts) + - [Custom Client](#custom-client) +- [Contributing](#contributing) + ## Installation ```sh @@ -89,14 +104,7 @@ client = Pipedream( client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", ) -response = client.apps.list( - after="after", - before="before", - limit=1, - q="q", - sort_key="name", - sort_direction="asc", -) +response = client.apps.list() for item in response: yield item # alternatively, you can paginate page-by-page @@ -104,6 +112,15 @@ for page in response.iter_pages(): yield page ``` +```python +# You can also iterate through pages and access the typed response per page +pager = client.apps.list(...) +for page in pager.iter_pages(): + print(page.response) # access the typed response for each page + for item in page: + print(item) +``` + ## Advanced ### Access Raw Response Data @@ -121,11 +138,11 @@ response = client.actions.with_raw_response.run(...) print(response.headers) # access the response headers print(response.data) # access the underlying object pager = client.apps.list(...) -print(pager.response.headers) # access the response headers for the first page +print(pager.response) # access the typed response for the first page for item in pager: print(item) # access the underlying object(s) for page in pager.iter_pages(): - print(page.response.headers) # access the response headers for each page + print(page.response) # access the typed response for each page for item in page: print(item) # access the underlying object(s) ``` diff --git a/poetry.lock b/poetry.lock index fef3795..794340b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -38,13 +38,13 @@ trio = ["trio (>=0.26.1)"] [[package]] name = "certifi" -version = "2025.10.5" +version = "2025.11.12" description = "Python package for providing Mozilla's CA Bundle." optional = false python-versions = ">=3.7" files = [ - {file = "certifi-2025.10.5-py3-none-any.whl", hash = "sha256:0f212c2744a9bb6de0c56639a6f68afe01ecd92d91f14ae897c4fe7bbeeef0de"}, - {file = "certifi-2025.10.5.tar.gz", hash = "sha256:47c09d31ccf2acf0be3f701ea53595ee7e0b8fa08801c6624be771df09ae7b43"}, + {file = "certifi-2025.11.12-py3-none-any.whl", hash = "sha256:97de8790030bbd5c2d96b7ec782fc2f7820ef8dba6db909ccf95449f2d062d4b"}, + {file = "certifi-2025.11.12.tar.gz", hash = "sha256:d8ab5478f2ecd78af242878415affce761ca6bc54a22a27e026d7c25357c3316"}, ] [[package]] diff --git a/pyproject.toml b/pyproject.toml index c93c57d..4b3727b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ name = "pipedream" [tool.poetry] name = "pipedream" -version = "1.0.11" +version = "1.0.12" description = "" readme = "README.md" authors = [] @@ -30,7 +30,7 @@ packages = [ { include = "pipedream", from = "src"} ] -[project.urls] +[tool.poetry.urls] Repository = 'https://github.com/PipedreamHQ/pipedream-sdk-python' [tool.poetry.dependencies] diff --git a/src/pipedream/accounts/client.py b/src/pipedream/accounts/client.py index 84f3fdf..22ff573 100644 --- a/src/pipedream/accounts/client.py +++ b/src/pipedream/accounts/client.py @@ -6,6 +6,7 @@ from ..core.pagination import AsyncPager, SyncPager from ..core.request_options import RequestOptions from ..types.account import Account +from ..types.list_accounts_response import ListAccountsResponse from .raw_client import AsyncRawAccountsClient, RawAccountsClient # this is used as the default value for optional parameters @@ -38,7 +39,7 @@ def list( app: typing.Optional[str] = None, include_credentials: typing.Optional[bool] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> SyncPager[Account]: + ) -> SyncPager[Account, ListAccountsResponse]: """ Retrieve all connected accounts for the project with optional filtering @@ -69,7 +70,7 @@ def list( Returns ------- - SyncPager[Account] + SyncPager[Account, ListAccountsResponse] accounts listed Examples @@ -82,15 +83,7 @@ def list( client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", ) - response = client.accounts.list( - external_user_id="external_user_id", - oauth_app_id="oauth_app_id", - after="after", - before="before", - limit=1, - app="app", - include_credentials=True, - ) + response = client.accounts.list() for item in response: yield item # alternatively, you can paginate page-by-page @@ -160,8 +153,6 @@ def create( client_secret="YOUR_CLIENT_SECRET", ) client.accounts.create( - external_user_id="external_user_id", - oauth_app_id="oauth_app_id", app_slug="app_slug", cfmap_json="cfmap_json", connect_token="connect_token", @@ -215,7 +206,6 @@ def retrieve( ) client.accounts.retrieve( account_id="account_id", - include_credentials=True, ) """ _response = self._raw_client.retrieve( @@ -314,7 +304,7 @@ async def list( app: typing.Optional[str] = None, include_credentials: typing.Optional[bool] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncPager[Account]: + ) -> AsyncPager[Account, ListAccountsResponse]: """ Retrieve all connected accounts for the project with optional filtering @@ -345,7 +335,7 @@ async def list( Returns ------- - AsyncPager[Account] + AsyncPager[Account, ListAccountsResponse] accounts listed Examples @@ -363,15 +353,7 @@ async def list( async def main() -> None: - response = await client.accounts.list( - external_user_id="external_user_id", - oauth_app_id="oauth_app_id", - after="after", - before="before", - limit=1, - app="app", - include_credentials=True, - ) + response = await client.accounts.list() async for item in response: yield item @@ -450,8 +432,6 @@ async def create( async def main() -> None: await client.accounts.create( - external_user_id="external_user_id", - oauth_app_id="oauth_app_id", app_slug="app_slug", cfmap_json="cfmap_json", connect_token="connect_token", @@ -513,7 +493,6 @@ async def retrieve( async def main() -> None: await client.accounts.retrieve( account_id="account_id", - include_credentials=True, ) diff --git a/src/pipedream/accounts/raw_client.py b/src/pipedream/accounts/raw_client.py index ac44791..9539d78 100644 --- a/src/pipedream/accounts/raw_client.py +++ b/src/pipedream/accounts/raw_client.py @@ -7,7 +7,7 @@ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.http_response import AsyncHttpResponse, HttpResponse from ..core.jsonable_encoder import jsonable_encoder -from ..core.pagination import AsyncPager, BaseHttpResponse, SyncPager +from ..core.pagination import AsyncPager, SyncPager from ..core.pydantic_utilities import parse_obj_as from ..core.request_options import RequestOptions from ..errors.too_many_requests_error import TooManyRequestsError @@ -33,7 +33,7 @@ def list( app: typing.Optional[str] = None, include_credentials: typing.Optional[bool] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> SyncPager[Account]: + ) -> SyncPager[Account, ListAccountsResponse]: """ Retrieve all connected accounts for the project with optional filtering @@ -64,7 +64,7 @@ def list( Returns ------- - SyncPager[Account] + SyncPager[Account, ListAccountsResponse] accounts listed """ _response = self._client_wrapper.httpx_client.request( @@ -106,16 +106,14 @@ def list( include_credentials=include_credentials, request_options=request_options, ) - return SyncPager( - has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response) - ) + return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -199,9 +197,9 @@ def create( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -258,9 +256,9 @@ def retrieve( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -297,9 +295,9 @@ def delete(self, account_id: str, *, request_options: typing.Optional[RequestOpt raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -338,9 +336,9 @@ def delete_by_app( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -366,7 +364,7 @@ async def list( app: typing.Optional[str] = None, include_credentials: typing.Optional[bool] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncPager[Account]: + ) -> AsyncPager[Account, ListAccountsResponse]: """ Retrieve all connected accounts for the project with optional filtering @@ -397,7 +395,7 @@ async def list( Returns ------- - AsyncPager[Account] + AsyncPager[Account, ListAccountsResponse] accounts listed """ _response = await self._client_wrapper.httpx_client.request( @@ -442,16 +440,14 @@ async def _get_next(): request_options=request_options, ) - return AsyncPager( - has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response) - ) + return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -535,9 +531,9 @@ async def create( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -594,9 +590,9 @@ async def retrieve( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -635,9 +631,9 @@ async def delete( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -676,9 +672,9 @@ async def delete_by_app( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), diff --git a/src/pipedream/actions/client.py b/src/pipedream/actions/client.py index cebb494..8bbfdd9 100644 --- a/src/pipedream/actions/client.py +++ b/src/pipedream/actions/client.py @@ -8,6 +8,7 @@ from ..types.component import Component from ..types.configure_prop_response import ConfigurePropResponse from ..types.configured_props import ConfiguredProps +from ..types.get_components_response import GetComponentsResponse from ..types.reload_props_response import ReloadPropsResponse from ..types.run_action_opts_stash_id import RunActionOptsStashId from ..types.run_action_response import RunActionResponse @@ -41,7 +42,7 @@ def list( q: typing.Optional[str] = None, app: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> SyncPager[Component]: + ) -> SyncPager[Component, GetComponentsResponse]: """ Retrieve available actions with optional search and app filtering @@ -67,7 +68,7 @@ def list( Returns ------- - SyncPager[Component] + SyncPager[Component, GetComponentsResponse] actions listed Examples @@ -80,13 +81,7 @@ def list( client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", ) - response = client.actions.list( - after="after", - before="before", - limit=1, - q="q", - app="app", - ) + response = client.actions.list() for item in response: yield item # alternatively, you can paginate page-by-page @@ -152,7 +147,7 @@ def configure_prop( configured_props: typing.Optional[ConfiguredProps] = OMIT, dynamic_props_id: typing.Optional[str] = OMIT, page: typing.Optional[float] = OMIT, - prev_context: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT, + prev_context: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, query: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> ConfigurePropResponse: @@ -184,7 +179,7 @@ def configure_prop( page : typing.Optional[float] Page number for paginated results - prev_context : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] + prev_context : typing.Optional[typing.Dict[str, typing.Any]] Previous context for pagination query : typing.Optional[str] @@ -387,7 +382,7 @@ async def list( q: typing.Optional[str] = None, app: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncPager[Component]: + ) -> AsyncPager[Component, GetComponentsResponse]: """ Retrieve available actions with optional search and app filtering @@ -413,7 +408,7 @@ async def list( Returns ------- - AsyncPager[Component] + AsyncPager[Component, GetComponentsResponse] actions listed Examples @@ -431,13 +426,7 @@ async def list( async def main() -> None: - response = await client.actions.list( - after="after", - before="before", - limit=1, - q="q", - app="app", - ) + response = await client.actions.list() async for item in response: yield item @@ -515,7 +504,7 @@ async def configure_prop( configured_props: typing.Optional[ConfiguredProps] = OMIT, dynamic_props_id: typing.Optional[str] = OMIT, page: typing.Optional[float] = OMIT, - prev_context: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT, + prev_context: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, query: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> ConfigurePropResponse: @@ -547,7 +536,7 @@ async def configure_prop( page : typing.Optional[float] Page number for paginated results - prev_context : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] + prev_context : typing.Optional[typing.Dict[str, typing.Any]] Previous context for pagination query : typing.Optional[str] diff --git a/src/pipedream/actions/raw_client.py b/src/pipedream/actions/raw_client.py index 1637a43..716e155 100644 --- a/src/pipedream/actions/raw_client.py +++ b/src/pipedream/actions/raw_client.py @@ -7,7 +7,7 @@ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.http_response import AsyncHttpResponse, HttpResponse from ..core.jsonable_encoder import jsonable_encoder -from ..core.pagination import AsyncPager, BaseHttpResponse, SyncPager +from ..core.pagination import AsyncPager, SyncPager from ..core.pydantic_utilities import parse_obj_as from ..core.request_options import RequestOptions from ..core.serialization import convert_and_respect_annotation_metadata @@ -38,7 +38,7 @@ def list( q: typing.Optional[str] = None, app: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> SyncPager[Component]: + ) -> SyncPager[Component, GetComponentsResponse]: """ Retrieve available actions with optional search and app filtering @@ -64,7 +64,7 @@ def list( Returns ------- - SyncPager[Component] + SyncPager[Component, GetComponentsResponse] actions listed """ _response = self._client_wrapper.httpx_client.request( @@ -102,16 +102,14 @@ def list( app=app, request_options=request_options, ) - return SyncPager( - has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response) - ) + return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -170,9 +168,9 @@ def retrieve( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -193,7 +191,7 @@ def configure_prop( configured_props: typing.Optional[ConfiguredProps] = OMIT, dynamic_props_id: typing.Optional[str] = OMIT, page: typing.Optional[float] = OMIT, - prev_context: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT, + prev_context: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, query: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> HttpResponse[ConfigurePropResponse]: @@ -225,7 +223,7 @@ def configure_prop( page : typing.Optional[float] Page number for paginated results - prev_context : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] + prev_context : typing.Optional[typing.Dict[str, typing.Any]] Previous context for pagination query : typing.Optional[str] @@ -276,9 +274,9 @@ def configure_prop( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -362,9 +360,9 @@ def reload_props( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -426,7 +424,7 @@ def run( ), "dynamic_props_id": dynamic_props_id, "stash_id": convert_and_respect_annotation_metadata( - object_=stash_id, annotation=RunActionOptsStashId, direction="write" + object_=stash_id, annotation=typing.Optional[RunActionOptsStashId], direction="write" ), }, headers={ @@ -449,9 +447,9 @@ def run( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -475,7 +473,7 @@ async def list( q: typing.Optional[str] = None, app: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncPager[Component]: + ) -> AsyncPager[Component, GetComponentsResponse]: """ Retrieve available actions with optional search and app filtering @@ -501,7 +499,7 @@ async def list( Returns ------- - AsyncPager[Component] + AsyncPager[Component, GetComponentsResponse] actions listed """ _response = await self._client_wrapper.httpx_client.request( @@ -542,16 +540,14 @@ async def _get_next(): request_options=request_options, ) - return AsyncPager( - has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response) - ) + return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -610,9 +606,9 @@ async def retrieve( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -633,7 +629,7 @@ async def configure_prop( configured_props: typing.Optional[ConfiguredProps] = OMIT, dynamic_props_id: typing.Optional[str] = OMIT, page: typing.Optional[float] = OMIT, - prev_context: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT, + prev_context: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, query: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> AsyncHttpResponse[ConfigurePropResponse]: @@ -665,7 +661,7 @@ async def configure_prop( page : typing.Optional[float] Page number for paginated results - prev_context : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] + prev_context : typing.Optional[typing.Dict[str, typing.Any]] Previous context for pagination query : typing.Optional[str] @@ -716,9 +712,9 @@ async def configure_prop( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -802,9 +798,9 @@ async def reload_props( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -866,7 +862,7 @@ async def run( ), "dynamic_props_id": dynamic_props_id, "stash_id": convert_and_respect_annotation_metadata( - object_=stash_id, annotation=RunActionOptsStashId, direction="write" + object_=stash_id, annotation=typing.Optional[RunActionOptsStashId], direction="write" ), }, headers={ @@ -889,9 +885,9 @@ async def run( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), diff --git a/src/pipedream/apps/__init__.py b/src/pipedream/apps/__init__.py index 3a7655e..4074914 100644 --- a/src/pipedream/apps/__init__.py +++ b/src/pipedream/apps/__init__.py @@ -6,8 +6,8 @@ from importlib import import_module if typing.TYPE_CHECKING: - from .types import AppsListRequestSortDirection, AppsListRequestSortKey -_dynamic_imports: typing.Dict[str, str] = {"AppsListRequestSortDirection": ".types", "AppsListRequestSortKey": ".types"} + from .types import ListAppsRequestSortDirection, ListAppsRequestSortKey +_dynamic_imports: typing.Dict[str, str] = {"ListAppsRequestSortDirection": ".types", "ListAppsRequestSortKey": ".types"} def __getattr__(attr_name: str) -> typing.Any: @@ -31,4 +31,4 @@ def __dir__(): return sorted(lazy_attrs) -__all__ = ["AppsListRequestSortDirection", "AppsListRequestSortKey"] +__all__ = ["ListAppsRequestSortDirection", "ListAppsRequestSortKey"] diff --git a/src/pipedream/apps/client.py b/src/pipedream/apps/client.py index 512d8df..99d2dbc 100644 --- a/src/pipedream/apps/client.py +++ b/src/pipedream/apps/client.py @@ -7,9 +7,10 @@ from ..core.request_options import RequestOptions from ..types.app import App from ..types.get_app_response import GetAppResponse +from ..types.list_apps_response import ListAppsResponse from .raw_client import AsyncRawAppsClient, RawAppsClient -from .types.apps_list_request_sort_direction import AppsListRequestSortDirection -from .types.apps_list_request_sort_key import AppsListRequestSortKey +from .types.list_apps_request_sort_direction import ListAppsRequestSortDirection +from .types.list_apps_request_sort_key import ListAppsRequestSortKey class AppsClient: @@ -34,11 +35,11 @@ def list( before: typing.Optional[str] = None, limit: typing.Optional[int] = None, q: typing.Optional[str] = None, - sort_key: typing.Optional[AppsListRequestSortKey] = None, - sort_direction: typing.Optional[AppsListRequestSortDirection] = None, + sort_key: typing.Optional[ListAppsRequestSortKey] = None, + sort_direction: typing.Optional[ListAppsRequestSortDirection] = None, category_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> SyncPager[App]: + ) -> SyncPager[App, ListAppsResponse]: """ Retrieve all available apps with optional filtering and sorting @@ -56,10 +57,10 @@ def list( q : typing.Optional[str] A search query to filter the apps - sort_key : typing.Optional[AppsListRequestSortKey] + sort_key : typing.Optional[ListAppsRequestSortKey] The key to sort the apps by - sort_direction : typing.Optional[AppsListRequestSortDirection] + sort_direction : typing.Optional[ListAppsRequestSortDirection] The direction to sort the apps category_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]] @@ -70,7 +71,7 @@ def list( Returns ------- - SyncPager[App] + SyncPager[App, ListAppsResponse] apps listed Examples @@ -83,14 +84,7 @@ def list( client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", ) - response = client.apps.list( - after="after", - before="before", - limit=1, - q="q", - sort_key="name", - sort_direction="asc", - ) + response = client.apps.list() for item in response: yield item # alternatively, you can paginate page-by-page @@ -165,11 +159,11 @@ async def list( before: typing.Optional[str] = None, limit: typing.Optional[int] = None, q: typing.Optional[str] = None, - sort_key: typing.Optional[AppsListRequestSortKey] = None, - sort_direction: typing.Optional[AppsListRequestSortDirection] = None, + sort_key: typing.Optional[ListAppsRequestSortKey] = None, + sort_direction: typing.Optional[ListAppsRequestSortDirection] = None, category_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncPager[App]: + ) -> AsyncPager[App, ListAppsResponse]: """ Retrieve all available apps with optional filtering and sorting @@ -187,10 +181,10 @@ async def list( q : typing.Optional[str] A search query to filter the apps - sort_key : typing.Optional[AppsListRequestSortKey] + sort_key : typing.Optional[ListAppsRequestSortKey] The key to sort the apps by - sort_direction : typing.Optional[AppsListRequestSortDirection] + sort_direction : typing.Optional[ListAppsRequestSortDirection] The direction to sort the apps category_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]] @@ -201,7 +195,7 @@ async def list( Returns ------- - AsyncPager[App] + AsyncPager[App, ListAppsResponse] apps listed Examples @@ -219,14 +213,7 @@ async def list( async def main() -> None: - response = await client.apps.list( - after="after", - before="before", - limit=1, - q="q", - sort_key="name", - sort_direction="asc", - ) + response = await client.apps.list() async for item in response: yield item diff --git a/src/pipedream/apps/raw_client.py b/src/pipedream/apps/raw_client.py index 3bf84a7..f18b69c 100644 --- a/src/pipedream/apps/raw_client.py +++ b/src/pipedream/apps/raw_client.py @@ -7,14 +7,14 @@ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.http_response import AsyncHttpResponse, HttpResponse from ..core.jsonable_encoder import jsonable_encoder -from ..core.pagination import AsyncPager, BaseHttpResponse, SyncPager +from ..core.pagination import AsyncPager, SyncPager from ..core.pydantic_utilities import parse_obj_as from ..core.request_options import RequestOptions from ..types.app import App from ..types.get_app_response import GetAppResponse from ..types.list_apps_response import ListAppsResponse -from .types.apps_list_request_sort_direction import AppsListRequestSortDirection -from .types.apps_list_request_sort_key import AppsListRequestSortKey +from .types.list_apps_request_sort_direction import ListAppsRequestSortDirection +from .types.list_apps_request_sort_key import ListAppsRequestSortKey class RawAppsClient: @@ -28,11 +28,11 @@ def list( before: typing.Optional[str] = None, limit: typing.Optional[int] = None, q: typing.Optional[str] = None, - sort_key: typing.Optional[AppsListRequestSortKey] = None, - sort_direction: typing.Optional[AppsListRequestSortDirection] = None, + sort_key: typing.Optional[ListAppsRequestSortKey] = None, + sort_direction: typing.Optional[ListAppsRequestSortDirection] = None, category_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> SyncPager[App]: + ) -> SyncPager[App, ListAppsResponse]: """ Retrieve all available apps with optional filtering and sorting @@ -50,10 +50,10 @@ def list( q : typing.Optional[str] A search query to filter the apps - sort_key : typing.Optional[AppsListRequestSortKey] + sort_key : typing.Optional[ListAppsRequestSortKey] The key to sort the apps by - sort_direction : typing.Optional[AppsListRequestSortDirection] + sort_direction : typing.Optional[ListAppsRequestSortDirection] The direction to sort the apps category_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]] @@ -64,7 +64,7 @@ def list( Returns ------- - SyncPager[App] + SyncPager[App, ListAppsResponse] apps listed """ _response = self._client_wrapper.httpx_client.request( @@ -106,9 +106,7 @@ def list( category_ids=category_ids, request_options=request_options, ) - return SyncPager( - has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response) - ) + return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) @@ -165,11 +163,11 @@ async def list( before: typing.Optional[str] = None, limit: typing.Optional[int] = None, q: typing.Optional[str] = None, - sort_key: typing.Optional[AppsListRequestSortKey] = None, - sort_direction: typing.Optional[AppsListRequestSortDirection] = None, + sort_key: typing.Optional[ListAppsRequestSortKey] = None, + sort_direction: typing.Optional[ListAppsRequestSortDirection] = None, category_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncPager[App]: + ) -> AsyncPager[App, ListAppsResponse]: """ Retrieve all available apps with optional filtering and sorting @@ -187,10 +185,10 @@ async def list( q : typing.Optional[str] A search query to filter the apps - sort_key : typing.Optional[AppsListRequestSortKey] + sort_key : typing.Optional[ListAppsRequestSortKey] The key to sort the apps by - sort_direction : typing.Optional[AppsListRequestSortDirection] + sort_direction : typing.Optional[ListAppsRequestSortDirection] The direction to sort the apps category_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]] @@ -201,7 +199,7 @@ async def list( Returns ------- - AsyncPager[App] + AsyncPager[App, ListAppsResponse] apps listed """ _response = await self._client_wrapper.httpx_client.request( @@ -246,9 +244,7 @@ async def _get_next(): request_options=request_options, ) - return AsyncPager( - has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response) - ) + return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) _response_json = _response.json() except JSONDecodeError: raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) diff --git a/src/pipedream/apps/types/__init__.py b/src/pipedream/apps/types/__init__.py index 08c3a02..526f29a 100644 --- a/src/pipedream/apps/types/__init__.py +++ b/src/pipedream/apps/types/__init__.py @@ -6,11 +6,11 @@ from importlib import import_module if typing.TYPE_CHECKING: - from .apps_list_request_sort_direction import AppsListRequestSortDirection - from .apps_list_request_sort_key import AppsListRequestSortKey + from .list_apps_request_sort_direction import ListAppsRequestSortDirection + from .list_apps_request_sort_key import ListAppsRequestSortKey _dynamic_imports: typing.Dict[str, str] = { - "AppsListRequestSortDirection": ".apps_list_request_sort_direction", - "AppsListRequestSortKey": ".apps_list_request_sort_key", + "ListAppsRequestSortDirection": ".list_apps_request_sort_direction", + "ListAppsRequestSortKey": ".list_apps_request_sort_key", } @@ -35,4 +35,4 @@ def __dir__(): return sorted(lazy_attrs) -__all__ = ["AppsListRequestSortDirection", "AppsListRequestSortKey"] +__all__ = ["ListAppsRequestSortDirection", "ListAppsRequestSortKey"] diff --git a/src/pipedream/apps/types/apps_list_request_sort_direction.py b/src/pipedream/apps/types/list_apps_request_sort_direction.py similarity index 61% rename from src/pipedream/apps/types/apps_list_request_sort_direction.py rename to src/pipedream/apps/types/list_apps_request_sort_direction.py index d841cc9..4d86906 100644 --- a/src/pipedream/apps/types/apps_list_request_sort_direction.py +++ b/src/pipedream/apps/types/list_apps_request_sort_direction.py @@ -2,4 +2,4 @@ import typing -AppsListRequestSortDirection = typing.Union[typing.Literal["asc", "desc"], typing.Any] +ListAppsRequestSortDirection = typing.Union[typing.Literal["asc", "desc"], typing.Any] diff --git a/src/pipedream/apps/types/apps_list_request_sort_key.py b/src/pipedream/apps/types/list_apps_request_sort_key.py similarity index 65% rename from src/pipedream/apps/types/apps_list_request_sort_key.py rename to src/pipedream/apps/types/list_apps_request_sort_key.py index ab4065d..6e9b8e2 100644 --- a/src/pipedream/apps/types/apps_list_request_sort_key.py +++ b/src/pipedream/apps/types/list_apps_request_sort_key.py @@ -2,4 +2,4 @@ import typing -AppsListRequestSortKey = typing.Union[typing.Literal["name", "name_slug", "featured_weight"], typing.Any] +ListAppsRequestSortKey = typing.Union[typing.Literal["name", "name_slug", "featured_weight"], typing.Any] diff --git a/src/pipedream/client.py b/src/pipedream/client.py index 6f4accc..cfb7782 100644 --- a/src/pipedream/client.py +++ b/src/pipedream/client.py @@ -6,7 +6,7 @@ import typing import httpx -from .types.project_environment import ProjectEnvironment +from ._.types.project_environment import ProjectEnvironment from .core.api_error import ApiError from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from .core.oauth_token_provider import OAuthTokenProvider diff --git a/src/pipedream/components/client.py b/src/pipedream/components/client.py index a68c358..3e9d456 100644 --- a/src/pipedream/components/client.py +++ b/src/pipedream/components/client.py @@ -9,6 +9,7 @@ from ..types.component_type import ComponentType from ..types.configure_prop_response import ConfigurePropResponse from ..types.configured_props import ConfiguredProps +from ..types.get_components_response import GetComponentsResponse from ..types.reload_props_response import ReloadPropsResponse from .raw_client import AsyncRawComponentsClient, RawComponentsClient @@ -41,7 +42,7 @@ def list( app: typing.Optional[str] = None, component_type: typing.Optional[ComponentType] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> SyncPager[Component]: + ) -> SyncPager[Component, GetComponentsResponse]: """ Retrieve available components with optional search and app filtering @@ -70,7 +71,7 @@ def list( Returns ------- - SyncPager[Component] + SyncPager[Component, GetComponentsResponse] components listed Examples @@ -83,14 +84,7 @@ def list( client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", ) - response = client.components.list( - after="after", - before="before", - limit=1, - q="q", - app="app", - component_type="trigger", - ) + response = client.components.list() for item in response: yield item # alternatively, you can paginate page-by-page @@ -162,7 +156,7 @@ def configure_prop( configured_props: typing.Optional[ConfiguredProps] = OMIT, dynamic_props_id: typing.Optional[str] = OMIT, page: typing.Optional[float] = OMIT, - prev_context: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT, + prev_context: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, query: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> ConfigurePropResponse: @@ -194,7 +188,7 @@ def configure_prop( page : typing.Optional[float] Page number for paginated results - prev_context : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] + prev_context : typing.Optional[typing.Dict[str, typing.Any]] Previous context for pagination query : typing.Optional[str] @@ -332,7 +326,7 @@ async def list( app: typing.Optional[str] = None, component_type: typing.Optional[ComponentType] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncPager[Component]: + ) -> AsyncPager[Component, GetComponentsResponse]: """ Retrieve available components with optional search and app filtering @@ -361,7 +355,7 @@ async def list( Returns ------- - AsyncPager[Component] + AsyncPager[Component, GetComponentsResponse] components listed Examples @@ -379,14 +373,7 @@ async def list( async def main() -> None: - response = await client.components.list( - after="after", - before="before", - limit=1, - q="q", - app="app", - component_type="trigger", - ) + response = await client.components.list() async for item in response: yield item @@ -470,7 +457,7 @@ async def configure_prop( configured_props: typing.Optional[ConfiguredProps] = OMIT, dynamic_props_id: typing.Optional[str] = OMIT, page: typing.Optional[float] = OMIT, - prev_context: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT, + prev_context: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, query: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> ConfigurePropResponse: @@ -502,7 +489,7 @@ async def configure_prop( page : typing.Optional[float] Page number for paginated results - prev_context : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] + prev_context : typing.Optional[typing.Dict[str, typing.Any]] Previous context for pagination query : typing.Optional[str] diff --git a/src/pipedream/components/raw_client.py b/src/pipedream/components/raw_client.py index 3453921..756d01a 100644 --- a/src/pipedream/components/raw_client.py +++ b/src/pipedream/components/raw_client.py @@ -7,7 +7,7 @@ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.http_response import AsyncHttpResponse, HttpResponse from ..core.jsonable_encoder import jsonable_encoder -from ..core.pagination import AsyncPager, BaseHttpResponse, SyncPager +from ..core.pagination import AsyncPager, SyncPager from ..core.pydantic_utilities import parse_obj_as from ..core.request_options import RequestOptions from ..core.serialization import convert_and_respect_annotation_metadata @@ -38,7 +38,7 @@ def list( app: typing.Optional[str] = None, component_type: typing.Optional[ComponentType] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> SyncPager[Component]: + ) -> SyncPager[Component, GetComponentsResponse]: """ Retrieve available components with optional search and app filtering @@ -67,7 +67,7 @@ def list( Returns ------- - SyncPager[Component] + SyncPager[Component, GetComponentsResponse] components listed """ _response = self._client_wrapper.httpx_client.request( @@ -107,16 +107,14 @@ def list( component_type=component_type, request_options=request_options, ) - return SyncPager( - has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response) - ) + return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -175,9 +173,9 @@ def retrieve( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -198,7 +196,7 @@ def configure_prop( configured_props: typing.Optional[ConfiguredProps] = OMIT, dynamic_props_id: typing.Optional[str] = OMIT, page: typing.Optional[float] = OMIT, - prev_context: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT, + prev_context: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, query: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> HttpResponse[ConfigurePropResponse]: @@ -230,7 +228,7 @@ def configure_prop( page : typing.Optional[float] Page number for paginated results - prev_context : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] + prev_context : typing.Optional[typing.Dict[str, typing.Any]] Previous context for pagination query : typing.Optional[str] @@ -281,9 +279,9 @@ def configure_prop( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -367,9 +365,9 @@ def reload_props( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -394,7 +392,7 @@ async def list( app: typing.Optional[str] = None, component_type: typing.Optional[ComponentType] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncPager[Component]: + ) -> AsyncPager[Component, GetComponentsResponse]: """ Retrieve available components with optional search and app filtering @@ -423,7 +421,7 @@ async def list( Returns ------- - AsyncPager[Component] + AsyncPager[Component, GetComponentsResponse] components listed """ _response = await self._client_wrapper.httpx_client.request( @@ -466,16 +464,14 @@ async def _get_next(): request_options=request_options, ) - return AsyncPager( - has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response) - ) + return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -534,9 +530,9 @@ async def retrieve( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -557,7 +553,7 @@ async def configure_prop( configured_props: typing.Optional[ConfiguredProps] = OMIT, dynamic_props_id: typing.Optional[str] = OMIT, page: typing.Optional[float] = OMIT, - prev_context: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT, + prev_context: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, query: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> AsyncHttpResponse[ConfigurePropResponse]: @@ -589,7 +585,7 @@ async def configure_prop( page : typing.Optional[float] Page number for paginated results - prev_context : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] + prev_context : typing.Optional[typing.Dict[str, typing.Any]] Previous context for pagination query : typing.Optional[str] @@ -640,9 +636,9 @@ async def configure_prop( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -726,9 +722,9 @@ async def reload_props( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), diff --git a/src/pipedream/core/client_wrapper.py b/src/pipedream/core/client_wrapper.py index d1cbb05..5792b1c 100644 --- a/src/pipedream/core/client_wrapper.py +++ b/src/pipedream/core/client_wrapper.py @@ -3,7 +3,7 @@ import typing import httpx -from ..types.project_environment import ProjectEnvironment +from .._.types.project_environment import ProjectEnvironment from .http_client import AsyncHttpClient, HttpClient @@ -27,10 +27,10 @@ def __init__( def get_headers(self) -> typing.Dict[str, str]: headers: typing.Dict[str, str] = { - "User-Agent": "pipedream/1.0.11", + "User-Agent": "pipedream/1.0.12", "X-Fern-Language": "Python", "X-Fern-SDK-Name": "pipedream", - "X-Fern-SDK-Version": "1.0.11", + "X-Fern-SDK-Version": "1.0.12", **(self.get_custom_headers() or {}), } if self._project_environment is not None: diff --git a/src/pipedream/core/pagination.py b/src/pipedream/core/pagination.py index 97bcb64..760b089 100644 --- a/src/pipedream/core/pagination.py +++ b/src/pipedream/core/pagination.py @@ -5,10 +5,10 @@ from dataclasses import dataclass from typing import AsyncIterator, Awaitable, Callable, Generic, Iterator, List, Optional, TypeVar -from .http_response import BaseHttpResponse - # Generic to represent the underlying type of the results within a page T = TypeVar("T") +# Generic to represent the type of the API response +R = TypeVar("R") # SDKs implement a Page ABC per-pagination request, the endpoint then returns a pager that wraps this type @@ -23,11 +23,11 @@ @dataclass(frozen=True) -class SyncPager(Generic[T]): - get_next: Optional[Callable[[], Optional[SyncPager[T]]]] +class SyncPager(Generic[T, R]): + get_next: Optional[Callable[[], Optional[SyncPager[T, R]]]] has_next: bool items: Optional[List[T]] - response: Optional[BaseHttpResponse] + response: R # Here we type ignore the iterator to avoid a mypy error # caused by the type conflict with Pydanitc's __iter__ method @@ -37,8 +37,8 @@ def __iter__(self) -> Iterator[T]: # type: ignore[override] if page.items is not None: yield from page.items - def iter_pages(self) -> Iterator[SyncPager[T]]: - page: Optional[SyncPager[T]] = self + def iter_pages(self) -> Iterator[SyncPager[T, R]]: + page: Optional[SyncPager[T, R]] = self while page is not None: yield page @@ -49,16 +49,16 @@ def iter_pages(self) -> Iterator[SyncPager[T]]: if page is None or page.items is None or len(page.items) == 0: return - def next_page(self) -> Optional[SyncPager[T]]: + def next_page(self) -> Optional[SyncPager[T, R]]: return self.get_next() if self.get_next is not None else None @dataclass(frozen=True) -class AsyncPager(Generic[T]): - get_next: Optional[Callable[[], Awaitable[Optional[AsyncPager[T]]]]] +class AsyncPager(Generic[T, R]): + get_next: Optional[Callable[[], Awaitable[Optional[AsyncPager[T, R]]]]] has_next: bool items: Optional[List[T]] - response: Optional[BaseHttpResponse] + response: R async def __aiter__(self) -> AsyncIterator[T]: async for page in self.iter_pages(): @@ -66,8 +66,8 @@ async def __aiter__(self) -> AsyncIterator[T]: for item in page.items: yield item - async def iter_pages(self) -> AsyncIterator[AsyncPager[T]]: - page: Optional[AsyncPager[T]] = self + async def iter_pages(self) -> AsyncIterator[AsyncPager[T, R]]: + page: Optional[AsyncPager[T, R]] = self while page is not None: yield page @@ -78,5 +78,5 @@ async def iter_pages(self) -> AsyncIterator[AsyncPager[T]]: if page is None or page.items is None or len(page.items) == 0: return - async def next_page(self) -> Optional[AsyncPager[T]]: + async def next_page(self) -> Optional[AsyncPager[T, R]]: return await self.get_next() if self.get_next is not None else None diff --git a/src/pipedream/core/pydantic_utilities.py b/src/pipedream/core/pydantic_utilities.py index 8906cdf..185e5c4 100644 --- a/src/pipedream/core/pydantic_utilities.py +++ b/src/pipedream/core/pydantic_utilities.py @@ -220,7 +220,9 @@ def universal_root_validator( ) -> Callable[[AnyCallable], AnyCallable]: def decorator(func: AnyCallable) -> AnyCallable: if IS_PYDANTIC_V2: - return cast(AnyCallable, pydantic.model_validator(mode="before" if pre else "after")(func)) # type: ignore[attr-defined] + # In Pydantic v2, for RootModel we always use "before" mode + # The custom validators transform the input value before the model is created + return cast(AnyCallable, pydantic.model_validator(mode="before")(func)) # type: ignore[attr-defined] return cast(AnyCallable, pydantic.root_validator(pre=pre)(func)) # type: ignore[call-overload] return decorator diff --git a/src/pipedream/deployed_triggers/client.py b/src/pipedream/deployed_triggers/client.py index ea92f4e..5612c96 100644 --- a/src/pipedream/deployed_triggers/client.py +++ b/src/pipedream/deployed_triggers/client.py @@ -11,6 +11,7 @@ from ..types.emitter_type import EmitterType from ..types.get_trigger_webhooks_response import GetTriggerWebhooksResponse from ..types.get_trigger_workflows_response import GetTriggerWorkflowsResponse +from ..types.get_triggers_response import GetTriggersResponse from .raw_client import AsyncRawDeployedTriggersClient, RawDeployedTriggersClient # this is used as the default value for optional parameters @@ -41,7 +42,7 @@ def list( limit: typing.Optional[int] = None, emitter_type: typing.Optional[EmitterType] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> SyncPager[Emitter]: + ) -> SyncPager[Emitter, GetTriggersResponse]: """ Retrieve all deployed triggers for a specific external user @@ -67,7 +68,7 @@ def list( Returns ------- - SyncPager[Emitter] + SyncPager[Emitter, GetTriggersResponse] deployed triggers listed Examples @@ -81,11 +82,7 @@ def list( client_secret="YOUR_CLIENT_SECRET", ) response = client.deployed_triggers.list( - after="after", - before="before", - limit=1, external_user_id="external_user_id", - emitter_type="email", ) for item in response: yield item @@ -245,7 +242,6 @@ def delete( client.deployed_triggers.delete( trigger_id="trigger_id", external_user_id="external_user_id", - ignore_hook_errors=True, ) """ _response = self._raw_client.delete( @@ -298,7 +294,6 @@ def list_events( client.deployed_triggers.list_events( trigger_id="trigger_id", external_user_id="external_user_id", - n=1, ) """ _response = self._raw_client.list_events( @@ -513,7 +508,7 @@ async def list( limit: typing.Optional[int] = None, emitter_type: typing.Optional[EmitterType] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncPager[Emitter]: + ) -> AsyncPager[Emitter, GetTriggersResponse]: """ Retrieve all deployed triggers for a specific external user @@ -539,7 +534,7 @@ async def list( Returns ------- - AsyncPager[Emitter] + AsyncPager[Emitter, GetTriggersResponse] deployed triggers listed Examples @@ -558,11 +553,7 @@ async def list( async def main() -> None: response = await client.deployed_triggers.list( - after="after", - before="before", - limit=1, external_user_id="external_user_id", - emitter_type="email", ) async for item in response: yield item @@ -747,7 +738,6 @@ async def main() -> None: await client.deployed_triggers.delete( trigger_id="trigger_id", external_user_id="external_user_id", - ignore_hook_errors=True, ) @@ -808,7 +798,6 @@ async def main() -> None: await client.deployed_triggers.list_events( trigger_id="trigger_id", external_user_id="external_user_id", - n=1, ) diff --git a/src/pipedream/deployed_triggers/raw_client.py b/src/pipedream/deployed_triggers/raw_client.py index 4b2e576..bd9de0c 100644 --- a/src/pipedream/deployed_triggers/raw_client.py +++ b/src/pipedream/deployed_triggers/raw_client.py @@ -7,7 +7,7 @@ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.http_response import AsyncHttpResponse, HttpResponse from ..core.jsonable_encoder import jsonable_encoder -from ..core.pagination import AsyncPager, BaseHttpResponse, SyncPager +from ..core.pagination import AsyncPager, SyncPager from ..core.pydantic_utilities import parse_obj_as from ..core.request_options import RequestOptions from ..core.serialization import convert_and_respect_annotation_metadata @@ -39,7 +39,7 @@ def list( limit: typing.Optional[int] = None, emitter_type: typing.Optional[EmitterType] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> SyncPager[Emitter]: + ) -> SyncPager[Emitter, GetTriggersResponse]: """ Retrieve all deployed triggers for a specific external user @@ -65,7 +65,7 @@ def list( Returns ------- - SyncPager[Emitter] + SyncPager[Emitter, GetTriggersResponse] deployed triggers listed """ _response = self._client_wrapper.httpx_client.request( @@ -103,16 +103,14 @@ def list( emitter_type=emitter_type, request_options=request_options, ) - return SyncPager( - has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response) - ) + return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -166,9 +164,9 @@ def retrieve( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -248,9 +246,9 @@ def update( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -304,9 +302,9 @@ def delete( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -369,9 +367,9 @@ def list_events( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -424,9 +422,9 @@ def list_workflows( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -494,9 +492,9 @@ def update_workflows( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -549,9 +547,9 @@ def list_webhooks( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -619,9 +617,9 @@ def update_webhooks( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -645,7 +643,7 @@ async def list( limit: typing.Optional[int] = None, emitter_type: typing.Optional[EmitterType] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncPager[Emitter]: + ) -> AsyncPager[Emitter, GetTriggersResponse]: """ Retrieve all deployed triggers for a specific external user @@ -671,7 +669,7 @@ async def list( Returns ------- - AsyncPager[Emitter] + AsyncPager[Emitter, GetTriggersResponse] deployed triggers listed """ _response = await self._client_wrapper.httpx_client.request( @@ -712,16 +710,14 @@ async def _get_next(): request_options=request_options, ) - return AsyncPager( - has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response) - ) + return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -775,9 +771,9 @@ async def retrieve( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -857,9 +853,9 @@ async def update( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -913,9 +909,9 @@ async def delete( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -978,9 +974,9 @@ async def list_events( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -1033,9 +1029,9 @@ async def list_workflows( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -1103,9 +1099,9 @@ async def update_workflows( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -1158,9 +1154,9 @@ async def list_webhooks( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -1228,9 +1224,9 @@ async def update_webhooks( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), diff --git a/src/pipedream/errors/too_many_requests_error.py b/src/pipedream/errors/too_many_requests_error.py index 2705399..705d6f1 100644 --- a/src/pipedream/errors/too_many_requests_error.py +++ b/src/pipedream/errors/too_many_requests_error.py @@ -6,5 +6,5 @@ class TooManyRequestsError(ApiError): - def __init__(self, body: typing.Optional[typing.Any], headers: typing.Optional[typing.Dict[str, str]] = None): + def __init__(self, body: typing.Any, headers: typing.Optional[typing.Dict[str, str]] = None): super().__init__(status_code=429, headers=headers, body=body) diff --git a/src/pipedream/file_stash/raw_client.py b/src/pipedream/file_stash/raw_client.py index 0a4d576..08c8725 100644 --- a/src/pipedream/file_stash/raw_client.py +++ b/src/pipedream/file_stash/raw_client.py @@ -57,9 +57,9 @@ def _stream() -> HttpResponse[typing.Iterator[bytes]]: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -119,9 +119,9 @@ async def _stream() -> AsyncHttpResponse[typing.AsyncIterator[bytes]]: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), diff --git a/src/pipedream/projects/raw_client.py b/src/pipedream/projects/raw_client.py index 54d4b1c..0f0ea4f 100644 --- a/src/pipedream/projects/raw_client.py +++ b/src/pipedream/projects/raw_client.py @@ -52,9 +52,9 @@ def retrieve_info( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -104,9 +104,9 @@ async def retrieve_info( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), diff --git a/src/pipedream/proxy/raw_client.py b/src/pipedream/proxy/raw_client.py index 6825954..932f049 100644 --- a/src/pipedream/proxy/raw_client.py +++ b/src/pipedream/proxy/raw_client.py @@ -1,5 +1,6 @@ # This file was auto-generated by Fern from our API Definition. +import contextlib import typing from json.decoder import JSONDecodeError @@ -10,7 +11,6 @@ from ..core.pydantic_utilities import parse_obj_as from ..core.request_options import RequestOptions from ..errors.too_many_requests_error import TooManyRequestsError -from ..types.proxy_response import ProxyResponse # this is used as the default value for optional parameters OMIT = typing.cast(typing.Any, ...) @@ -20,6 +20,7 @@ class RawProxyClient: def __init__(self, *, client_wrapper: SyncClientWrapper): self._client_wrapper = client_wrapper + @contextlib.contextmanager def get( self, url_64: str, @@ -27,7 +28,7 @@ def get( external_user_id: str, account_id: str, request_options: typing.Optional[RequestOptions] = None, - ) -> HttpResponse[ProxyResponse]: + ) -> typing.Iterator[HttpResponse[typing.Iterator[bytes]]]: """ Forward an authenticated GET request to an external API using an external user's account credentials @@ -43,14 +44,14 @@ def get( The account ID to use for authentication request_options : typing.Optional[RequestOptions] - Request-specific configuration. + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. Returns ------- - HttpResponse[ProxyResponse] + typing.Iterator[HttpResponse[typing.Iterator[bytes]]] proxy request successful """ - _response = self._client_wrapper.httpx_client.request( + with self._client_wrapper.httpx_client.stream( f"v1/connect/{jsonable_encoder(self._client_wrapper._project_id)}/proxy/{jsonable_encoder(url_64)}", method="GET", params={ @@ -58,44 +59,46 @@ def get( "account_id": account_id, }, request_options=request_options, - ) - try: - if _response is None or not _response.text.strip(): - return HttpResponse(response=_response, data=None) - if 200 <= _response.status_code < 300: - _data = typing.cast( - ProxyResponse, - parse_obj_as( - type_=ProxyResponse, # type: ignore - object_=_response.json(), - ), - ) - return HttpResponse(response=_response, data=_data) - if _response.status_code == 429: - raise TooManyRequestsError( - headers=dict(_response.headers), - body=typing.cast( - typing.Optional[typing.Any], - parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore - object_=_response.json(), - ), - ), - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) - + ) as _response: + + def _stream() -> HttpResponse[typing.Iterator[bytes]]: + try: + if 200 <= _response.status_code < 300: + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None + return HttpResponse( + response=_response, data=(_chunk for _chunk in _response.iter_bytes(chunk_size=_chunk_size)) + ) + _response.read() + if _response.status_code == 429: + raise TooManyRequestsError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + + yield _stream() + + @contextlib.contextmanager def post( self, url_64: str, *, external_user_id: str, account_id: str, - request: typing.Dict[str, typing.Optional[typing.Any]], + request: typing.Dict[str, typing.Any], request_options: typing.Optional[RequestOptions] = None, - ) -> HttpResponse[ProxyResponse]: + ) -> typing.Iterator[HttpResponse[typing.Iterator[bytes]]]: """ Forward an authenticated POST request to an external API using an external user's account credentials @@ -110,17 +113,17 @@ def post( account_id : str The account ID to use for authentication - request : typing.Dict[str, typing.Optional[typing.Any]] + request : typing.Dict[str, typing.Any] request_options : typing.Optional[RequestOptions] - Request-specific configuration. + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. Returns ------- - HttpResponse[ProxyResponse] + typing.Iterator[HttpResponse[typing.Iterator[bytes]]] proxy request successful """ - _response = self._client_wrapper.httpx_client.request( + with self._client_wrapper.httpx_client.stream( f"v1/connect/{jsonable_encoder(self._client_wrapper._project_id)}/proxy/{jsonable_encoder(url_64)}", method="POST", params={ @@ -133,44 +136,46 @@ def post( }, request_options=request_options, omit=OMIT, - ) - try: - if _response is None or not _response.text.strip(): - return HttpResponse(response=_response, data=None) - if 200 <= _response.status_code < 300: - _data = typing.cast( - ProxyResponse, - parse_obj_as( - type_=ProxyResponse, # type: ignore - object_=_response.json(), - ), - ) - return HttpResponse(response=_response, data=_data) - if _response.status_code == 429: - raise TooManyRequestsError( - headers=dict(_response.headers), - body=typing.cast( - typing.Optional[typing.Any], - parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore - object_=_response.json(), - ), - ), - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) - + ) as _response: + + def _stream() -> HttpResponse[typing.Iterator[bytes]]: + try: + if 200 <= _response.status_code < 300: + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None + return HttpResponse( + response=_response, data=(_chunk for _chunk in _response.iter_bytes(chunk_size=_chunk_size)) + ) + _response.read() + if _response.status_code == 429: + raise TooManyRequestsError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + + yield _stream() + + @contextlib.contextmanager def put( self, url_64: str, *, external_user_id: str, account_id: str, - request: typing.Dict[str, typing.Optional[typing.Any]], + request: typing.Dict[str, typing.Any], request_options: typing.Optional[RequestOptions] = None, - ) -> HttpResponse[ProxyResponse]: + ) -> typing.Iterator[HttpResponse[typing.Iterator[bytes]]]: """ Forward an authenticated PUT request to an external API using an external user's account credentials @@ -185,17 +190,17 @@ def put( account_id : str The account ID to use for authentication - request : typing.Dict[str, typing.Optional[typing.Any]] + request : typing.Dict[str, typing.Any] request_options : typing.Optional[RequestOptions] - Request-specific configuration. + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. Returns ------- - HttpResponse[ProxyResponse] + typing.Iterator[HttpResponse[typing.Iterator[bytes]]] proxy request successful """ - _response = self._client_wrapper.httpx_client.request( + with self._client_wrapper.httpx_client.stream( f"v1/connect/{jsonable_encoder(self._client_wrapper._project_id)}/proxy/{jsonable_encoder(url_64)}", method="PUT", params={ @@ -208,35 +213,37 @@ def put( }, request_options=request_options, omit=OMIT, - ) - try: - if _response is None or not _response.text.strip(): - return HttpResponse(response=_response, data=None) - if 200 <= _response.status_code < 300: - _data = typing.cast( - ProxyResponse, - parse_obj_as( - type_=ProxyResponse, # type: ignore - object_=_response.json(), - ), - ) - return HttpResponse(response=_response, data=_data) - if _response.status_code == 429: - raise TooManyRequestsError( - headers=dict(_response.headers), - body=typing.cast( - typing.Optional[typing.Any], - parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore - object_=_response.json(), - ), - ), - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) - + ) as _response: + + def _stream() -> HttpResponse[typing.Iterator[bytes]]: + try: + if 200 <= _response.status_code < 300: + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None + return HttpResponse( + response=_response, data=(_chunk for _chunk in _response.iter_bytes(chunk_size=_chunk_size)) + ) + _response.read() + if _response.status_code == 429: + raise TooManyRequestsError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + + yield _stream() + + @contextlib.contextmanager def delete( self, url_64: str, @@ -244,7 +251,7 @@ def delete( external_user_id: str, account_id: str, request_options: typing.Optional[RequestOptions] = None, - ) -> HttpResponse[ProxyResponse]: + ) -> typing.Iterator[HttpResponse[typing.Iterator[bytes]]]: """ Forward an authenticated DELETE request to an external API using an external user's account credentials @@ -260,14 +267,14 @@ def delete( The account ID to use for authentication request_options : typing.Optional[RequestOptions] - Request-specific configuration. + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. Returns ------- - HttpResponse[ProxyResponse] + typing.Iterator[HttpResponse[typing.Iterator[bytes]]] proxy request successful """ - _response = self._client_wrapper.httpx_client.request( + with self._client_wrapper.httpx_client.stream( f"v1/connect/{jsonable_encoder(self._client_wrapper._project_id)}/proxy/{jsonable_encoder(url_64)}", method="DELETE", params={ @@ -275,44 +282,46 @@ def delete( "account_id": account_id, }, request_options=request_options, - ) - try: - if _response is None or not _response.text.strip(): - return HttpResponse(response=_response, data=None) - if 200 <= _response.status_code < 300: - _data = typing.cast( - ProxyResponse, - parse_obj_as( - type_=ProxyResponse, # type: ignore - object_=_response.json(), - ), - ) - return HttpResponse(response=_response, data=_data) - if _response.status_code == 429: - raise TooManyRequestsError( - headers=dict(_response.headers), - body=typing.cast( - typing.Optional[typing.Any], - parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore - object_=_response.json(), - ), - ), - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) - + ) as _response: + + def _stream() -> HttpResponse[typing.Iterator[bytes]]: + try: + if 200 <= _response.status_code < 300: + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None + return HttpResponse( + response=_response, data=(_chunk for _chunk in _response.iter_bytes(chunk_size=_chunk_size)) + ) + _response.read() + if _response.status_code == 429: + raise TooManyRequestsError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + + yield _stream() + + @contextlib.contextmanager def patch( self, url_64: str, *, external_user_id: str, account_id: str, - request: typing.Dict[str, typing.Optional[typing.Any]], + request: typing.Dict[str, typing.Any], request_options: typing.Optional[RequestOptions] = None, - ) -> HttpResponse[ProxyResponse]: + ) -> typing.Iterator[HttpResponse[typing.Iterator[bytes]]]: """ Forward an authenticated PATCH request to an external API using an external user's account credentials @@ -327,17 +336,17 @@ def patch( account_id : str The account ID to use for authentication - request : typing.Dict[str, typing.Optional[typing.Any]] + request : typing.Dict[str, typing.Any] request_options : typing.Optional[RequestOptions] - Request-specific configuration. + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. Returns ------- - HttpResponse[ProxyResponse] + typing.Iterator[HttpResponse[typing.Iterator[bytes]]] proxy request successful """ - _response = self._client_wrapper.httpx_client.request( + with self._client_wrapper.httpx_client.stream( f"v1/connect/{jsonable_encoder(self._client_wrapper._project_id)}/proxy/{jsonable_encoder(url_64)}", method="PATCH", params={ @@ -350,40 +359,42 @@ def patch( }, request_options=request_options, omit=OMIT, - ) - try: - if _response is None or not _response.text.strip(): - return HttpResponse(response=_response, data=None) - if 200 <= _response.status_code < 300: - _data = typing.cast( - ProxyResponse, - parse_obj_as( - type_=ProxyResponse, # type: ignore - object_=_response.json(), - ), - ) - return HttpResponse(response=_response, data=_data) - if _response.status_code == 429: - raise TooManyRequestsError( - headers=dict(_response.headers), - body=typing.cast( - typing.Optional[typing.Any], - parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore - object_=_response.json(), - ), - ), - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + ) as _response: + + def _stream() -> HttpResponse[typing.Iterator[bytes]]: + try: + if 200 <= _response.status_code < 300: + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None + return HttpResponse( + response=_response, data=(_chunk for _chunk in _response.iter_bytes(chunk_size=_chunk_size)) + ) + _response.read() + if _response.status_code == 429: + raise TooManyRequestsError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + + yield _stream() class AsyncRawProxyClient: def __init__(self, *, client_wrapper: AsyncClientWrapper): self._client_wrapper = client_wrapper + @contextlib.asynccontextmanager async def get( self, url_64: str, @@ -391,7 +402,7 @@ async def get( external_user_id: str, account_id: str, request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncHttpResponse[ProxyResponse]: + ) -> typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]]: """ Forward an authenticated GET request to an external API using an external user's account credentials @@ -407,14 +418,14 @@ async def get( The account ID to use for authentication request_options : typing.Optional[RequestOptions] - Request-specific configuration. + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. Returns ------- - AsyncHttpResponse[ProxyResponse] + typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]] proxy request successful """ - _response = await self._client_wrapper.httpx_client.request( + async with self._client_wrapper.httpx_client.stream( f"v1/connect/{jsonable_encoder(self._client_wrapper._project_id)}/proxy/{jsonable_encoder(url_64)}", method="GET", params={ @@ -422,44 +433,47 @@ async def get( "account_id": account_id, }, request_options=request_options, - ) - try: - if _response is None or not _response.text.strip(): - return AsyncHttpResponse(response=_response, data=None) - if 200 <= _response.status_code < 300: - _data = typing.cast( - ProxyResponse, - parse_obj_as( - type_=ProxyResponse, # type: ignore - object_=_response.json(), - ), - ) - return AsyncHttpResponse(response=_response, data=_data) - if _response.status_code == 429: - raise TooManyRequestsError( - headers=dict(_response.headers), - body=typing.cast( - typing.Optional[typing.Any], - parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore - object_=_response.json(), - ), - ), - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) - + ) as _response: + + async def _stream() -> AsyncHttpResponse[typing.AsyncIterator[bytes]]: + try: + if 200 <= _response.status_code < 300: + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None + return AsyncHttpResponse( + response=_response, + data=(_chunk async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size)), + ) + await _response.aread() + if _response.status_code == 429: + raise TooManyRequestsError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + + yield await _stream() + + @contextlib.asynccontextmanager async def post( self, url_64: str, *, external_user_id: str, account_id: str, - request: typing.Dict[str, typing.Optional[typing.Any]], + request: typing.Dict[str, typing.Any], request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncHttpResponse[ProxyResponse]: + ) -> typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]]: """ Forward an authenticated POST request to an external API using an external user's account credentials @@ -474,17 +488,17 @@ async def post( account_id : str The account ID to use for authentication - request : typing.Dict[str, typing.Optional[typing.Any]] + request : typing.Dict[str, typing.Any] request_options : typing.Optional[RequestOptions] - Request-specific configuration. + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. Returns ------- - AsyncHttpResponse[ProxyResponse] + typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]] proxy request successful """ - _response = await self._client_wrapper.httpx_client.request( + async with self._client_wrapper.httpx_client.stream( f"v1/connect/{jsonable_encoder(self._client_wrapper._project_id)}/proxy/{jsonable_encoder(url_64)}", method="POST", params={ @@ -497,44 +511,47 @@ async def post( }, request_options=request_options, omit=OMIT, - ) - try: - if _response is None or not _response.text.strip(): - return AsyncHttpResponse(response=_response, data=None) - if 200 <= _response.status_code < 300: - _data = typing.cast( - ProxyResponse, - parse_obj_as( - type_=ProxyResponse, # type: ignore - object_=_response.json(), - ), - ) - return AsyncHttpResponse(response=_response, data=_data) - if _response.status_code == 429: - raise TooManyRequestsError( - headers=dict(_response.headers), - body=typing.cast( - typing.Optional[typing.Any], - parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore - object_=_response.json(), - ), - ), - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) - + ) as _response: + + async def _stream() -> AsyncHttpResponse[typing.AsyncIterator[bytes]]: + try: + if 200 <= _response.status_code < 300: + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None + return AsyncHttpResponse( + response=_response, + data=(_chunk async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size)), + ) + await _response.aread() + if _response.status_code == 429: + raise TooManyRequestsError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + + yield await _stream() + + @contextlib.asynccontextmanager async def put( self, url_64: str, *, external_user_id: str, account_id: str, - request: typing.Dict[str, typing.Optional[typing.Any]], + request: typing.Dict[str, typing.Any], request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncHttpResponse[ProxyResponse]: + ) -> typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]]: """ Forward an authenticated PUT request to an external API using an external user's account credentials @@ -549,17 +566,17 @@ async def put( account_id : str The account ID to use for authentication - request : typing.Dict[str, typing.Optional[typing.Any]] + request : typing.Dict[str, typing.Any] request_options : typing.Optional[RequestOptions] - Request-specific configuration. + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. Returns ------- - AsyncHttpResponse[ProxyResponse] + typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]] proxy request successful """ - _response = await self._client_wrapper.httpx_client.request( + async with self._client_wrapper.httpx_client.stream( f"v1/connect/{jsonable_encoder(self._client_wrapper._project_id)}/proxy/{jsonable_encoder(url_64)}", method="PUT", params={ @@ -572,35 +589,38 @@ async def put( }, request_options=request_options, omit=OMIT, - ) - try: - if _response is None or not _response.text.strip(): - return AsyncHttpResponse(response=_response, data=None) - if 200 <= _response.status_code < 300: - _data = typing.cast( - ProxyResponse, - parse_obj_as( - type_=ProxyResponse, # type: ignore - object_=_response.json(), - ), - ) - return AsyncHttpResponse(response=_response, data=_data) - if _response.status_code == 429: - raise TooManyRequestsError( - headers=dict(_response.headers), - body=typing.cast( - typing.Optional[typing.Any], - parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore - object_=_response.json(), - ), - ), - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) - + ) as _response: + + async def _stream() -> AsyncHttpResponse[typing.AsyncIterator[bytes]]: + try: + if 200 <= _response.status_code < 300: + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None + return AsyncHttpResponse( + response=_response, + data=(_chunk async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size)), + ) + await _response.aread() + if _response.status_code == 429: + raise TooManyRequestsError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + + yield await _stream() + + @contextlib.asynccontextmanager async def delete( self, url_64: str, @@ -608,7 +628,7 @@ async def delete( external_user_id: str, account_id: str, request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncHttpResponse[ProxyResponse]: + ) -> typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]]: """ Forward an authenticated DELETE request to an external API using an external user's account credentials @@ -624,14 +644,14 @@ async def delete( The account ID to use for authentication request_options : typing.Optional[RequestOptions] - Request-specific configuration. + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. Returns ------- - AsyncHttpResponse[ProxyResponse] + typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]] proxy request successful """ - _response = await self._client_wrapper.httpx_client.request( + async with self._client_wrapper.httpx_client.stream( f"v1/connect/{jsonable_encoder(self._client_wrapper._project_id)}/proxy/{jsonable_encoder(url_64)}", method="DELETE", params={ @@ -639,44 +659,47 @@ async def delete( "account_id": account_id, }, request_options=request_options, - ) - try: - if _response is None or not _response.text.strip(): - return AsyncHttpResponse(response=_response, data=None) - if 200 <= _response.status_code < 300: - _data = typing.cast( - ProxyResponse, - parse_obj_as( - type_=ProxyResponse, # type: ignore - object_=_response.json(), - ), - ) - return AsyncHttpResponse(response=_response, data=_data) - if _response.status_code == 429: - raise TooManyRequestsError( - headers=dict(_response.headers), - body=typing.cast( - typing.Optional[typing.Any], - parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore - object_=_response.json(), - ), - ), - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) - + ) as _response: + + async def _stream() -> AsyncHttpResponse[typing.AsyncIterator[bytes]]: + try: + if 200 <= _response.status_code < 300: + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None + return AsyncHttpResponse( + response=_response, + data=(_chunk async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size)), + ) + await _response.aread() + if _response.status_code == 429: + raise TooManyRequestsError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + + yield await _stream() + + @contextlib.asynccontextmanager async def patch( self, url_64: str, *, external_user_id: str, account_id: str, - request: typing.Dict[str, typing.Optional[typing.Any]], + request: typing.Dict[str, typing.Any], request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncHttpResponse[ProxyResponse]: + ) -> typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]]: """ Forward an authenticated PATCH request to an external API using an external user's account credentials @@ -691,17 +714,17 @@ async def patch( account_id : str The account ID to use for authentication - request : typing.Dict[str, typing.Optional[typing.Any]] + request : typing.Dict[str, typing.Any] request_options : typing.Optional[RequestOptions] - Request-specific configuration. + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. Returns ------- - AsyncHttpResponse[ProxyResponse] + typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]] proxy request successful """ - _response = await self._client_wrapper.httpx_client.request( + async with self._client_wrapper.httpx_client.stream( f"v1/connect/{jsonable_encoder(self._client_wrapper._project_id)}/proxy/{jsonable_encoder(url_64)}", method="PATCH", params={ @@ -714,31 +737,33 @@ async def patch( }, request_options=request_options, omit=OMIT, - ) - try: - if _response is None or not _response.text.strip(): - return AsyncHttpResponse(response=_response, data=None) - if 200 <= _response.status_code < 300: - _data = typing.cast( - ProxyResponse, - parse_obj_as( - type_=ProxyResponse, # type: ignore - object_=_response.json(), - ), - ) - return AsyncHttpResponse(response=_response, data=_data) - if _response.status_code == 429: - raise TooManyRequestsError( - headers=dict(_response.headers), - body=typing.cast( - typing.Optional[typing.Any], - parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore - object_=_response.json(), - ), - ), - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) - raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + ) as _response: + + async def _stream() -> AsyncHttpResponse[typing.AsyncIterator[bytes]]: + try: + if 200 <= _response.status_code < 300: + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None + return AsyncHttpResponse( + response=_response, + data=(_chunk async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size)), + ) + await _response.aread() + if _response.status_code == 429: + raise TooManyRequestsError( + headers=dict(_response.headers), + body=typing.cast( + typing.Any, + parse_obj_as( + type_=typing.Any, # type: ignore + object_=_response.json(), + ), + ), + ) + _response_json = _response.json() + except JSONDecodeError: + raise ApiError( + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text + ) + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) + + yield await _stream() diff --git a/src/pipedream/tokens/client.py b/src/pipedream/tokens/client.py index f37eccf..cbe1c64 100644 --- a/src/pipedream/tokens/client.py +++ b/src/pipedream/tokens/client.py @@ -132,7 +132,6 @@ def validate( client.tokens.validate( ctok="ctok", app_id="app_id", - oauth_app_id="oauth_app_id", ) """ _response = self._raw_client.validate( @@ -273,7 +272,6 @@ async def main() -> None: await client.tokens.validate( ctok="ctok", app_id="app_id", - oauth_app_id="oauth_app_id", ) diff --git a/src/pipedream/tokens/raw_client.py b/src/pipedream/tokens/raw_client.py index 4370714..ff14f04 100644 --- a/src/pipedream/tokens/raw_client.py +++ b/src/pipedream/tokens/raw_client.py @@ -90,9 +90,9 @@ def create( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -154,9 +154,9 @@ def validate( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -239,9 +239,9 @@ async def create( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -303,9 +303,9 @@ async def validate( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), diff --git a/src/pipedream/triggers/client.py b/src/pipedream/triggers/client.py index 85a6646..0dbbece 100644 --- a/src/pipedream/triggers/client.py +++ b/src/pipedream/triggers/client.py @@ -9,6 +9,7 @@ from ..types.configure_prop_response import ConfigurePropResponse from ..types.configured_props import ConfiguredProps from ..types.emitter import Emitter +from ..types.get_components_response import GetComponentsResponse from ..types.reload_props_response import ReloadPropsResponse from .raw_client import AsyncRawTriggersClient, RawTriggersClient @@ -40,7 +41,7 @@ def list( q: typing.Optional[str] = None, app: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> SyncPager[Component]: + ) -> SyncPager[Component, GetComponentsResponse]: """ Retrieve available triggers with optional search and app filtering @@ -66,7 +67,7 @@ def list( Returns ------- - SyncPager[Component] + SyncPager[Component, GetComponentsResponse] triggers listed Examples @@ -79,13 +80,7 @@ def list( client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", ) - response = client.triggers.list( - after="after", - before="before", - limit=1, - q="q", - app="app", - ) + response = client.triggers.list() for item in response: yield item # alternatively, you can paginate page-by-page @@ -151,7 +146,7 @@ def configure_prop( configured_props: typing.Optional[ConfiguredProps] = OMIT, dynamic_props_id: typing.Optional[str] = OMIT, page: typing.Optional[float] = OMIT, - prev_context: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT, + prev_context: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, query: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> ConfigurePropResponse: @@ -183,7 +178,7 @@ def configure_prop( page : typing.Optional[float] Page number for paginated results - prev_context : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] + prev_context : typing.Optional[typing.Dict[str, typing.Any]] Previous context for pagination query : typing.Optional[str] @@ -392,7 +387,7 @@ async def list( q: typing.Optional[str] = None, app: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncPager[Component]: + ) -> AsyncPager[Component, GetComponentsResponse]: """ Retrieve available triggers with optional search and app filtering @@ -418,7 +413,7 @@ async def list( Returns ------- - AsyncPager[Component] + AsyncPager[Component, GetComponentsResponse] triggers listed Examples @@ -436,13 +431,7 @@ async def list( async def main() -> None: - response = await client.triggers.list( - after="after", - before="before", - limit=1, - q="q", - app="app", - ) + response = await client.triggers.list() async for item in response: yield item @@ -520,7 +509,7 @@ async def configure_prop( configured_props: typing.Optional[ConfiguredProps] = OMIT, dynamic_props_id: typing.Optional[str] = OMIT, page: typing.Optional[float] = OMIT, - prev_context: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT, + prev_context: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, query: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> ConfigurePropResponse: @@ -552,7 +541,7 @@ async def configure_prop( page : typing.Optional[float] Page number for paginated results - prev_context : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] + prev_context : typing.Optional[typing.Dict[str, typing.Any]] Previous context for pagination query : typing.Optional[str] diff --git a/src/pipedream/triggers/raw_client.py b/src/pipedream/triggers/raw_client.py index 0d5da95..a1a0831 100644 --- a/src/pipedream/triggers/raw_client.py +++ b/src/pipedream/triggers/raw_client.py @@ -7,7 +7,7 @@ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.http_response import AsyncHttpResponse, HttpResponse from ..core.jsonable_encoder import jsonable_encoder -from ..core.pagination import AsyncPager, BaseHttpResponse, SyncPager +from ..core.pagination import AsyncPager, SyncPager from ..core.pydantic_utilities import parse_obj_as from ..core.request_options import RequestOptions from ..core.serialization import convert_and_respect_annotation_metadata @@ -38,7 +38,7 @@ def list( q: typing.Optional[str] = None, app: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> SyncPager[Component]: + ) -> SyncPager[Component, GetComponentsResponse]: """ Retrieve available triggers with optional search and app filtering @@ -64,7 +64,7 @@ def list( Returns ------- - SyncPager[Component] + SyncPager[Component, GetComponentsResponse] triggers listed """ _response = self._client_wrapper.httpx_client.request( @@ -102,16 +102,14 @@ def list( app=app, request_options=request_options, ) - return SyncPager( - has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response) - ) + return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -170,9 +168,9 @@ def retrieve( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -193,7 +191,7 @@ def configure_prop( configured_props: typing.Optional[ConfiguredProps] = OMIT, dynamic_props_id: typing.Optional[str] = OMIT, page: typing.Optional[float] = OMIT, - prev_context: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT, + prev_context: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, query: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> HttpResponse[ConfigurePropResponse]: @@ -225,7 +223,7 @@ def configure_prop( page : typing.Optional[float] Page number for paginated results - prev_context : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] + prev_context : typing.Optional[typing.Dict[str, typing.Any]] Previous context for pagination query : typing.Optional[str] @@ -276,9 +274,9 @@ def configure_prop( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -362,9 +360,9 @@ def reload_props( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -454,9 +452,9 @@ def deploy( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -480,7 +478,7 @@ async def list( q: typing.Optional[str] = None, app: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None, - ) -> AsyncPager[Component]: + ) -> AsyncPager[Component, GetComponentsResponse]: """ Retrieve available triggers with optional search and app filtering @@ -506,7 +504,7 @@ async def list( Returns ------- - AsyncPager[Component] + AsyncPager[Component, GetComponentsResponse] triggers listed """ _response = await self._client_wrapper.httpx_client.request( @@ -547,16 +545,14 @@ async def _get_next(): request_options=request_options, ) - return AsyncPager( - has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response) - ) + return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response) if _response.status_code == 429: raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -615,9 +611,9 @@ async def retrieve( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -638,7 +634,7 @@ async def configure_prop( configured_props: typing.Optional[ConfiguredProps] = OMIT, dynamic_props_id: typing.Optional[str] = OMIT, page: typing.Optional[float] = OMIT, - prev_context: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT, + prev_context: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, query: typing.Optional[str] = OMIT, request_options: typing.Optional[RequestOptions] = None, ) -> AsyncHttpResponse[ConfigurePropResponse]: @@ -670,7 +666,7 @@ async def configure_prop( page : typing.Optional[float] Page number for paginated results - prev_context : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] + prev_context : typing.Optional[typing.Dict[str, typing.Any]] Previous context for pagination query : typing.Optional[str] @@ -721,9 +717,9 @@ async def configure_prop( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -807,9 +803,9 @@ async def reload_props( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -899,9 +895,9 @@ async def deploy( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), diff --git a/src/pipedream/types/__init__.py b/src/pipedream/types/__init__.py index 1484a49..6063ee7 100644 --- a/src/pipedream/types/__init__.py +++ b/src/pipedream/types/__init__.py @@ -102,6 +102,7 @@ from .prop_option_nested import PropOptionNested from .prop_option_value import PropOptionValue from .proxy_response import ProxyResponse + from .proxy_response_binary import ProxyResponseBinary from .reload_props_opts import ReloadPropsOpts from .reload_props_response import ReloadPropsResponse from .run_action_opts_stash_id import RunActionOptsStashId @@ -214,6 +215,7 @@ "PropOptionNested": ".prop_option_nested", "PropOptionValue": ".prop_option_value", "ProxyResponse": ".proxy_response", + "ProxyResponseBinary": ".proxy_response_binary", "ReloadPropsOpts": ".reload_props_opts", "ReloadPropsResponse": ".reload_props_response", "RunActionOptsStashId": ".run_action_opts_stash_id", @@ -350,6 +352,7 @@ def __dir__(): "PropOptionNested", "PropOptionValue", "ProxyResponse", + "ProxyResponseBinary", "ReloadPropsOpts", "ReloadPropsResponse", "RunActionOptsStashId", diff --git a/src/pipedream/types/account.py b/src/pipedream/types/account.py index 2627d08..ee8e428 100644 --- a/src/pipedream/types/account.py +++ b/src/pipedream/types/account.py @@ -46,7 +46,7 @@ class Account(UniversalBaseModel): The date and time the account was last updated, an ISO 8601 formatted string """ - credentials: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = pydantic.Field(default=None) + credentials: typing.Optional[typing.Dict[str, typing.Any]] = pydantic.Field(default=None) """ The credentials associated with the account, if the `include_credentials` parameter was set to true in the request """ diff --git a/src/pipedream/types/configurable_prop_apphook.py b/src/pipedream/types/configurable_prop_apphook.py index a2688c2..a6651a2 100644 --- a/src/pipedream/types/configurable_prop_apphook.py +++ b/src/pipedream/types/configurable_prop_apphook.py @@ -27,7 +27,7 @@ class ConfigurablePropApphook(UniversalBaseModel): Whether this apphook is remote """ - static: typing.Optional[typing.List[typing.Optional[typing.Any]]] = pydantic.Field(default=None) + static: typing.Optional[typing.List[typing.Any]] = pydantic.Field(default=None) """ Static configuration for the apphook """ diff --git a/src/pipedream/types/configure_prop_opts.py b/src/pipedream/types/configure_prop_opts.py index bee3f7c..1712ac7 100644 --- a/src/pipedream/types/configure_prop_opts.py +++ b/src/pipedream/types/configure_prop_opts.py @@ -48,7 +48,7 @@ class ConfigurePropOpts(UniversalBaseModel): Page number for paginated results """ - prev_context: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = pydantic.Field(default=None) + prev_context: typing.Optional[typing.Dict[str, typing.Any]] = pydantic.Field(default=None) """ Previous context for pagination """ diff --git a/src/pipedream/types/configure_prop_response.py b/src/pipedream/types/configure_prop_response.py index 188645d..7bb1134 100644 --- a/src/pipedream/types/configure_prop_response.py +++ b/src/pipedream/types/configure_prop_response.py @@ -20,7 +20,7 @@ class ConfigurePropResponse(UniversalBaseModel): """ observations: typing.Optional[typing.List[Observation]] = None - context: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = pydantic.Field(default=None) + context: typing.Optional[typing.Dict[str, typing.Any]] = pydantic.Field(default=None) """ New context after configuring the prop """ diff --git a/src/pipedream/types/configured_prop_value_any.py b/src/pipedream/types/configured_prop_value_any.py index 98361e0..180403c 100644 --- a/src/pipedream/types/configured_prop_value_any.py +++ b/src/pipedream/types/configured_prop_value_any.py @@ -2,4 +2,4 @@ import typing -ConfiguredPropValueAny = typing.Optional[typing.Any] +ConfiguredPropValueAny = typing.Any diff --git a/src/pipedream/types/configured_prop_value_object.py b/src/pipedream/types/configured_prop_value_object.py index 3cab1eb..b77485b 100644 --- a/src/pipedream/types/configured_prop_value_object.py +++ b/src/pipedream/types/configured_prop_value_object.py @@ -2,4 +2,4 @@ import typing -ConfiguredPropValueObject = typing.Dict[str, typing.Optional[typing.Any]] +ConfiguredPropValueObject = typing.Dict[str, typing.Any] diff --git a/src/pipedream/types/deployed_component.py b/src/pipedream/types/deployed_component.py index 39ba6c2..4c17d84 100644 --- a/src/pipedream/types/deployed_component.py +++ b/src/pipedream/types/deployed_component.py @@ -64,7 +64,7 @@ class DeployedComponent(UniversalBaseModel): The name slug of the deployed component """ - callback_observations: typing.Optional[typing.Optional[typing.Any]] = pydantic.Field(default=None) + callback_observations: typing.Optional[typing.Any] = pydantic.Field(default=None) """ Callback observations for the deployed component """ diff --git a/src/pipedream/types/emitted_event.py b/src/pipedream/types/emitted_event.py index 633bbeb..0ce4f3d 100644 --- a/src/pipedream/types/emitted_event.py +++ b/src/pipedream/types/emitted_event.py @@ -11,7 +11,7 @@ class EmittedEvent(UniversalBaseModel): An event emitted by a trigger """ - e: typing.Dict[str, typing.Optional[typing.Any]] = pydantic.Field() + e: typing.Dict[str, typing.Any] = pydantic.Field() """ The event's payload """ diff --git a/src/pipedream/types/emitter.py b/src/pipedream/types/emitter.py index cd4962f..4dda01c 100644 --- a/src/pipedream/types/emitter.py +++ b/src/pipedream/types/emitter.py @@ -5,6 +5,7 @@ import typing import pydantic +import typing_extensions from ..core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel from .configurable_prop import ConfigurableProp from .configured_props import ConfiguredProps @@ -27,7 +28,7 @@ class Emitter_DeployedComponent(UniversalBaseModel): updated_at: int name: str name_slug: str - callback_observations: typing.Optional[typing.Optional[typing.Any]] = None + callback_observations: typing.Optional[typing.Any] = None if IS_PYDANTIC_V2: model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 @@ -86,4 +87,7 @@ class Config: extra = pydantic.Extra.allow -Emitter = typing.Union[Emitter_DeployedComponent, Emitter_HttpInterface, Emitter_TimerInterface] +Emitter = typing_extensions.Annotated[ + typing.Union[Emitter_DeployedComponent, Emitter_HttpInterface, Emitter_TimerInterface], + pydantic.Field(discriminator="type"), +] diff --git a/src/pipedream/types/error_response.py b/src/pipedream/types/error_response.py index ce5a708..62e35d4 100644 --- a/src/pipedream/types/error_response.py +++ b/src/pipedream/types/error_response.py @@ -21,7 +21,7 @@ class ErrorResponse(UniversalBaseModel): The error code """ - details: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = pydantic.Field(default=None) + details: typing.Optional[typing.Dict[str, typing.Any]] = pydantic.Field(default=None) """ Additional error details """ diff --git a/src/pipedream/types/proxy_response.py b/src/pipedream/types/proxy_response.py index 902ac7d..6d7a139 100644 --- a/src/pipedream/types/proxy_response.py +++ b/src/pipedream/types/proxy_response.py @@ -2,4 +2,4 @@ import typing -ProxyResponse = typing.Optional[typing.Any] +ProxyResponse = typing.Any diff --git a/src/pipedream/types/proxy_response_binary.py b/src/pipedream/types/proxy_response_binary.py new file mode 100644 index 0000000..e799429 --- /dev/null +++ b/src/pipedream/types/proxy_response_binary.py @@ -0,0 +1,3 @@ +# This file was auto-generated by Fern from our API Definition. + +ProxyResponseBinary = str diff --git a/src/pipedream/types/run_action_response.py b/src/pipedream/types/run_action_response.py index e223088..844175f 100644 --- a/src/pipedream/types/run_action_response.py +++ b/src/pipedream/types/run_action_response.py @@ -12,17 +12,17 @@ class RunActionResponse(UniversalBaseModel): The response received after running an action. See https://pipedream.com/docs/components/api#returning-data-from-steps for more details. """ - exports: typing.Optional[typing.Optional[typing.Any]] = pydantic.Field(default=None) + exports: typing.Optional[typing.Any] = pydantic.Field(default=None) """ The key-value pairs resulting from calls to `$.export` """ - os: typing.Optional[typing.Optional[typing.Any]] = pydantic.Field(default=None) + os: typing.Optional[typing.Any] = pydantic.Field(default=None) """ Any logs produced during the execution of the action """ - ret: typing.Optional[typing.Optional[typing.Any]] = pydantic.Field(default=None) + ret: typing.Optional[typing.Any] = pydantic.Field(default=None) """ The value returned by the action """ diff --git a/src/pipedream/users/raw_client.py b/src/pipedream/users/raw_client.py index 168f71b..4239355 100644 --- a/src/pipedream/users/raw_client.py +++ b/src/pipedream/users/raw_client.py @@ -45,9 +45,9 @@ def delete_external_user( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ), @@ -91,9 +91,9 @@ async def delete_external_user( raise TooManyRequestsError( headers=dict(_response.headers), body=typing.cast( - typing.Optional[typing.Any], + typing.Any, parse_obj_as( - type_=typing.Optional[typing.Any], # type: ignore + type_=typing.Any, # type: ignore object_=_response.json(), ), ),