b24api 0.7.4__tar.gz → 1.0.0__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-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,166 @@
1
+ Metadata-Version: 2.4
2
+ Name: b24api
3
+ Version: 1.0.0
4
+ Summary: Bitrix24 API
5
+ Requires-Python: >=3.12
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: aioitertools>=0.12.0
9
+ Requires-Dist: fast-depends>=2.4.12
10
+ Requires-Dist: httpx[http2]>=0.28.1
11
+ Requires-Dist: pydantic>=2.11.7
12
+ Requires-Dist: pydantic-settings>=2.10.1
13
+ Requires-Dist: tenacity>=9.1.2
14
+ Dynamic: license-file
15
+
16
+ # API client for Bitrix24
17
+
18
+ Low-level API client with multiple strategies for lists gathering.
19
+ All methods support retries.
20
+
21
+ ## Regular call (any method)
22
+
23
+ ```python
24
+ import asyncio
25
+
26
+ from b24api import Bitrix24
27
+
28
+
29
+ async def main():
30
+ async with Bitrix24() as b24:
31
+ result = await b24.call({"method": "user.access", "parameters": {"ACCESS": ["G2", "AU"]}})
32
+ print(result)
33
+
34
+
35
+ asyncio.run(main())
36
+ ```
37
+
38
+ ## Batch call (any method, no limit)
39
+
40
+ ```python
41
+ import asyncio
42
+
43
+ from b24api import Bitrix24
44
+
45
+
46
+ async def main():
47
+ async with Bitrix24() as b24:
48
+ requests = ({"method": "user.update", "parameters": {"ID": u, "UF_SKYPE": ""}} for u in range(1000))
49
+ async for result in b24.batch(requests):
50
+ print(result)
51
+
52
+
53
+ asyncio.run(main())
54
+ ```
55
+
56
+ ## Gathering full list (slow)
57
+ Applicable to list methods with `start=<offset>` support.
58
+ Fetches list chunks one by one.
59
+
60
+ ```python
61
+ import asyncio
62
+
63
+ from b24api import Bitrix24
64
+
65
+
66
+ async def main():
67
+ async with Bitrix24() as b24:
68
+ async for item in b24.list_sequential({"method": "user.get"}):
69
+ print(item)
70
+
71
+
72
+ asyncio.run(main())
73
+ ```
74
+
75
+ ## Gathering full list (faster)
76
+ Applicable to list methods with `start=<offset>` support.
77
+ Fetches first list chunk with regular call, then fetches other chunks with `batch`.
78
+ Approximately 3 times faster then `list_sequential`.
79
+
80
+ ```python
81
+ import asyncio
82
+
83
+ from b24api import Bitrix24
84
+
85
+
86
+ async def main():
87
+ async with Bitrix24() as b24:
88
+ async for item in b24.list_batched({"method": "user.get"}):
89
+ print(item)
90
+
91
+
92
+ asyncio.run(main())
93
+ ```
94
+
95
+ ## Gathering full list (fastest)
96
+ Applicable to list methods with `filter={<parameters>}` support.
97
+ Fetches first and last list chunk with batch call, then fetches other chunks with `batch`. Doesn't use counting (`start=-1`).
98
+ Approximately 2 times faster then `list_batched`.
99
+
100
+ ```python
101
+ import asyncio
102
+
103
+ from b24api import Bitrix24
104
+
105
+
106
+ async def main():
107
+ async with Bitrix24() as b24:
108
+ async for item in b24.list_batched_no_count({"method": "user.get"}):
109
+ print(item)
110
+
111
+
112
+ asyncio.run(main())
113
+ ```
114
+
115
+ ## Gathering full list with required reference
116
+ Applicable to list methods with `select=[<fields>]` and `filter={<parameters>}` support and required filter parameters.
117
+ Fetches first and last list chunk with batch call, then fetches other chunks with `batch`. Doesn't use counting (`start=-1`).
118
+
119
+ ```python
120
+ import asyncio
121
+
122
+ from b24api import Bitrix24
123
+
124
+
125
+ async def main():
126
+ async with Bitrix24() as b24:
127
+ deal_ids = [1, 2, 3] # deals IDs (e.g. from "crm.deal.list" call)
128
+ filter_updates = ({"=ENTITY_ID": i} for i in deal_ids)
129
+ items = b24.reference_batched_no_count(
130
+ {"method": "crm.timeline.comment.list", "parameters": {"filter": {"ENTITY_TYPE": "deal"}}},
131
+ filter_updates,
132
+ )
133
+ async for item in items:
134
+ print(item)
135
+
136
+
137
+ asyncio.run(main())
138
+ ```
139
+
140
+ ## Gathering full list with cursor pagination per reference
141
+ Applicable to list methods that paginate via a dedicated top-level cursor parameter (`LAST_ID`, `FIRST_ID`) per reference instead of the standard `>ID` filter — e.g. most `im.*` list methods. Pagination within a single reference is strictly sequential; each round-trip fires up to `batch_size` requests in parallel, mixing new first-page requests with in-flight continuations as the FIFO queue rotates (so continuations may be served before later-arriving first-pages).
142
+
143
+ ```python
144
+ import asyncio
145
+
146
+ from b24api import Bitrix24
147
+
148
+
149
+ async def main():
150
+ async with Bitrix24() as b24:
151
+ dialog_ids = ["chat1", "chat2", "chat3"]
152
+ references = ({"DIALOG_ID": d} for d in dialog_ids)
153
+ items = b24.reference_cursor_no_count(
154
+ {"method": "im.dialog.messages.get", "parameters": {}},
155
+ references,
156
+ cursor_param="LAST_ID", # name of the cursor parameter the API accepts
157
+ cursor_field="id", # field in each item that holds its id
158
+ cursor_take="min", # "min" = older messages direction; "max" = newer
159
+ result_key="messages", # required for multi-key responses
160
+ )
161
+ async for item in items:
162
+ print(item)
163
+
164
+
165
+ asyncio.run(main())
166
+ ```
b24api-1.0.0/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # API client for Bitrix24
2
+
3
+ Low-level API client with multiple strategies for lists gathering.
4
+ All methods support retries.
5
+
6
+ ## Regular call (any method)
7
+
8
+ ```python
9
+ import asyncio
10
+
11
+ from b24api import Bitrix24
12
+
13
+
14
+ async def main():
15
+ async with Bitrix24() as b24:
16
+ result = await b24.call({"method": "user.access", "parameters": {"ACCESS": ["G2", "AU"]}})
17
+ print(result)
18
+
19
+
20
+ asyncio.run(main())
21
+ ```
22
+
23
+ ## Batch call (any method, no limit)
24
+
25
+ ```python
26
+ import asyncio
27
+
28
+ from b24api import Bitrix24
29
+
30
+
31
+ async def main():
32
+ async with Bitrix24() as b24:
33
+ requests = ({"method": "user.update", "parameters": {"ID": u, "UF_SKYPE": ""}} for u in range(1000))
34
+ async for result in b24.batch(requests):
35
+ print(result)
36
+
37
+
38
+ asyncio.run(main())
39
+ ```
40
+
41
+ ## Gathering full list (slow)
42
+ Applicable to list methods with `start=<offset>` support.
43
+ Fetches list chunks one by one.
44
+
45
+ ```python
46
+ import asyncio
47
+
48
+ from b24api import Bitrix24
49
+
50
+
51
+ async def main():
52
+ async with Bitrix24() as b24:
53
+ async for item in b24.list_sequential({"method": "user.get"}):
54
+ print(item)
55
+
56
+
57
+ asyncio.run(main())
58
+ ```
59
+
60
+ ## Gathering full list (faster)
61
+ Applicable to list methods with `start=<offset>` support.
62
+ Fetches first list chunk with regular call, then fetches other chunks with `batch`.
63
+ Approximately 3 times faster then `list_sequential`.
64
+
65
+ ```python
66
+ import asyncio
67
+
68
+ from b24api import Bitrix24
69
+
70
+
71
+ async def main():
72
+ async with Bitrix24() as b24:
73
+ async for item in b24.list_batched({"method": "user.get"}):
74
+ print(item)
75
+
76
+
77
+ asyncio.run(main())
78
+ ```
79
+
80
+ ## Gathering full list (fastest)
81
+ Applicable to list methods with `filter={<parameters>}` support.
82
+ Fetches first and last list chunk with batch call, then fetches other chunks with `batch`. Doesn't use counting (`start=-1`).
83
+ Approximately 2 times faster then `list_batched`.
84
+
85
+ ```python
86
+ import asyncio
87
+
88
+ from b24api import Bitrix24
89
+
90
+
91
+ async def main():
92
+ async with Bitrix24() as b24:
93
+ async for item in b24.list_batched_no_count({"method": "user.get"}):
94
+ print(item)
95
+
96
+
97
+ asyncio.run(main())
98
+ ```
99
+
100
+ ## Gathering full list with required reference
101
+ Applicable to list methods with `select=[<fields>]` and `filter={<parameters>}` support and required filter parameters.
102
+ Fetches first and last list chunk with batch call, then fetches other chunks with `batch`. Doesn't use counting (`start=-1`).
103
+
104
+ ```python
105
+ import asyncio
106
+
107
+ from b24api import Bitrix24
108
+
109
+
110
+ async def main():
111
+ async with Bitrix24() as b24:
112
+ deal_ids = [1, 2, 3] # deals IDs (e.g. from "crm.deal.list" call)
113
+ filter_updates = ({"=ENTITY_ID": i} for i in deal_ids)
114
+ items = b24.reference_batched_no_count(
115
+ {"method": "crm.timeline.comment.list", "parameters": {"filter": {"ENTITY_TYPE": "deal"}}},
116
+ filter_updates,
117
+ )
118
+ async for item in items:
119
+ print(item)
120
+
121
+
122
+ asyncio.run(main())
123
+ ```
124
+
125
+ ## Gathering full list with cursor pagination per reference
126
+ Applicable to list methods that paginate via a dedicated top-level cursor parameter (`LAST_ID`, `FIRST_ID`) per reference instead of the standard `>ID` filter — e.g. most `im.*` list methods. Pagination within a single reference is strictly sequential; each round-trip fires up to `batch_size` requests in parallel, mixing new first-page requests with in-flight continuations as the FIFO queue rotates (so continuations may be served before later-arriving first-pages).
127
+
128
+ ```python
129
+ import asyncio
130
+
131
+ from b24api import Bitrix24
132
+
133
+
134
+ async def main():
135
+ async with Bitrix24() as b24:
136
+ dialog_ids = ["chat1", "chat2", "chat3"]
137
+ references = ({"DIALOG_ID": d} for d in dialog_ids)
138
+ items = b24.reference_cursor_no_count(
139
+ {"method": "im.dialog.messages.get", "parameters": {}},
140
+ references,
141
+ cursor_param="LAST_ID", # name of the cursor parameter the API accepts
142
+ cursor_field="id", # field in each item that holds its id
143
+ cursor_take="min", # "min" = older messages direction; "max" = newer
144
+ result_key="messages", # required for multi-key responses
145
+ )
146
+ async for item in items:
147
+ print(item)
148
+
149
+
150
+ asyncio.run(main())
151
+ ```
@@ -0,0 +1,3 @@
1
+ from b24api.api import Bitrix24
2
+
3
+ __all__ = ["Bitrix24"]