Skip to content

Commit

Permalink
Add support for specifying the max_items parameter for pay-per resu…
Browse files Browse the repository at this point in the history
…lt Actors and their runs (#148)

When we introduced pay-per result Actors, we did not add support for
specifying the max items limit to the Python API client. This adds it
hopefully everywhere it's supported.

Closes #146.
  • Loading branch information
fnesveda authored Sep 5, 2023
1 parent afe796a commit bf64cb2
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
[1.4.1](../../releases/tag/v1.4.1) - Unreleased
-----------------------------------------------

### Added

- support for specifying the `max_items` parameter for pay-per result Actors and their runs

### Internal changes

- Improved logging of HTTP requests
Expand Down
80 changes: 64 additions & 16 deletions docs/docs.md

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions src/apify_client/clients/resource_clients/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def _get_actor_representation(
is_anonymously_runnable: Optional[bool] = None,
categories: Optional[List[str]] = None,
default_run_build: Optional[str] = None,
default_run_max_items: Optional[int] = None,
default_run_memory_mbytes: Optional[int] = None,
default_run_timeout_secs: Optional[int] = None,
example_run_input_body: Optional[Any] = None,
Expand All @@ -46,6 +47,7 @@ def _get_actor_representation(
'categories': categories,
'defaultRunOptions': {
'build': default_run_build,
'maxItems': default_run_max_items,
'memoryMbytes': default_run_memory_mbytes,
'timeoutSecs': default_run_timeout_secs,
},
Expand Down Expand Up @@ -90,6 +92,7 @@ def update(
is_anonymously_runnable: Optional[bool] = None,
categories: Optional[List[str]] = None,
default_run_build: Optional[str] = None,
default_run_max_items: Optional[int] = None,
default_run_memory_mbytes: Optional[int] = None,
default_run_timeout_secs: Optional[int] = None,
example_run_input_body: Optional[Any] = None,
Expand All @@ -112,6 +115,8 @@ def update(
is_anonymously_runnable (bool, optional): Whether the actor is anonymously runnable.
categories (list of str, optional): The categories to which the actor belongs to.
default_run_build (str, optional): Tag or number of the build that you want to run by default.
default_run_max_items (int, optional): Default limit of the number of results that will be returned by runs of this Actor,
if the Actor is charged per result.
default_run_memory_mbytes (int, optional): Default amount of memory allocated for the runs of this actor, in megabytes.
default_run_timeout_secs (int, optional): Default timeout for the runs of this actor in seconds.
example_run_input_body (Any, optional): Input to be prefilled as default input to new users of this actor.
Expand All @@ -133,6 +138,7 @@ def update(
is_anonymously_runnable=is_anonymously_runnable,
categories=categories,
default_run_build=default_run_build,
default_run_max_items=default_run_max_items,
default_run_memory_mbytes=default_run_memory_mbytes,
default_run_timeout_secs=default_run_timeout_secs,
example_run_input_body=example_run_input_body,
Expand All @@ -154,6 +160,7 @@ def start(
run_input: Optional[Any] = None,
content_type: Optional[str] = None,
build: Optional[str] = None,
max_items: Optional[int] = None,
memory_mbytes: Optional[int] = None,
timeout_secs: Optional[int] = None,
wait_for_finish: Optional[int] = None,
Expand All @@ -168,6 +175,8 @@ def start(
content_type (str, optional): The content type of the input.
build (str, optional): Specifies the actor build to run. It can be either a build tag or build number.
By default, the run uses the build specified in the default run configuration for the actor (typically latest).
max_items (int, optional): Maximum number of results that will be returned by this run.
If the Actor is charged per result, you will not be charged for more results than the given limit.
memory_mbytes (int, optional): Memory limit for the run, in megabytes.
By default, the run uses a memory limit specified in the default run configuration for the actor.
timeout_secs (int, optional): Optional timeout for the run, in seconds.
Expand All @@ -190,6 +199,7 @@ def start(

request_params = self._params(
build=build,
maxItems=max_items,
memory=memory_mbytes,
timeout=timeout_secs,
waitForFinish=wait_for_finish,
Expand All @@ -212,6 +222,7 @@ def call(
run_input: Optional[Any] = None,
content_type: Optional[str] = None,
build: Optional[str] = None,
max_items: Optional[int] = None,
memory_mbytes: Optional[int] = None,
timeout_secs: Optional[int] = None,
webhooks: Optional[List[Dict]] = None,
Expand All @@ -228,6 +239,8 @@ def call(
content_type (str, optional): The content type of the input.
build (str, optional): Specifies the actor build to run. It can be either a build tag or build number.
By default, the run uses the build specified in the default run configuration for the actor (typically latest).
max_items (int, optional): Maximum number of results that will be returned by this run.
If the Actor is charged per result, you will not be charged for more results than the given limit.
memory_mbytes (int, optional): Memory limit for the run, in megabytes.
By default, the run uses a memory limit specified in the default run configuration for the actor.
timeout_secs (int, optional): Optional timeout for the run, in seconds.
Expand All @@ -244,6 +257,7 @@ def call(
run_input=run_input,
content_type=content_type,
build=build,
max_items=max_items,
memory_mbytes=memory_mbytes,
timeout_secs=timeout_secs,
webhooks=webhooks,
Expand Down Expand Up @@ -378,6 +392,7 @@ async def update(
is_anonymously_runnable: Optional[bool] = None,
categories: Optional[List[str]] = None,
default_run_build: Optional[str] = None,
default_run_max_items: Optional[int] = None,
default_run_memory_mbytes: Optional[int] = None,
default_run_timeout_secs: Optional[int] = None,
example_run_input_body: Optional[Any] = None,
Expand All @@ -400,6 +415,8 @@ async def update(
is_anonymously_runnable (bool, optional): Whether the actor is anonymously runnable.
categories (list of str, optional): The categories to which the actor belongs to.
default_run_build (str, optional): Tag or number of the build that you want to run by default.
default_run_max_items (int, optional): Default limit of the number of results that will be returned by runs of this Actor,
if the Actor is charged per result.
default_run_memory_mbytes (int, optional): Default amount of memory allocated for the runs of this actor, in megabytes.
default_run_timeout_secs (int, optional): Default timeout for the runs of this actor in seconds.
example_run_input_body (Any, optional): Input to be prefilled as default input to new users of this actor.
Expand All @@ -421,6 +438,7 @@ async def update(
is_anonymously_runnable=is_anonymously_runnable,
categories=categories,
default_run_build=default_run_build,
default_run_max_items=default_run_max_items,
default_run_memory_mbytes=default_run_memory_mbytes,
default_run_timeout_secs=default_run_timeout_secs,
example_run_input_body=example_run_input_body,
Expand All @@ -442,6 +460,7 @@ async def start(
run_input: Optional[Any] = None,
content_type: Optional[str] = None,
build: Optional[str] = None,
max_items: Optional[int] = None,
memory_mbytes: Optional[int] = None,
timeout_secs: Optional[int] = None,
wait_for_finish: Optional[int] = None,
Expand All @@ -456,6 +475,8 @@ async def start(
content_type (str, optional): The content type of the input.
build (str, optional): Specifies the actor build to run. It can be either a build tag or build number.
By default, the run uses the build specified in the default run configuration for the actor (typically latest).
max_items (int, optional): Maximum number of results that will be returned by this run.
If the Actor is charged per result, you will not be charged for more results than the given limit.
memory_mbytes (int, optional): Memory limit for the run, in megabytes.
By default, the run uses a memory limit specified in the default run configuration for the actor.
timeout_secs (int, optional): Optional timeout for the run, in seconds.
Expand All @@ -478,6 +499,7 @@ async def start(

request_params = self._params(
build=build,
maxItems=max_items,
memory=memory_mbytes,
timeout=timeout_secs,
waitForFinish=wait_for_finish,
Expand All @@ -500,6 +522,7 @@ async def call(
run_input: Optional[Any] = None,
content_type: Optional[str] = None,
build: Optional[str] = None,
max_items: Optional[int] = None,
memory_mbytes: Optional[int] = None,
timeout_secs: Optional[int] = None,
webhooks: Optional[List[Dict]] = None,
Expand All @@ -516,6 +539,8 @@ async def call(
content_type (str, optional): The content type of the input.
build (str, optional): Specifies the actor build to run. It can be either a build tag or build number.
By default, the run uses the build specified in the default run configuration for the actor (typically latest).
max_items (int, optional): Maximum number of results that will be returned by this run.
If the Actor is charged per result, you will not be charged for more results than the given limit.
memory_mbytes (int, optional): Memory limit for the run, in megabytes.
By default, the run uses a memory limit specified in the default run configuration for the actor.
timeout_secs (int, optional): Optional timeout for the run, in seconds.
Expand All @@ -532,6 +557,7 @@ async def call(
run_input=run_input,
content_type=content_type,
build=build,
max_items=max_items,
memory_mbytes=memory_mbytes,
timeout_secs=timeout_secs,
webhooks=webhooks,
Expand Down
8 changes: 8 additions & 0 deletions src/apify_client/clients/resource_clients/actor_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def create(
is_anonymously_runnable: Optional[bool] = None,
categories: Optional[List[str]] = None,
default_run_build: Optional[str] = None,
default_run_max_items: Optional[int] = None,
default_run_memory_mbytes: Optional[int] = None,
default_run_timeout_secs: Optional[int] = None,
example_run_input_body: Optional[Any] = None,
Expand All @@ -76,6 +77,8 @@ def create(
is_anonymously_runnable (bool, optional): Whether the actor is anonymously runnable.
categories (list of str, optional): The categories to which the actor belongs to.
default_run_build (str, optional): Tag or number of the build that you want to run by default.
default_run_max_items (int, optional): Default limit of the number of results that will be returned by runs of this Actor,
if the Actor is charged per result.
default_run_memory_mbytes (int, optional): Default amount of memory allocated for the runs of this actor, in megabytes.
default_run_timeout_secs (int, optional): Default timeout for the runs of this actor in seconds.
example_run_input_body (Any, optional): Input to be prefilled as default input to new users of this actor.
Expand All @@ -97,6 +100,7 @@ def create(
is_anonymously_runnable=is_anonymously_runnable,
categories=categories,
default_run_build=default_run_build,
default_run_max_items=default_run_max_items,
default_run_memory_mbytes=default_run_memory_mbytes,
default_run_timeout_secs=default_run_timeout_secs,
example_run_input_body=example_run_input_body,
Expand Down Expand Up @@ -153,6 +157,7 @@ async def create(
is_anonymously_runnable: Optional[bool] = None,
categories: Optional[List[str]] = None,
default_run_build: Optional[str] = None,
default_run_max_items: Optional[int] = None,
default_run_memory_mbytes: Optional[int] = None,
default_run_timeout_secs: Optional[int] = None,
example_run_input_body: Optional[Any] = None,
Expand All @@ -175,6 +180,8 @@ async def create(
is_anonymously_runnable (bool, optional): Whether the actor is anonymously runnable.
categories (list of str, optional): The categories to which the actor belongs to.
default_run_build (str, optional): Tag or number of the build that you want to run by default.
default_run_max_items (int, optional): Default limit of the number of results that will be returned by runs of this Actor,
if the Actor is charged per result.
default_run_memory_mbytes (int, optional): Default amount of memory allocated for the runs of this actor, in megabytes.
default_run_timeout_secs (int, optional): Default timeout for the runs of this actor in seconds.
example_run_input_body (Any, optional): Input to be prefilled as default input to new users of this actor.
Expand All @@ -196,6 +203,7 @@ async def create(
is_anonymously_runnable=is_anonymously_runnable,
categories=categories,
default_run_build=default_run_build,
default_run_max_items=default_run_max_items,
default_run_memory_mbytes=default_run_memory_mbytes,
default_run_timeout_secs=default_run_timeout_secs,
example_run_input_body=example_run_input_body,
Expand Down
Loading

0 comments on commit bf64cb2

Please sign in to comment.