Партнёрская доставка (tbank.delivery)¶
Партнёрская доставка и выездные встречи: задания (создание, обновление, отмена), подбор интервалов и назначение встречи, загрузка и скачивание документов.
Хост:
business.tbank.ru/openapiпо Bearer-токену.Документы: загрузка —
multipart/form-data, скачивание — «сырые» байты.Клиенты:
tbank.delivery.DeliveryClient(async) иtbank.delivery.sync.DeliveryClient(sync).
Задание и встреча¶
from tbank.delivery import DeliveryClient
from tbank.delivery.models import (
CreateTaskRequest, Contact, Phone, Passport,
GetIntervalsRequest, Address, CreateMeetingRequest,
)
from tbank.delivery.enums import PhoneType
client = DeliveryClient(token="business-token")
# создать задание (Idempotency-Key генерируется автоматически)
task = await client.create_task(CreateTaskRequest(
template="COURIER",
contacts=[Contact(
id="c-1", first_name="Иван",
phones=[Phone(type=PhoneType.MOBILE, number="+79001112233")],
documents=[Passport(number="123456", series="4509")],
)],
))
# подобрать интервал и назначить встречу
intervals = await client.get_intervals(GetIntervalsRequest(
address=Address(full_address="Москва, ул. Тверская, 1"), task_ids=[task.id],
))
slot = intervals.intervals[0]
await client.create_meeting(CreateMeetingRequest(
appointment_id=intervals.appointment_id,
interval_start_time=slot.start_interval,
interval_end_time=slot.end_interval,
))
info = await client.get_task(task.id) # статус, вложения, фото
Документы¶
# загрузить документ (multipart) и связать с заданием
uploaded = await client.upload_document(
task_id=task.id, document_type="ACT", content=pdf_bytes, filename="act.pdf",
)
# скачать документ — вернутся байты
content = await client.download_document(uploaded.id)
Клиент¶
- class tbank.delivery.aio.DeliveryClient(token, *, base_url=None, sandbox=False, retry=None, transport=None)[исходный код]¶
Базовые классы:
BaseAsyncClientАсинхронный клиент партнёрской доставки: задания, встречи и интервалы, документы (загрузка и скачивание).
Работает на обычном хосте по Bearer-токену. Провод — camelCase.
- Параметры:
token (str)
base_url (Optional[str])
sandbox (bool)
retry (Optional[RetryPolicy])
transport (Optional[AsyncTransport])
- async create_task(request, *, idempotency_key=None)[исходный код]¶
Создать задание на доставку/встречу.
- Параметры:
request (CreateTaskRequest)
idempotency_key (str | None)
- Тип результата:
- async get_task(task_id)[исходный код]¶
Карточка задания.
- Параметры:
task_id (str)
- Тип результата:
- async update_task(task_id, request)[исходный код]¶
Обновить задание.
- Параметры:
task_id (str)
request (UpdateTaskRequest)
- Тип результата:
None
- async cancel_task(task_id, request)[исходный код]¶
Отменить задание.
- Параметры:
task_id (str)
request (CancelTaskRequest)
- Тип результата:
None
- async get_intervals(request)[исходный код]¶
Доступные интервалы встречи по адресу.
- Параметры:
request (GetIntervalsRequest)
- Тип результата:
- async create_meeting(request)[исходный код]¶
Назначить встречу на выбранный интервал.
- Параметры:
request (CreateMeetingRequest)
- Тип результата:
- async upload_document(task_id, document_type, content, *, prev_doc_id=None, filename='document')[исходный код]¶
Загрузить документ и связать с заданием (multipart).
- async download_document(document_id)[исходный код]¶
Скачать документ задания (бинарное содержимое).
Модели¶
- class tbank.delivery.models.DeliveryModel[исходный код]¶
Базовые классы:
BaseModelБазовая модель домена: snake_case в Python, camelCase на проводе.
- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.Passport(*, number, series, type=IdentificationDocumentType.PASSPORT, divisionName=None, issueDate=None)[исходный код]¶
Базовые классы:
DeliveryModelДокумент, удостоверяющий личность (паспорт).
- Параметры:
number (str)
series (str)
type (IdentificationDocumentType)
divisionName (str | None)
issueDate (date | None)
- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.Phone(*, type, number)[исходный код]¶
Базовые классы:
DeliveryModel- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.Contact(*, id, role=None, firstName=None, lastName=None, middleName=None, birthDate=None, phones=None, documents=None)[исходный код]¶
Базовые классы:
DeliveryModel- Параметры:
- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.Attachment(*, id, type, meta=None)[исходный код]¶
Базовые классы:
DeliveryModel- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.Photo(*, id, type=None, subType=None, sheetNumber=None, review=None)[исходный код]¶
Базовые классы:
DeliveryModel- Параметры:
- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.CreateTaskRequest(*, template, commentForAgent=None, parentTaskId=None, meta=None, contacts=None)[исходный код]¶
Базовые классы:
DeliveryModel- Параметры:
- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.CreateTaskResult(*, id)[исходный код]¶
Базовые классы:
DeliveryModel- Параметры:
id (str)
- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.UpdateTaskRequest(*, template, commentForAgent=None, parentTaskId=None, meta=None, contacts=None, photos=None)[исходный код]¶
Базовые классы:
DeliveryModel- Параметры:
- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.CancelTaskRequest(*, reason)[исходный код]¶
Базовые классы:
DeliveryModel- Параметры:
reason (str)
- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.DeliveryTask(*, id, status, template, meetResult=None, resolution=None, subResolution=None, parentTaskId=None, meta=None, attachments=None, photos=None)[исходный код]¶
Базовые классы:
DeliveryModelКарточка задания на доставку/встречу.
- Параметры:
- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.Address(*, fullAddress, zipCode=None, country=None, region=None, area=None, city=None, street=None, house=None, building=None, flat=None, construction=None, settlement=None)[исходный код]¶
Базовые классы:
DeliveryModel- Параметры:
- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.GetIntervalsRequest(*, address, taskIds=None)[исходный код]¶
Базовые классы:
DeliveryModel- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.Interval(*, startInterval, endInterval)[исходный код]¶
Базовые классы:
DeliveryModel- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.GetIntervalsResult(*, appointmentId, timeOffset, intervals=None)[исходный код]¶
Базовые классы:
DeliveryModel- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.CreateMeetingRequest(*, appointmentId, intervalStartTime, intervalEndTime, commentForAgent=None)[исходный код]¶
Базовые классы:
DeliveryModel- Параметры:
- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.CreateMeetingResult(*, meetingId)[исходный код]¶
Базовые классы:
DeliveryModel- Параметры:
meetingId (str)
- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class tbank.delivery.models.UploadDocumentResult(*, id)[исходный код]¶
Базовые классы:
DeliveryModel- Параметры:
id (str)
- model_config = {'alias_generator': <function to_camel>, 'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Перечисления¶
- class tbank.delivery.enums.IdentificationDocumentType(*values)[исходный код]¶
-
Тип документа, удостоверяющего личность контакта.
- PASSPORT = 'PASSPORT'¶