Skip to content

feat: add support for general resource access #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ classifiers = [
]
keywords = ["apify", "api", "client", "automation", "crawling", "scraping"]
dependencies = [
"apify-shared>=1.1.2",
"apify-shared>=1.4.1",
"httpx>=0.25",
"more_itertools>=10.0.0",
]
Expand Down
17 changes: 13 additions & 4 deletions src/apify_client/clients/resource_clients/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from collections.abc import AsyncIterator, Iterator

import httpx
from apify_shared.consts import StorageGeneralAccess
from apify_shared.types import JSONSerializable

_SMALL_TIMEOUT = 5 # For fast and common actions. Suitable for idempotent actions.
Expand All @@ -39,18 +40,22 @@ def get(self) -> dict | None:
"""
return self._get(timeout_secs=_SMALL_TIMEOUT)

def update(self, *, name: str | None = None) -> dict:
def update(self, *, name: str | None = None, general_access: StorageGeneralAccess | None = None) -> dict:
"""Update the dataset with specified fields.

https://docs.apify.com/api/v2#/reference/datasets/dataset/update-dataset

Args:
name: The new name for the dataset.
general_access: Determines how others can access the dataset.

Returns:
The updated dataset.
"""
updated_fields = {'name': name}
updated_fields = {
'name': name,
'generalAccess': general_access,
}

return self._update(filter_out_none_values_recursively(updated_fields), timeout_secs=_SMALL_TIMEOUT)

Expand Down Expand Up @@ -585,18 +590,22 @@ async def get(self) -> dict | None:
"""
return await self._get(timeout_secs=_SMALL_TIMEOUT)

async def update(self, *, name: str | None = None) -> dict:
async def update(self, *, name: str | None = None, general_access: StorageGeneralAccess | None = None) -> dict:
"""Update the dataset with specified fields.

https://docs.apify.com/api/v2#/reference/datasets/dataset/update-dataset

Args:
name: The new name for the dataset.
general_access: Determines how others can access the dataset.

Returns:
The updated dataset.
"""
updated_fields = {'name': name}
updated_fields = {
'name': name,
'generalAccess': general_access,
}

return await self._update(filter_out_none_values_recursively(updated_fields), timeout_secs=_SMALL_TIMEOUT)

Expand Down
10 changes: 8 additions & 2 deletions src/apify_client/clients/resource_clients/key_value_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
if TYPE_CHECKING:
from collections.abc import AsyncIterator, Iterator

from apify_shared.consts import StorageGeneralAccess

_SMALL_TIMEOUT = 5 # For fast and common actions. Suitable for idempotent actions.
_MEDIUM_TIMEOUT = 30 # For actions that may take longer.

Expand All @@ -35,19 +37,21 @@ def get(self) -> dict | None:
"""
return self._get(timeout_secs=_SMALL_TIMEOUT)

def update(self, *, name: str | None = None) -> dict:
def update(self, *, name: str | None = None, general_access: StorageGeneralAccess | None = None) -> dict:
"""Update the key-value store with specified fields.

https://docs.apify.com/api/v2#/reference/key-value-stores/store-object/update-store

Args:
name: The new name for key-value store.
general_access: Determines how others can access the key-value store.

Returns:
The updated key-value store.
"""
updated_fields = {
'name': name,
'generalAccess': general_access,
}

return self._update(filter_out_none_values_recursively(updated_fields))
Expand Down Expand Up @@ -262,19 +266,21 @@ async def get(self) -> dict | None:
"""
return await self._get(timeout_secs=_SMALL_TIMEOUT)

async def update(self, *, name: str | None = None) -> dict:
async def update(self, *, name: str | None = None, general_access: StorageGeneralAccess | None = None) -> dict:
"""Update the key-value store with specified fields.

https://docs.apify.com/api/v2#/reference/key-value-stores/store-object/update-store

Args:
name: The new name for key-value store.
general_access: Determines how others can access the key-value store.

Returns:
The updated key-value store.
"""
updated_fields = {
'name': name,
'generalAccess': general_access,
}

