diff --git a/pyproject.toml b/pyproject.toml index 2447bf6b..f48b1c87 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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/Mantisus//crawlee-python.git@up-json-serializavle-typing", "cachetools>=5.5.0", "cryptography>=42.0.0", "impit>=0.8.0", diff --git a/src/apify/_actor.py b/src/apify/_actor.py index 9f4cd7ec..7895b0be 100644 --- a/src/apify/_actor.py +++ b/src/apify/_actor.py @@ -41,7 +41,7 @@ if TYPE_CHECKING: import logging - from collections.abc import Callable + from collections.abc import Callable, MutableMapping from types import TracebackType from typing_extensions import Self @@ -1373,7 +1373,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. diff --git a/src/apify/_charging.py b/src/apify/_charging.py index 07fdd04b..0bf43626 100644 --- a/src/apify/_charging.py +++ b/src/apify/_charging.py @@ -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(), } diff --git a/src/apify/storage_clients/_apify/_dataset_client.py b/src/apify/storage_clients/_apify/_dataset_client.py index 2287ec66..fc809646 100644 --- a/src/apify/storage_clients/_apify/_dataset_client.py +++ b/src/apify/storage_clients/_apify/_dataset_client.py @@ -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 @@ -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 @@ -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] @@ -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: diff --git a/src/apify/storage_clients/_file_system/_dataset_client.py b/src/apify/storage_clients/_file_system/_dataset_client.py index 04af9ae2..057bcc9f 100644 --- a/src/apify/storage_clients/_file_system/_dataset_client.py +++ b/src/apify/storage_clients/_file_system/_dataset_client.py @@ -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 @@ -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]) diff --git a/uv.lock b/uv.lock index bd57dbfd..7fd367a4 100644 --- a/uv.lock +++ b/uv.lock @@ -88,7 +88,7 @@ requires-dist = [ { name = "apify-client", specifier = ">=2.3.0,<3.0.0" }, { name = "apify-shared", specifier = ">=2.0.0,<3.0.0" }, { name = "cachetools", specifier = ">=5.5.0" }, - { name = "crawlee", specifier = ">=1.0.4,<2.0.0" }, + { name = "crawlee", git = "https://github.com/Mantisus//crawlee-python.git?rev=up-json-serializavle-typing" }, { name = "cryptography", specifier = ">=42.0.0" }, { name = "impit", specifier = ">=0.8.0" }, { name = "lazy-object-proxy", specifier = ">=1.11.0" }, @@ -609,8 +609,8 @@ toml = [ [[package]] name = "crawlee" -version = "1.6.3" -source = { registry = "https://pypi.org/simple" } +version = "1.6.4" +source = { git = "https://github.com/Mantisus//crawlee-python.git?rev=up-json-serializavle-typing#413ee179214f44efce04b278cb1bc25c7a4e4aba" } dependencies = [ { name = "async-timeout" }, { name = "cachetools" }, @@ -626,10 +626,6 @@ dependencies = [ { name = "typing-extensions" }, { name = "yarl" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/35/1d/3f3652c8cf889053b795934a4d6268e805793a30be11001603c5a7f4b46e/crawlee-1.6.3.tar.gz", hash = "sha256:9cbb243071186daa2f9e9572a8bfb966c81537bc86ef6e3bc8572602d659b159", size = 25869502, upload-time = "2026-04-27T16:33:56.51Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/86/83/e9adf980396829edc8a2979892bdec1bbd203443c513a791255ab59aab53/crawlee-1.6.3-py3-none-any.whl", hash = "sha256:551a4c54de70aeb4eaf079bb44f63aaa45d94e6e143c1fd72924a92b46ded505", size = 343055, upload-time = "2026-04-27T16:33:54.019Z" }, -] [package.optional-dependencies] parsel = [