Skip to main content

Bitrix24 API

Project description

API client for Bitrix24

Low-level API client with multiple strategies for lists gathering. All methods support retries.

Regular call (any method)

import asyncio

from b24api import Bitrix24


async def main():
    async with Bitrix24() as b24:
        result = await b24.call({"method": "user.access", "parameters": {"ACCESS": ["G2", "AU"]}})
        print(result)


asyncio.run(main())

Batch call (any method, no limit)

import asyncio

from b24api import Bitrix24


async def main():
    async with Bitrix24() as b24:
        requests = ({"method": "user.update", "parameters": {"ID": u, "UF_SKYPE": ""}} for u in range(1000))
        async for result in b24.batch(requests):
            print(result)


asyncio.run(main())

Gathering full list (slow)

Applicable to list methods with start=<offset> support. Fetches list chunks one by one.

import asyncio

from b24api import Bitrix24


async def main():
    async with Bitrix24() as b24:
        async for item in b24.list_sequential({"method": "user.get"}):
            print(item)


asyncio.run(main())

Gathering full list (faster)

Applicable to list methods with start=<offset> support. Fetches first list chunk with regular call, then fetches other chunks with batch. Approximately 3 times faster then list_sequential.

import asyncio

from b24api import Bitrix24


async def main():
    async with Bitrix24() as b24:
        async for item in b24.list_batched({"method": "user.get"}):
            print(item)


asyncio.run(main())

Gathering full list (fastest)

Applicable to list methods with filter={<parameters>} support. Fetches first and last list chunk with batch call, then fetches other chunks with batch. Doesn't use counting (start=-1). Approximately 2 times faster then list_batched.

import asyncio

from b24api import Bitrix24


async def main():
    async with Bitrix24() as b24:
        async for item in b24.list_batched_no_count({"method": "user.get"}):
            print(item)


asyncio.run(main())

Gathering full list with required reference

Applicable to list methods with select=[<fields>] and filter={<parameters>} support and required filter parameters. Fetches first and last list chunk with batch call, then fetches other chunks with batch. Doesn't use counting (start=-1).

import asyncio

from b24api import Bitrix24


async def main():
    async with Bitrix24() as b24:
        deal_ids = [1, 2, 3]  # deals IDs (e.g. from "crm.deal.list" call)
        filter_updates = ({"=ENTITY_ID": i} for i in deal_ids)
        items = b24.reference_batched_no_count(
            {"method": "crm.timeline.comment.list", "parameters": {"filter": {"ENTITY_TYPE": "deal"}}},
            filter_updates,
        )
        async for item in items:
            print(item)


asyncio.run(main())

Gathering full list with cursor pagination per reference

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).

import asyncio

from b24api import Bitrix24


async def main():
    async with Bitrix24() as b24:
        dialog_ids = ["chat1", "chat2", "chat3"]
        references = ({"DIALOG_ID": d} for d in dialog_ids)
        items = b24.reference_cursor_no_count(
            {"method": "im.dialog.messages.get", "parameters": {}},
            references,
            cursor_param="LAST_ID",   # name of the cursor parameter the API accepts
            cursor_field="id",         # field in each item that holds its id
            cursor_take="min",         # "min" = older messages direction; "max" = newer
            result_key="messages",     # required for multi-key responses
        )
        async for item in items:
            print(item)


asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

b24api-1.0.1.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

b24api-1.0.1-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file b24api-1.0.1.tar.gz.

File metadata

  • Download URL: b24api-1.0.1.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for b24api-1.0.1.tar.gz
Algorithm Hash digest
SHA256 33a6aa17174963c22259f166dc6fd36fbae5126c4db0c2911a9504e854012426
MD5 e6858e647205fd1ca139cf6978213829
BLAKE2b-256 5a4fd1bf22937a32f2ffbb69787940f8d57a3ad6e89aae5739566454b1ac080c

See more details on using hashes here.

Provenance

The following attestation bundles were made for b24api-1.0.1.tar.gz:

Publisher: publish-to-pypi.yml on shkarupa-alex/b24api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file b24api-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: b24api-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for b24api-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bae6e98abba8ab383dcdcfa1b809c232b4965d8d90b4a0d059b62366c20d61bf
MD5 73561eae410d33dbe15440ecfe24389d
BLAKE2b-256 67d1ddcc1e41ab9f27c897c8d0c223edb3109f49c742fa62165552560447bcbd

See more details on using hashes here.

Provenance

The following attestation bundles were made for b24api-1.0.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on shkarupa-alex/b24api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page