Партнёрская доставка (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.

Параметры:
async create_task(request, *, idempotency_key=None)[исходный код]

Создать задание на доставку/встречу.

Параметры:
Тип результата:

CreateTaskResult

async get_task(task_id)[исходный код]

Карточка задания.

Параметры:

task_id (str)

Тип результата:

DeliveryTask

async update_task(task_id, request)[исходный код]

Обновить задание.

Параметры:
Тип результата:

None

async cancel_task(task_id, request)[исходный код]

Отменить задание.

Параметры:
Тип результата:

None

async get_intervals(request)[исходный код]

Доступные интервалы встречи по адресу.

Параметры:

request (GetIntervalsRequest)

Тип результата:

GetIntervalsResult

async create_meeting(request)[исходный код]

Назначить встречу на выбранный интервал.

Параметры:

request (CreateMeetingRequest)

Тип результата:

CreateMeetingResult

async upload_document(task_id, document_type, content, *, prev_doc_id=None, filename='document')[исходный код]

Загрузить документ и связать с заданием (multipart).

Параметры:
  • task_id (str)

  • document_type (str)

  • content (bytes)

  • prev_doc_id (str | None)

  • filename (str)

Тип результата:

UploadDocumentResult

async download_document(document_id)[исходный код]

Скачать документ задания (бинарное содержимое).

Параметры:

document_id (str)

Тип результата:

bytes

Модели

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

Документ, удостоверяющий личность (паспорт).

Параметры:
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

Параметры:
  • fullAddress (str)

  • zipCode (str | None)

  • country (str | None)

  • region (str | None)

  • area (str | None)

  • city (str | None)

  • street (str | None)

  • house (str | None)

  • building (str | None)

  • flat (str | None)

  • construction (str | None)

  • settlement (str | 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.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

Параметры:
  • startInterval (str)

  • endInterval (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.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

Параметры:
  • appointmentId (str)

  • intervalStartTime (str)

  • intervalEndTime (str)

  • commentForAgent (str | 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.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)[исходный код]

Базовые классы: str, Enum

Тип документа, удостоверяющего личность контакта.

PASSPORT = 'PASSPORT'
class tbank.delivery.enums.PhoneType(*values)[исходный код]

Базовые классы: str, Enum

Тип телефона контакта.

MOBILE = 'MOBILE'
HOME = 'HOME'
WORK = 'WORK'
OTHER = 'OTHER'