Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -37,7 +37,7 @@ keywords = [
dependencies = [
"apify-client>=2.3.0,<3.0.0",
"apify-shared>=2.0.0,<3.0.0",
"crawlee>=1.0.4,<2.0.0",
"crawlee @ git+https://github.com/apify/crawlee-python.git@master",
"cachetools>=5.5.0",
"cryptography>=42.0.0",
"impit>=0.8.0",
Expand Down
4 changes: 2 additions & 2 deletions src/apify/_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

if TYPE_CHECKING:
import logging
from collections.abc import Callable
from collections.abc import Callable, MutableMapping
from decimal import Decimal
from types import TracebackType

Expand Down Expand Up @@ -1401,7 +1401,7 @@ async def use_state(
default_value: dict[str, JsonSerializable] | None = None,
key: str | None = None,
kvs_name: str | None = None,
) -> dict[str, JsonSerializable]:
) -> MutableMapping[str, JsonSerializable]:
"""Easily create and manage state values. All state values are automatically persisted.

Values can be modified by simply using the assignment operator.
Expand Down
2 changes: 1 addition & 1 deletion src/apify/_charging.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ async def charge(self, event_name: str, count: int = 1) -> ChargeResult:
{
'event_name': event_name,
'event_title': pricing_info.title,
'event_price_usd': round(pricing_info.price, 3),
'event_price_usd': float(round(pricing_info.price, 3)),
'charged_count': charged_count,
'timestamp': datetime.now(timezone.utc).isoformat(),
}
Expand Down
12 changes: 6 additions & 6 deletions src/apify/storage_clients/_apify/_dataset_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import warnings
from logging import getLogger
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

from typing_extensions import override

Expand All @@ -16,7 +16,7 @@
from apify.storage_clients._ppe_dataset_mixin import DatasetClientPpeMixin

if TYPE_CHECKING:
from collections.abc import AsyncIterator
from collections.abc import AsyncIterator, Mapping, Sequence

from apify_client.clients import DatasetClientAsync
from crawlee._types import JsonSerializable
Expand Down Expand Up @@ -137,13 +137,13 @@ async def drop(self) -> None:
await self._api_client.delete()

@override
async def push_data(self, data: list[Any] | dict[str, Any]) -> None:
async def payloads_generator(items: list[Any]) -> AsyncIterator[str]:
async def push_data(self, data: Sequence[Mapping[str, JsonSerializable]] | Mapping[str, JsonSerializable]) -> None:
async def payloads_generator(items: Sequence[Mapping[str, JsonSerializable]]) -> AsyncIterator[str]:
for index, item in enumerate(items):
yield await self._check_and_serialize(item, index)

async with self._charge_lock(), self._lock:
items = data if isinstance(data, list) else [data]
items = data if self._is_sequence_of_items(data) else [data]
limit = self._compute_limit_for_push(len(items))
items = items[:limit]

Expand Down Expand Up @@ -211,7 +211,7 @@ async def iterate_items(
yield item

@classmethod
async def _check_and_serialize(cls, item: JsonSerializable, index: int | None = None) -> str:
async def _check_and_serialize(cls, item: Mapping[str, JsonSerializable], index: int | None = None) -> str:
"""Serialize a given item to JSON, checks its serializability and size against a limit.

Args:
Expand Down
7 changes: 5 additions & 2 deletions src/apify/storage_clients/_file_system/_dataset_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from apify.storage_clients._ppe_dataset_mixin import DatasetClientPpeMixin

if TYPE_CHECKING:
from collections.abc import Mapping, Sequence

from crawlee._types import JsonSerializable
from crawlee.configuration import Configuration


Expand Down Expand Up @@ -47,9 +50,9 @@ async def open(
return dataset_client

@override
async def push_data(self, data: list[dict[str, Any]] | dict[str, Any]) -> None:
async def push_data(self, data: Sequence[Mapping[str, JsonSerializable]] | Mapping[str, JsonSerializable]) -> None:
async with self._charge_lock():
items = data if isinstance(data, list) else [data]
items = data if self._is_sequence_of_items(data) else [data]
limit = self._compute_limit_for_push(len(items))

await super().push_data(items[:limit])
Expand Down
10 changes: 3 additions & 7 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading