A modern Python client for Bitrix24 REST API. Supports both synchronous and asynchronous communication.
Project description
Bitrix24 REST API Client
A Python client for interacting with the Bitrix24 REST API.
Supports both synchronous (requests) and asynchronous (httpx) modes.
Ideal for CRM automation, data synchronization, and Bitrix24 integrations.
🔧 Features
- Synchronous client (
requests) - Asynchronous client (
httpx) - Retry strategies:
fixed,linear,exponential,logarithmic,exponential_jitter - Support for pagination (
fetch_all=True) - API and HTTP error handling
- Context manager and session support
💻 Installation
pip install bitrix24-api-client
🚀 Quick Start
from bitrix24_client import Bitrix24Client
with Bitrix24Client(
base_url="https://yourdomain.bitrix24.ru",
access_token="your_webhook_or_token"
) as client:
result = client.call_method("crm.lead.list", {"select": ["ID", "TITLE"]}, fetch_all=True)
print(result)
import asyncio
from typing import List
from src.bitrix24_client import AsyncBitrix24Client
from src.bitrix24_client import chunk_batch_requests
async def run_batch_example():
client = AsyncBitrix24Client(
base_url="https://example.bitrix24.ru",
access_token="token",
max_concurrent_requests=35,
user_id=1
)
await client.open_session()
lead_ids: List[dict] = await client.call_method(
'crm.lead.list',
params={
'select': ['ID']
},
fetch_all=True
)
commands = {
f"get_lead_{lead_id['ID']}": f"crm.lead.get?id={lead_id['ID']}"
for lead_id in lead_ids
}
chunks = chunk_batch_requests(commands)
get_lead_tasks = [
asyncio.create_task(client.call_method(
'batch',
params={"halt": 1, "cmd": chunk}
)) for chunk in chunks
]
results = await asyncio.gather(*get_lead_tasks)
await client.close_session()
if __name__ == "__main__":
asyncio.run(run_batch_example())
🔁 Retry Strategies
Supported strategies:
fixed— fixed delaylinear— linear backofflogarithmic— logarithmic backoffexponential— exponential backoffexponential_jitter— exponential backoff with jitter (randomized delay)
Example:
client = Bitrix24Client(
base_url="https://yourdomain.bitrix24.ru",
access_token="your_webhook_or_token",
retry_strategy="exponential_jitter"
)
⚙️ Constructor Arguments
| Parameter | Description |
|---|---|
base_url |
Base URL of the Bitrix24 portal. |
access_token |
Bitrix24 access token or webhook key. |
user_id |
User ID for OAuth-based authentication (optional, None for webhook). |
timeout |
Request timeout in seconds. |
max_retries |
Maximum number of retries on 503 errors. |
retry_strategy |
Optional retry delay strategy (implements RetryStrategyI). |
response_formatter |
Optional API response formatter (implements ResponseFormatterI). |
response_validator |
Optional API response validator (implements ResponseValidatorI). |
Note:
If retry_strategy, response_formatter, or response_validator are not provided, default implementations will be used.
Raises:
Bitrix24InvalidBaseURLError — If the provided base_url is invalid.
🤝 Contributing
If you’ve found a bug, have a suggestion, or want to add a feature — your help is welcome! Feel free to open an issue or submit a pull request.
All contributions are appreciated: code, documentation, or usage examples.
📄 License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bitrix24_api_client-0.1.2.tar.gz.
File metadata
- Download URL: bitrix24_api_client-0.1.2.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58785216415c04a48cc05e3c2fdd5c406679002c2b03393c768836dce24fa5a4
|
|
| MD5 |
20c181bbca63b71758b7c584e8019e70
|
|
| BLAKE2b-256 |
79933ae60c4b512b970e409b91146116f11704976262cb3b57c44e0edf1cf1e7
|
File details
Details for the file bitrix24_api_client-0.1.2-py3-none-any.whl.
File metadata
- Download URL: bitrix24_api_client-0.1.2-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
215fc67fde52304258dba80fac1dff8aaa1acb557a5e4ca873c6bb37863416fe
|
|
| MD5 |
5a9cfbb292a08428eb96251bbd88dd9b
|
|
| BLAKE2b-256 |
5a8df762324136ac25c0310a59845fe6a91171b5e53a0308bc35904e7f000360
|