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.0.tar.gz (14.4 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.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: b24api-1.0.0.tar.gz
  • Upload date:
  • Size: 14.4 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.0.tar.gz
Algorithm Hash digest
SHA256 fb3964b8c5b6c53538ad79040f93c2d56e03a11837ccf5d43028a3716691057f
MD5 edc60246195ac6e75b240b1a0c4dba85
BLAKE2b-256 bfd76ae7889074dfe9e8832e1095a80758b8536d81c74d1985805f536c522eba

See more details on using hashes here.

Provenance

The following attestation bundles were made for b24api-1.0.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: b24api-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 194df175b18b006a9b75193e3b2915621e0aeef4b91cbc88af4857b311a26ead
MD5 944ba71ba83919817165d9fe1b8a0556
BLAKE2b-256 d5090f9629a75f9089d326b7b3186da86f891a5e14844148d86fb928bff491d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for b24api-1.0.0-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