return await self._update(filter_out_none_values_recursively(updated_fields))
Expand Down
10 changes: 8 additions & 2 deletions src/apify_client/clients/resource_clients/request_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
if TYPE_CHECKING:
from collections.abc import Iterable

from apify_shared.consts import StorageGeneralAccess

logger = logging.getLogger(__name__)

_RQ_MAX_REQUESTS_PER_BATCH = 25
Expand Down Expand Up @@ -83,19 +85,21 @@ def get(self) -> dict | None:
"""
return self._get(timeout_secs=_SMALL_TIMEOUT)

def update(self, *, name: str | None = None) -> dict:
def update(self, *, name: str | None = None, general_access: StorageGeneralAccess | None = None) -> dict:
"""Update the request queue with specified fields.

https://docs.apify.com/api/v2#/reference/request-queues/queue/update-request-queue

Args:
name: The new name for the request queue.
general_access: Determines how others can access the request queue.

Returns:
The updated request queue.
"""
updated_fields = {
'name': name,
'generalAccess': general_access,
}

return self._update(filter_out_none_values_recursively(updated_fields), timeout_secs=_SMALL_TIMEOUT)
Expand Down Expand Up @@ -448,19 +452,21 @@ async def get(self) -> dict | None:
"""
return await self._get(timeout_secs=_SMALL_TIMEOUT)

async def update(self, *, name: str | None = None) -> dict:
async def update(self, *, name: str | None = None, general_access: StorageGeneralAccess | None = None) -> dict:
"""Update the request queue with specified fields.

https://docs.apify.com/api/v2#/reference/request-queues/queue/update-request-queue

Args:
name: The new name for the request queue.
general_access: Determines how others can access the request queue.

Returns:
The updated request queue.
"""
updated_fields = {
'name': name,
'generalAccess': general_access,
}

return await self._update(filter_out_none_values_recursively(updated_fields), timeout_secs=_SMALL_TIMEOUT)
Expand Down
20 changes: 18 additions & 2 deletions src/apify_client/clients/resource_clients/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
if TYPE_CHECKING:
from decimal import Decimal

from apify_shared.consts import RunGeneralAccess


class RunClient(ActorJobBaseClient):
"""Sub-client for manipulating a single Actor run."""
Expand All @@ -37,21 +39,29 @@ def get(self) -> dict | None:
"""
return self._get()

def update(self, *, status_message: str | None = None, is_status_message_terminal: bool | None = None) -> dict:
def update(
self,
*,
status_message: str | None = None,
is_status_message_terminal: bool | None = None,
general_access: RunGeneralAccess | None = None,
) -> dict:
"""Update the run with the specified fields.

https://docs.apify.com/api/v2#/reference/actor-runs/run-object/update-run

Args:
status_message: The new status message for the run.
is_status_message_terminal: Set this flag to True if this is the final status message of the Actor run.
general_access: Determines how others can access the run and its storages.

Returns:
The updated run.
"""
updated_fields = {
'statusMessage': status_message,
'isStatusMessageTerminal': is_status_message_terminal,
'generalAccess': general_access,
}

return self._update(filter_out_none_values_recursively(updated_fields))
Expand Down Expand Up @@ -294,7 +304,11 @@ async def get(self) -> dict | None:
return await self._get()

async def update(
self, *, status_message: str | None = None, is_status_message_terminal: bool | None = None
self,
*,
status_message: str | None = None,
is_status_message_terminal: bool | None = None,
general_access: RunGeneralAccess | None = None,
) -> dict:
"""Update the run with the specified fields.

Expand All @@ -303,13 +317,15 @@ async def update(
Args:
status_message: The new status message for the run.
is_status_message_terminal: Set this flag to True if this is the final status message of the Actor run.
general_access: Determines how others can access the run and its storages.

Returns:
The updated run.
"""
updated_fields = {
'statusMessage': status_message,
'isStatusMessageTerminal': is_status_message_terminal,
'generalAccess': general_access,
}

return await self._update(filter_out_none_values_recursively(updated_fields))
Expand Down
Loading