b24api 0.6.1__tar.gz → 0.7.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: b24api
3
- Version: 0.6.1
3
+ Version: 0.7.1
4
4
  Summary: Bitrix24 API
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -2,6 +2,7 @@ from collections.abc import AsyncGenerator, AsyncIterable, Iterable
2
2
  from itertools import batched, islice
3
3
  from typing import Any
4
4
 
5
+ from aioitertools.itertools import batched as abatched
5
6
  from aioitertools.itertools import chain as achain
6
7
  from httpx import AsyncClient
7
8
  from tenacity import AsyncRetrying
@@ -48,7 +49,8 @@ class AsyncBitrix24(BaseBitrix24):
48
49
 
49
50
  async def batch(
50
51
  self,
51
- requests: Iterable[Request | dict | tuple[Request | dict, Any]],
52
+ requests: Iterable[Request | dict | tuple[Request | dict, Any]]
53
+ | AsyncIterable[Request | dict | tuple[Request | dict, Any]],
52
54
  *,
53
55
  batch_size: int | None = None,
54
56
  list_method: bool = False,
@@ -57,20 +59,34 @@ class AsyncBitrix24(BaseBitrix24):
57
59
  """Call unlimited sequence of methods within batches and return `result` from responses."""
58
60
  batch_size = batch_size or self.settings.batch_size
59
61
 
60
- for batched_requests_ in batched(requests, batch_size):
61
- if with_payload:
62
- batched_requests, batched_payloads = zip(*batched_requests_, strict=True)
63
- else:
64
- batched_requests, batched_payloads = batched_requests_, None
62
+ if isinstance(requests, AsyncIterable):
63
+ async for batched_requests_ in abatched(requests, batch_size):
64
+ async for item in self._batch_common_body(batched_requests_, list_method, with_payload):
65
+ yield item
66
+ else:
67
+ for batched_requests_ in batched(requests, batch_size):
68
+ async for item in self._batch_common_body(batched_requests_, list_method, with_payload):
69
+ yield item
65
70
 
66
- batched_responses = await self.retry(self._batch, batched_requests)
71
+ async def _batch_common_body(
72
+ self,
73
+ requests: tuple[Request | dict | tuple[Request | dict, Any], ...],
74
+ list_method: bool = False, # noqa: FBT001, FBT002
75
+ with_payload: bool = False, # noqa: FBT001, FBT002
76
+ ) -> AsyncGenerator[ApiTypes | tuple[ApiTypes, Any]]:
77
+ if with_payload:
78
+ batched_requests, batched_payloads = zip(*requests, strict=True)
79
+ else:
80
+ batched_requests, batched_payloads = requests, None
81
+
82
+ batched_responses = await self.retry(self._batch, batched_requests)
67
83
 
68
- for i, response in enumerate(batched_responses):
69
- result = response.list_result if list_method else response.result
70
- if with_payload:
71
- yield result, batched_payloads[i]
72
- else:
73
- yield result
84
+ for i, response in enumerate(batched_responses):
85
+ result = response.list_result if list_method else response.result
86
+ if with_payload:
87
+ yield result, batched_payloads[i]
88
+ else:
89
+ yield result
74
90
 
75
91
  async def list_sequential(
76
92
  self,
@@ -10,11 +10,11 @@ class ApiResponseError(Exception):
10
10
 
11
11
  def __init__(self, *, code: str, description: str | None, request: str) -> None:
12
12
  if code and description:
13
- message = f"API error [{code}]: {description} for request {request}"
13
+ message = f"API error [{code}]: {description} for <Request {request}>"
14
14
  elif code:
15
- message = f"API error [{code}] for request {request}"
15
+ message = f"API error [{code}] for <Request {request}>"
16
16
  else:
17
- message = f"API error: {description} for request {request}"
17
+ message = f"API error: {description} for <Request {request}>"
18
18
  super().__init__(message)
19
19
 
20
20
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: b24api
3
- Version: 0.6.1
3
+ Version: 0.7.1
4
4
  Summary: Bitrix24 API
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes