b24api 0.2.0__tar.gz → 0.3.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.
- {b24api-0.2.0/b24api.egg-info → b24api-0.3.1}/PKG-INFO +5 -2
- {b24api-0.2.0 → b24api-0.3.1}/README.md +2 -0
- {b24api-0.2.0 → b24api-0.3.1}/b24api/api.py +8 -17
- {b24api-0.2.0 → b24api-0.3.1}/b24api/entity.py +14 -8
- {b24api-0.2.0 → b24api-0.3.1}/b24api/error.py +6 -1
- {b24api-0.2.0 → b24api-0.3.1/b24api.egg-info}/PKG-INFO +5 -2
- {b24api-0.2.0 → b24api-0.3.1}/pyproject.toml +1 -3
- {b24api-0.2.0 → b24api-0.3.1}/LICENSE +0 -0
- {b24api-0.2.0 → b24api-0.3.1}/MANIFEST.in +0 -0
- {b24api-0.2.0 → b24api-0.3.1}/b24api/__init__.py +0 -0
- {b24api-0.2.0 → b24api-0.3.1}/b24api/httpc.py +0 -0
- {b24api-0.2.0 → b24api-0.3.1}/b24api/query.py +0 -0
- {b24api-0.2.0 → b24api-0.3.1}/b24api/settings.py +0 -0
- {b24api-0.2.0 → b24api-0.3.1}/b24api/type.py +0 -0
- {b24api-0.2.0 → b24api-0.3.1}/b24api.egg-info/SOURCES.txt +0 -0
- {b24api-0.2.0 → b24api-0.3.1}/b24api.egg-info/dependency_links.txt +0 -0
- {b24api-0.2.0 → b24api-0.3.1}/b24api.egg-info/requires.txt +0 -0
- {b24api-0.2.0 → b24api-0.3.1}/b24api.egg-info/top_level.txt +0 -0
- {b24api-0.2.0 → b24api-0.3.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: b24api
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Bitrix24 API
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -10,6 +10,7 @@ Requires-Dist: httpx[http2]>=0.28.1
|
|
|
10
10
|
Requires-Dist: pydantic>=2.10.6
|
|
11
11
|
Requires-Dist: pydantic-settings>=2.8.1
|
|
12
12
|
Requires-Dist: retry>=0.9.2
|
|
13
|
+
Dynamic: license-file
|
|
13
14
|
|
|
14
15
|
# API client for Bitrix24
|
|
15
16
|
|
|
@@ -51,6 +52,7 @@ print(list(result))
|
|
|
51
52
|
## Gathering full list (faster)
|
|
52
53
|
Applicable to list methods with `start=<offset>` support.
|
|
53
54
|
Fetches first list chunk with regular call, then fetches other chunks with `batch`.
|
|
55
|
+
Approximately 3 times faster then `list_sequential`.
|
|
54
56
|
|
|
55
57
|
```python
|
|
56
58
|
from b24api import Bitrix24
|
|
@@ -63,6 +65,7 @@ print(list(result))
|
|
|
63
65
|
## Gathering full list (fastest)
|
|
64
66
|
Applicable to list methods with `filter={<parameters>}` support.
|
|
65
67
|
Fetches first and last list chunk with batch call, then fetches other chunks with `batch`. Doesn't use counting (`start=-1`).
|
|
68
|
+
Approximately 2 times faster then `list_batched`.
|
|
66
69
|
|
|
67
70
|
```python
|
|
68
71
|
from b24api import Bitrix24
|
|
@@ -38,6 +38,7 @@ print(list(result))
|
|
|
38
38
|
## Gathering full list (faster)
|
|
39
39
|
Applicable to list methods with `start=<offset>` support.
|
|
40
40
|
Fetches first list chunk with regular call, then fetches other chunks with `batch`.
|
|
41
|
+
Approximately 3 times faster then `list_sequential`.
|
|
41
42
|
|
|
42
43
|
```python
|
|
43
44
|
from b24api import Bitrix24
|
|
@@ -50,6 +51,7 @@ print(list(result))
|
|
|
50
51
|
## Gathering full list (fastest)
|
|
51
52
|
Applicable to list methods with `filter={<parameters>}` support.
|
|
52
53
|
Fetches first and last list chunk with batch call, then fetches other chunks with `batch`. Doesn't use counting (`start=-1`).
|
|
54
|
+
Approximately 2 times faster then `list_batched`.
|
|
53
55
|
|
|
54
56
|
```python
|
|
55
57
|
from b24api import Bitrix24
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import contextlib
|
|
2
|
+
import json
|
|
2
3
|
import logging
|
|
3
4
|
from collections.abc import Generator, Iterable
|
|
4
5
|
from itertools import chain, islice
|
|
@@ -20,7 +21,7 @@ class Bitrix24:
|
|
|
20
21
|
def __init__(self, client: HttpxClient, settings: ApiSettings) -> None:
|
|
21
22
|
self.client = client
|
|
22
23
|
self.settings = settings
|
|
23
|
-
self.logger = logging.getLogger(
|
|
24
|
+
self.logger = logging.getLogger("b24api")
|
|
24
25
|
self._call_retry = retry(
|
|
25
26
|
exceptions=(RetryHTTPStatusError, RetryApiResponseError),
|
|
26
27
|
tries=self.settings.retry_tries,
|
|
@@ -39,7 +40,7 @@ class Bitrix24:
|
|
|
39
40
|
"""Call any method and return full response."""
|
|
40
41
|
request = Request.model_validate(request)
|
|
41
42
|
|
|
42
|
-
self.logger.debug("Sending request",
|
|
43
|
+
self.logger.debug("Sending request: %s", request)
|
|
43
44
|
|
|
44
45
|
http_response = self.client.post(
|
|
45
46
|
f"{self.settings.webhook_url}{request.method}",
|
|
@@ -47,6 +48,9 @@ class Bitrix24:
|
|
|
47
48
|
json=request.model_dump()["parameters"],
|
|
48
49
|
)
|
|
49
50
|
|
|
51
|
+
with contextlib.suppress(httpx.ResponseNotRead, json.JSONDecodeError, ValidationError):
|
|
52
|
+
ErrorResponse.model_validate(http_response.json()).raise_error(self.settings.retry_errors)
|
|
53
|
+
|
|
50
54
|
try:
|
|
51
55
|
json_response = http_response.raise_for_status().json()
|
|
52
56
|
except httpx.HTTPStatusError as error:
|
|
@@ -63,16 +67,7 @@ class Bitrix24:
|
|
|
63
67
|
|
|
64
68
|
response = Response.model_validate(json_response)
|
|
65
69
|
|
|
66
|
-
self.logger.debug("Received response
|
|
67
|
-
self.logger.info(
|
|
68
|
-
"Received response",
|
|
69
|
-
extra={
|
|
70
|
-
"method": request.method,
|
|
71
|
-
"duration": response.time.duration,
|
|
72
|
-
"processing": response.time.processing,
|
|
73
|
-
"operating": response.time.operating,
|
|
74
|
-
},
|
|
75
|
-
)
|
|
70
|
+
self.logger.debug("Received response: %s", response)
|
|
76
71
|
|
|
77
72
|
return response
|
|
78
73
|
|
|
@@ -102,10 +97,6 @@ class Bitrix24:
|
|
|
102
97
|
|
|
103
98
|
result = self.call(request)
|
|
104
99
|
|
|
105
|
-
for fix_key in ["result_error", "result_total", "result_next"]:
|
|
106
|
-
if isinstance(result[fix_key], list) and not result[fix_key]:
|
|
107
|
-
result[fix_key] = dict(result[fix_key])
|
|
108
|
-
|
|
109
100
|
result = BatchResult.model_validate(result)
|
|
110
101
|
|
|
111
102
|
for i in range(len(commands)):
|
|
@@ -252,7 +243,7 @@ class Bitrix24:
|
|
|
252
243
|
body_request.parameters.filter[id_to] = min(start + list_size + 1, min_tail_id)
|
|
253
244
|
yield body_request
|
|
254
245
|
|
|
255
|
-
if max_head_id < min_tail_id:
|
|
246
|
+
if max_head_id and min_tail_id and max_head_id < min_tail_id:
|
|
256
247
|
body = self.batch(_body_requests(), batch_size)
|
|
257
248
|
body = map(self._fix_list_result, body)
|
|
258
249
|
body = chain.from_iterable(body)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
|
-
from typing import Self
|
|
2
|
+
from typing import Annotated, Any, Self
|
|
3
3
|
|
|
4
|
-
from pydantic import BaseModel
|
|
4
|
+
from pydantic import BaseModel, BeforeValidator
|
|
5
5
|
|
|
6
6
|
from b24api.error import ApiResponseError, RetryApiResponseError
|
|
7
7
|
from b24api.query import build_query
|
|
@@ -46,7 +46,7 @@ class ErrorResponse(BaseModel):
|
|
|
46
46
|
"""API error response."""
|
|
47
47
|
|
|
48
48
|
error: str
|
|
49
|
-
error_description: str
|
|
49
|
+
error_description: str
|
|
50
50
|
|
|
51
51
|
def raise_error(self, retry_errors: list[str]) -> Self:
|
|
52
52
|
if self.error in retry_errors:
|
|
@@ -82,11 +82,17 @@ class Response(BaseModel):
|
|
|
82
82
|
next: int | None = None
|
|
83
83
|
|
|
84
84
|
|
|
85
|
+
def _php_dict(value: Any) -> Any: # noqa: ANN401
|
|
86
|
+
if isinstance(value, list) and not value:
|
|
87
|
+
return {}
|
|
88
|
+
return value
|
|
89
|
+
|
|
90
|
+
|
|
85
91
|
class BatchResult(BaseModel):
|
|
86
92
|
"""API response `result` structure for `batch` method."""
|
|
87
93
|
|
|
88
|
-
result: dict[str, ApiTypes]
|
|
89
|
-
result_time: dict[str, ResponseTime]
|
|
90
|
-
result_error: dict[str, ErrorResponse]
|
|
91
|
-
result_total: dict[str, int]
|
|
92
|
-
result_next: dict[str, int]
|
|
94
|
+
result: Annotated[dict[str, ApiTypes], BeforeValidator(_php_dict)]
|
|
95
|
+
result_time: Annotated[dict[str, ResponseTime], BeforeValidator(_php_dict)]
|
|
96
|
+
result_error: Annotated[dict[str, ErrorResponse], BeforeValidator(_php_dict)]
|
|
97
|
+
result_total: Annotated[dict[str, int], BeforeValidator(_php_dict)]
|
|
98
|
+
result_next: Annotated[dict[str, int], BeforeValidator(_php_dict)]
|
|
@@ -14,7 +14,12 @@ class ApiResponseError(Exception):
|
|
|
14
14
|
code: str,
|
|
15
15
|
description: str | None,
|
|
16
16
|
) -> None:
|
|
17
|
-
|
|
17
|
+
if code and description:
|
|
18
|
+
message = f"API error [{code}]: {description}"
|
|
19
|
+
elif code:
|
|
20
|
+
message = f"API error [{code}]"
|
|
21
|
+
else:
|
|
22
|
+
message = f"API error: {description}"
|
|
18
23
|
super().__init__(message)
|
|
19
24
|
|
|
20
25
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: b24api
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Bitrix24 API
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -10,6 +10,7 @@ Requires-Dist: httpx[http2]>=0.28.1
|
|
|
10
10
|
Requires-Dist: pydantic>=2.10.6
|
|
11
11
|
Requires-Dist: pydantic-settings>=2.8.1
|
|
12
12
|
Requires-Dist: retry>=0.9.2
|
|
13
|
+
Dynamic: license-file
|
|
13
14
|
|
|
14
15
|
# API client for Bitrix24
|
|
15
16
|
|
|
@@ -51,6 +52,7 @@ print(list(result))
|
|
|
51
52
|
## Gathering full list (faster)
|
|
52
53
|
Applicable to list methods with `start=<offset>` support.
|
|
53
54
|
Fetches first list chunk with regular call, then fetches other chunks with `batch`.
|
|
55
|
+
Approximately 3 times faster then `list_sequential`.
|
|
54
56
|
|
|
55
57
|
```python
|
|
56
58
|
from b24api import Bitrix24
|
|
@@ -63,6 +65,7 @@ print(list(result))
|
|
|
63
65
|
## Gathering full list (fastest)
|
|
64
66
|
Applicable to list methods with `filter={<parameters>}` support.
|
|
65
67
|
Fetches first and last list chunk with batch call, then fetches other chunks with `batch`. Doesn't use counting (`start=-1`).
|
|
68
|
+
Approximately 2 times faster then `list_batched`.
|
|
66
69
|
|
|
67
70
|
```python
|
|
68
71
|
from b24api import Bitrix24
|
|
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
|
|
5
5
|
|
|
6
6
|
[project]
|
|
7
7
|
name = "b24api"
|
|
8
|
-
version = "0.
|
|
8
|
+
version = "0.3.1"
|
|
9
9
|
description = "Bitrix24 API"
|
|
10
10
|
readme = "README.md"
|
|
11
11
|
requires-python = ">=3.11"
|
|
@@ -19,11 +19,9 @@ dependencies = [
|
|
|
19
19
|
|
|
20
20
|
[dependency-groups]
|
|
21
21
|
dev = [
|
|
22
|
-
"mypy>=1.15.0",
|
|
23
22
|
"pytest-env>=1.1.5",
|
|
24
23
|
"pytest-httpx>=0.35.0",
|
|
25
24
|
"pytest-mock>=3.14.0",
|
|
26
|
-
"ruff>=0.9.9",
|
|
27
25
|
]
|
|
28
26
|
|
|
29
27
|
[tool.ruff]
|
|
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
|