ORM-система для работы с Bitrix24
Работа библиотеки находится в стадии разработки. (рекомендуется только для локальной разработки) тест автодеплоя
Библиотека для удобной работы с API Bitrix24 в объектно-ориентированном стиле.
Особенности
- ORM-подобный доступ к данным через точечную нотацию
- Удобные методы для создания, обновления и поиска сущностей
- Поддержка связанных объектов и отношений между ними
- Поддержка пользовательских полей
- Работа с товарными позициями сделок
- Асинхронный подход для лучшей производительности
Установка
uv add orm-bitrix24
Использование
Инициализация
from fast_bitrix24 import Bitrix
from entity import Deal
# Инициализация Bitrix клиента
bitrix = Bitrix('https://your-domain.bitrix24.ru/rest/1/your_webhook_token/')
# Инициализация менеджера сущностей
Deal.get_manager(bitrix)
Получение сделок
# Получение всех сделок
deals = await Deal.objects.get_all()
# Фильтрация сделок
deals = await Deal.objects.filter(type_id="SALE", stage_id="NEW")
# Получение сделки по ID
deal = await Deal.get_by_id(bitrix, "123")
Работа со сделкой
# Чтение полей
print(deal.title)
print(deal.opportunity)
print(deal.created_at) # Автоматически преобразуется в datetime объект
# Чтение связанных объектов (необходимо использовать await)
company = await deal.company
if company:
print(company.name)
# Изменение значений
deal.title = "Новое название"
deal.opportunity = 15000
deal.tags.append("новый_тег")
await deal.save()
# Создание примечаний
note = await deal.notes.create(text="Примечание к сделке")
Создание новой сделки
# Создание через менеджер объектов
deal = await Deal.objects.create(
title="Новая сделка",
opportunity=10000,
currency_id="RUB",
stage_id="NEW"
)
# Альтернативный способ создания
deal = Deal(bitrix)
deal.title = "Новая сделка"
deal.opportunity = 10000
deal.currency_id = "RUB"
deal.stage_id = "NEW"
await deal.save()
Работа с товарами сделки
# Получение товаров сделки
products = await deal.products.get_all()
print(f"В сделке {len(products)} товаров")
# Добавление товара
product = deal.products.add(
product_id=123, # ID товара из каталога Bitrix24
price=1000,
quantity=2,
discount_rate=10 # 10% скидка
)
# Изменение параметров товара
product.quantity = 3
product.discount_sum = 500 # Скидка фиксированной суммой
# Сохранение товаров сделки
await deal.save()
Пользовательские поля
from entity import Deal, CustomField, TextCustomField, SelectCustomField
# Добавление пользовательских полей напрямую в класс Deal
Deal.add_custom_field('utm_source', CustomField("UTM_SOURCE"))
Deal.add_custom_field('delivery_address', TextCustomField("UF_CRM_DELIVERY_ADDRESS"))
Deal.add_custom_field('delivery_type', SelectCustomField("UF_CRM_DELIVERY_TYPE"))
# Инициализация менеджера
Deal.get_manager(bitrix)
# Использование пользовательских полей
deals = await Deal.objects.get_all()
deal = deals[0]
deal.delivery_address = "ул. Примерная, д. 1, кв. 2"
await deal.save()
Работа со связанными объектами
Важно! Связанные объекты (company, contact и др.) возвращают корутины, которые нужно ожидать с помощью await:
# Получение связанной компании
company = await deal.company
if company:
print(f"Компания: {company.title}")
# Получение связанного контакта
contact = await deal.contact
if contact:
print(f"Контакт: {contact.full_name}")
# Изменение связанного объекта произойдет только после сохранения сделки
deal.company_id = 5 # Смена компании
await deal.save()
Требования
- Python 3.7+
- fast-bitrix24
Лицензия
MIT
Metadata
Release files for test-publish2 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| test_publish2-0.1.2.tar.gz | 13.0 kB | With provenance | Details for test_publish2-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| test_publish2-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for test_publish2-0.1.2-py3-none-any.whl |
Total release size: 27.7 kB
Release files / test_publish2-0.1.2.tar.gz
| Download URL | test_publish2-0.1.2.tar.gz |
|---|---|
| Size | 13.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7c16bbe6de7c1d8a4a297e30b867a3e87016e061e566be500816f65ae0df2d46
|
|
BLAKE2b-256 checksum How to use checksums |
90bae90c370923d060444ea828c707b264be834ba9c7234b032e29cdfadf12cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 4, 2025.
Transparency logRelease files / test_publish2-0.1.2-py3-none-any.whl
| Download URL | test_publish2-0.1.2-py3-none-any.whl |
|---|---|
| Size | 14.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b218d1f9200ec39352d8093bf3e8982bdad987d9e2232faa848fa9ac98ebe8bb
|
|
BLAKE2b-256 checksum How to use checksums |
c475b13c39047699439af73f2eb5cd9a12a81e508b38da7aa82b17a1bd563268
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 4, 2025.
Transparency logSecurity for test-publish2 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for test_publish2-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 4, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.